Ing jaman digital saiki, PDF wis dadi format populer kanggo nuduhake informasi, dokumen, lan laporan. Nanging, mung ndeleng PDF bisa uga ora cukup kanggo akeh pangguna. Kadhangkala, pangguna bisa uga pengin nyorot utawa nambah cathetan menyang bagean tartamtu saka PDF kanggo menehi konteks utawa umpan balik tambahan. Untunge, ana sawetara annotator PDF gratis sing kasedhiya sing ngidini pangguna nambah komentar, nyorot teks, lan liya-liyane. Nanging, ing artikel iki, kita bakal njelajah cara nggunakake API REST kanggo ndhukung anotasi PDF, lan nuduhake sampeyan carane nyorot, menehi komentar, lan nambah cathetan menyang dokumen PDF.
- REST API kanggo PDF Annotation
- Tambah Komentar menyang PDF nggunakake C#
- Tambah Anotasi Teks Gratis menyang PDF nggunakake Perintah cURL
REST API kanggo PDF Annotation
Aspose.PDF Cloud nyedhiyakake solusi sing gampang digunakake lan lengkap kanggo nambah anotasi menyang dokumen PDF kanthi program. Kanthi Aspose.PDF Cloud, sampeyan bisa nambah macem-macem jinis anotasi menyang dokumen PDF, kalebu teks, gambar, prangko, lan macem-macem anotasi markup. Sampeyan uga bisa ngowahi anotasi sing ana, kayata ngganti posisi, ukuran, werna, utawa sifat liyane.
Anotasi sing Didhukung kalebu Teks, Lingkaran, Poligon, PolyLine, Garis, Kotak, FreeText, Sorot, Underline, Squiggly, StrikeOut, Caret, Ink, Link, Popup, FileAttachment, Sound, Movie, Screen, Widget, Watermark, TrapNet, PrinterMark, Redaksi, Perangko, RichMedia lan PDF3D.
Saiki, kanggo nambah SDK ing proyek sampeyan, goleki Aspose.PDF-Cloud
ing manajer paket NuGet banjur klik tombol Tambah Paket. Langkah penting sabanjure yaiku ndhaptar akun liwat dasbor Cloud lan entuk kredensial klien pribadhi. Mangga deleng pandhuan [Mulai Cepet] (https://docs.aspose.cloud/words/getting-started/quickstart/) kanggo rincian luwih lengkap.
Tambah Komentar menyang PDF nggunakake C#
Ayo goleki potongan kode C# .NET sing digunakake kanggo nambah Anotasi menyang dokumen PDF.
// Kanggo conto lengkap lan file data, bukak
https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-dotnet
// Entuk kredensial klien saka https://dashboard.aspose.cloud/
string clientSecret = "7f098199230fc5f2175d494d48f2077c";
string clientID = "ee170169-ca49-49a4-87b7-0e2ff815ea6e";
// nggawe obyek saka PdfApi
PdfApi api = new PdfApi(clientSecret, clientID);
// nggawe List obyek ngemot FreeTextAnnotations
List<FreeTextAnnotation> annotations = new List<FreeTextAnnotation>
{
new FreeTextAnnotation(
// nemtokake wilayah persegi dowo nyekeli FreeTextAnnotation
// uga nemtokake rincian format teks
Rect: new Rectangle(100, 800, 350, 830),
TextStyle:new TextStyle(
FontSize: 26, Font: "Arial",
ForegroundColor: new Aspose.Pdf.Cloud.Sdk.Model.Color(0xFF, 0, 0xFF, 0),
BackgroundColor: new Aspose.Pdf.Cloud.Sdk.Model.Color(0xFF, 0xFF, 0, 0)
))
{
// Isi sing bakal ditampilake ing FreeTextAnnotation
Contents = "Confidential !",
Color = new Aspose.Pdf.Cloud.Sdk.Model.Color(0, 0, 0, 0),
Id = "id1",
Name = "Test Free Text",
Flags = new List<AnnotationFlags> {AnnotationFlags.Default},
HorizontalAlignment = HorizontalAlignment.Center,
Intent = FreeTextIntent.FreeTextTypeWriter,
RichText = "Rich Text",
Subject = "Text Box Subj",
ZIndex = 1,
Justification = Justification.Center,
Title = "Title",
PageIndex = 1
}
};
var response = api. PostPageFreeTextAnnotations("Binder1.pdf", 1, annotations);
Saiki, ayo ngerti potongan kode kanthi luwih rinci.
PdfApi api = new PdfApi(clientSecret, clientID);
Gawe conto kelas PdfApi sing njupuk kredensial klien minangka argumen ing konstruktor.
List<FreeTextAnnotation> annotations = new List<FreeTextAnnotation>
Minangka API ndhukung kemampuan kanggo nambah siji utawa luwih Anotasi saka jinis padha ing wektu sing padha, supaya kita kudu nggawe dhaftar obyek saka jinis FreeTextAnnotation.
new FreeTextAnnotation(
Rect: new Rectangle(100, 800, 350, 830),
TextStyle:new TextStyle(
FontSize: 26, Font: "Arial",
ForegroundColor: new Aspose.Pdf.Cloud.Sdk.Model.Color(0xFF, 0, 0xFF, 0),
BackgroundColor: new Aspose.Pdf.Cloud.Sdk.Model.Color(0xFF, 0xFF, 0, 0)
))
Nggawe obyek saka FreeTextAnnotation ngendi kita nemtokake wilayah persegi dowo kanggo Annotation lan rincian format teks.
Contents = "Confidential !"
Ing kene kita nemtokake isi kanggo FreeTextAnnotation.
var response = api. PostPageFreeTextAnnotations("Binder1.pdf", 1, annotations);
Telpon API REST kanggo nambah FreeTextAnnotation ing kaca pisanan dokumen PDF sing wis kasedhiya ing panyimpenan Cloud.
Ing ngisor iki ana nilai sing bisa ditugasake kanggo properti sing digunakake ing cuplikan kode ing ndhuwur.
- AnnotationFlags - Nilai sing didhukung bisa dadi
[Default, Invisible, Hidden, Print, NoZoom, NoRotate, NoView, ReadOnly, Locked, ToggleNoView, LockedContents]
.- Puter - Sudut rotasi kanggo teks. Nilai sing bisa ditindakake yaiku
[Ora ana, on90, on180, on270]
.- AnnotationFlags - Sakumpulan gendera sing nemtokake macem-macem karakteristik anotasi. Nilai sing bisa dadi
[Default, Ora Katon, Didhelikake, Cetak, NoZoom, NoRotate, NoView, ReadOnly, Dikunci, ToggleNoView, LockedContents]
.- FreeTextIntent - Enumerates maksud saka anotasi teks gratis. Nilai sing bisa ditindakake yaiku
[ Undefined, FreeTextCallout, FreeTextTypeWriter]
.
Tambah Anotasi Teks Gratis menyang PDF nggunakake Perintah cURL
Panggunaan perintah cURL kanggo nelpon Aspose.PDF Cloud API minangka pendekatan sing apik kanggo ngrampungake syarat iki. Iku uga apik yen sampeyan kenal karo alat baris perintah utawa luwih seneng nggunakake. Dadi, kanthi alat baris perintah cURL, sampeyan bisa nggawe panjalukan HTTP lan nindakake macem-macem operasi babagan pangolahan file PDF.
Saiki, kanggo nambah anotasi menyang dokumen PDF nggunakake perintah cURL, pisanan kita kudu nggawe token otentikasi kanthi ngirim panjaluk menyang titik pungkasan token nganggo App SID lan Kunci Aplikasi. Mangga nglakokake printah ing ngisor iki kanggo ngasilake accessToken.
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=ee170169-ca49-49a4-87b7-0e2ff815ea6e&client_secret=7f098199230fc5f2175d494d48f2077c" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Sawise accessToken digawe, mangga jalanake perintah ing ngisor iki sing nambah FreeTextAnnotation menyang dokumen PDF. File PDF sing dianotasi banjur dianyari ing panyimpenan Cloud.
curl -v "https://api.aspose.cloud/v3.0/pdf/{inputPDF}/pages/1/annotations/freetext" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "[ { \"Color\": { \"A\": 0, \"R\": 0, \"G\": 0, \"B\": 0 }, \"Contents\": \"Confidential !\", \"Modified\": \"01/05/2023 12:00:00.000 PM\", \"Id\": \"id0\", \"Flags\": [ \"Default\" ], \"Name\": \"comment\", \"Rect\": { \"LLX\": 100, \"LLY\": 800, \"URX\": 350, \"URY\": 830 }, \"PageIndex\": 0, \"ZIndex\": 1, \"HorizontalAlignment\": \"Center\", \"VerticalAlignment\": \"Center\", \"CreationDate\": \"03/05/2023 16:00:00.000 PM\", \"Subject\": \"Subj.\", \"Title\": \"Main Heading\", \"RichText\": \"Hello world...\", \"Justification\": \"Left\", \"Intent\": \"FreeTextTypeWriter\", \"Rotate\": \"None\", \"TextStyle\": { \"FontSize\": 26, \"Font\": \"Arial\", \"ForegroundColor\": { \"A\": 10, \"R\": 10, \"G\": 100, \"B\": 120 }, \"BackgroundColor\": { \"A\": 0, \"R\": 0, \"G\": 50, \"B\": 80 } } }]"
Ganti
{inputPDF}
karo jeneng file PDF input sing wis kasedhiya ing panyimpenan Cloud,{accessToken}
nganggo token akses JWT sing digawe ing ndhuwur.
Dokumen PDF sing digunakake ing conto ing ndhuwur bisa diundhuh saka pranala iki.
Kesimpulan
Kesimpulane, nambahake anotasi menyang PDF bisa ningkatake kegunaan lan fungsine. Apa sampeyan pengin nyorot teks penting, nambah komentar, utawa njupuk cathetan langsung ing dokumen kasebut, banjur Aspose.PDF Cloud minangka pilihan sing apik kanggo entuk iki. Kita uga wis sinau manawa Aspose.PDF Cloud SDK kanggo .NET lan perintah cURL nawakake solusi sing kuat kanggo menehi anotasi PDF, menehi sampeyan kemampuan kanggo nggawe alur kerja lan proses otomatisasi. Mula, kanthi alat kasebut, sampeyan bisa kanthi cepet lan gampang nambah anotasi menyang PDF, nalika ngirit wektu lan nambah produktivitas.
Pranala Migunani
Artikel sing gegandhengan
Disaranake kanggo ngunjungi blog ing ngisor iki: