To add a free text annotation to a PDF Document page.
1PDFDoc doc = new PDFDoc(filename);
2Page page = doc.GetPage(1);
3
4// Create a free text
5FreeText txtannot = FreeText.Create( doc, new Rect(100, 100, 350, 500) );
6txtannot.SetContentRect( new Rect( 200, 200, 350, 500 ) );
7txtannot.SetContents( "\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." +
8 "\n\nAha!\n\nAnd there was much rejoicing!" );
9txtannot.SetCalloutLinePoints( new Point(200,300), new Point(150,290), new Point(110,110) );
10txtannot.SetBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.Style.e_solid, 1, 10, 20 ) );
11txtannot.SetEndingStyle(Line.EndingStyle.e_ClosedArrow );
12txtannot.SetColor( new ColorPt( 0, 1, 0 ) );
13txtannot.SetQuaddingFormat(1);
14page.AnnotPushBack(txtannot);
15txtannot.RefreshAppearance();
1PDFDoc doc(filename);
2Page page = doc.GetPage(1);
3
4// Create a free text
5Annots::FreeText txtannot = Annots::FreeText::Create( doc, Rect(100, 100, 350, 500) );
6txtannot.SetContentRect( Rect( 200, 200, 350, 500 ) );
7txtannot.SetContents( UString("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare."
8 "\n\nAha!\n\nAnd there was much rejoicing!" ) );
9txtannot.SetCalloutLinePoints( Point(200,300), Point(150,290), Point(110,110) );
10txtannot.SetBorderStyle( Annot::BorderStyle( Annot::BorderStyle::e_solid, 1, 10, 20 ), false);
11txtannot.SetEndingStyle( Line::e_ClosedArrow );
12txtannot.SetColor( ColorPt( 0, 1, 0 ) );
13txtannot.SetQuaddingFormat(1);
14page.AnnotPushBack(txtannot);
15txtannot.RefreshAppearance();
1doc := NewPDFDoc(filename)
2page := doc.GetPage(1)
3
4// Create a free text
5txtannot := FreeTextCreate( doc.GetSDFDoc(), NewRect(100.0, 100.0, 350.0, 500.0) )
6txtannot.SetContentRect( NewRect(200.0, 200.0, 350.0, 500.0 ) )
7txtannot.SetContents( "\n\nSome swift brown fox snatched a gray hare out of the air " +
8 "by freezing it with an angry glare." +
9 "\n\nAha!\n\nAnd there was much rejoicing!" )
10txtannot.SetCalloutLinePoints( NewPoint(200.0,300.0), NewPoint(150.0,290.0), NewPoint(110.0,110.0) )
11txtannot.SetBorderStyle( NewBorderStyle( BorderStyleE_solid, 1.0, 10.0, 20.0 ), false )
12txtannot.SetEndingStyle( LineAnnotE_ClosedArrow )
13txtannot.SetColor( NewColorPt( 0.0, 1.0, 0.0 ) )
14txtannot.SetQuaddingFormat(1)
15page.AnnotPushBack(txtannot)
16txtannot.RefreshAppearance()
1PDFDoc doc = new PDFDoc(filename);
2Page page = doc.getPage(1);
3
4// Create a free text
5FreeText txtannot = FreeText.create(doc, new Rect(100, 100, 350, 500));
6txtannot.setContentRect(new Rect(200, 200, 350, 500));
7txtannot.setContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." +
8 "\n\nAha!\n\nAnd there was much rejoicing!");
9txtannot.setCalloutLinePoints(new Point(200, 300), new Point(150, 290), new Point(110, 110));
10txtannot.setBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.e_solid, 1, 10, 20));
11txtannot.setEndingStyle(Line.e_ClosedArrow);
12txtannot.setColor(new ColorPt(0, 1, 0));
13txtannot.setQuaddingFormat(1);
14page.annotPushBack(txtannot);
15txtannot.refreshAppearance();
1async function main() {
2 const doc = await PDFNet.PDFDoc.createFromURL(filename);
3 const page = await doc.getPage(1);
4
5 // Create a free text
6 const txtannot = await PDFNet.FreeTextAnnot.create(doc, new PDFNet.Rect(100, 100, 350, 500));
7 await txtannot.setContentRect(new PDFNet.Rect(200, 200, 350, 500));
8 await txtannot.setContents('\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare.\n\nAha!\n\nAnd there was much rejoicing!');
9 await txtannot.setCalloutLinePoints(new PDFNet.Point(200, 300), new PDFNet.Point(150, 290), new PDFNet.Point(110, 110));
10 const solidLine = await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 1, 10, 20);
11 await txtannot.setBorderStyle(solidLine, true);
12 await txtannot.setEndingStyle(PDFNet.LineAnnot.EndingStyle.e_ClosedArrow);
13 const greenColorPt = await PDFNet.ColorPt.init(0, 1, 0, 0);
14 await txtannot.setColorDefault(greenColorPt); // default value of last param is 0
15 await txtannot.setQuaddingFormat(1);
16 await page.annotPushBack(txtannot);
17 await txtannot.refreshAppearance();
18}
19PDFNet.runWithCleanup(main);
1PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: filename];
2PTPage *page = [doc GetPage:1];
3
4// Create a free text
5PTFreeText *txtannot = [PTFreeText Create: [doc GetSDFDoc] pos: [[PTPDFRect alloc] initWithX1: 100 y1: 100 x2: 350 y2: 500]];
6[txtannot SetContentRect: [[PTPDFRect alloc] initWithX1: 200 y1: 200 x2: 350 y2: 500]];
7[txtannot SetContents: @"\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare."
8 "\n\nAha!\n\nAnd there was much rejoicing!"];
9[txtannot SetCalloutLinePointsWithKneePoint: [[PTPDFPoint alloc] initWithPx: 200 py: 300] p2: [[PTPDFPoint alloc] initWithPx: 150 py: 290] p3: [[PTPDFPoint alloc] initWithPx: 110 py: 110]];
10[txtannot SetBorderStyle: [[PTBorderStyle alloc] initWithS: e_ptsolid b_width: 1 b_hr: 10 b_vr: 20 ] oldStyleOnly: YES];
11[txtannot SetEndingStyle: e_ptClosedArrow];
12[txtannot SetColor: [[PTColorPt alloc] initWithX: 0 y: 1 z: 0 w: 0] numcomp: 3];
13[txtannot SetQuaddingFormat: 1];
14[page AnnotPushBack: txtannot];
15[txtannot RefreshAppearance];
1$doc = new PDFDoc($filename);
2$page = $doc->GetPage(1);
3
4// Create a free text
5$txtannot = FreeText::Create( $doc->GetSDFDoc(), new Rect(100.0, 100.0, 350.0, 500.0) );
6$txtannot->SetContentRect( new Rect( 200.0, 200.0, 350.0, 500.0 ) );
7$txtannot->SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare."
8 ."\n\nAha!\n\nAnd there was much rejoicing!");
9$txtannot->SetCalloutLinePoints( new Point(200.0,300.0), new Point(150.0,290.0), new Point(110.0,110.0) );
10$txtannot->SetBorderStyle( new BorderStyle( BorderStyle::e_solid, 1.0, 10.0, 20.0 ), true );
11$txtannot->SetEndingStyle( LineAnnot::e_ClosedArrow );
12$txtannot->SetColor( new ColorPt( 0.0, 1.0, 0.0 ) );
13$txtannot->SetQuaddingFormat(1);
14$page->AnnotPushBack($txtannot);
15$txtannot->RefreshAppearance();
1doc = PDFDoc(filename)
2page = doc.GetPage(1)
3
4# Create a free text
5txtannot = FreeText.Create( doc.GetSDFDoc(), Rect(100, 100, 350, 500) )
6txtannot.SetContentRect( Rect( 200, 200, 350, 500 ) )
7txtannot.SetContents( "\n\nSome swift brown fox snatched a gray hare out of the air "
8 "by freezing it with an angry glare."
9 "\n\nAha!\n\nAnd there was much rejoicing!" )
10txtannot.SetCalloutLinePoints( Point(200,300), Point(150,290), Point(110,110) )
11txtannot.SetBorderStyle( BorderStyle( BorderStyle.e_solid, 1, 10, 20 ), True )
12txtannot.SetEndingStyle( LineAnnot.e_ClosedArrow )
13txtannot.SetColor( ColorPt( 0, 1, 0 ) )
14txtannot.SetQuaddingFormat(1)
15page.AnnotPushBack(txtannot)
16txtannot.RefreshAppearance()
1doc = PDFDoc.new(filename)
2page = doc.GetPage(1)
3
4# Create a free text
5txtannot = FreeText.Create( doc.GetSDFDoc(), Rect.new(100, 100, 350, 500) )
6txtannot.SetContentRect( Rect.new( 200, 200, 350, 500 ) )
7txtannot.SetContents( "\n\nSome swift brown fox snatched a gray hare out of the air " +
8 "by freezing it with an angry glare." +
9 "\n\nAha!\n\nAnd there was much rejoicing!")
10txtannot.SetCalloutLinePoints( Point.new(200,300), Point.new(150,290), Point.new(110,110) )
11txtannot.SetBorderStyle( BorderStyle.new( BorderStyle::E_solid, 1, 10, 20 ), false )
12txtannot.SetEndingStyle( LineAnnot::E_ClosedArrow )
13txtannot.SetColor( ColorPt.new( 0, 1, 0 ) )
14txtannot.SetQuaddingFormat(1)
15page.AnnotPushBack(txtannot)
16txtannot.RefreshAppearance()
1Dim doc As PDFDoc = New PDFDoc(filename)
2Dim page As Page = doc.GetPage(1)
3
4' Create a free text
5Dim txtannot As FreeText = FreeText.Create(doc, New Rect(100, 100, 350, 500))
6txtannot.SetContentRect(New Rect(200, 200, 350, 500))
7' txtannot.SetContents(("" & vbLf& vbLf&"Some swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." + ""& vbLf& vbLf&"Aha!"& vbLf& vbLf&"And there was much rejoicing!"))
8txtannot.SetCalloutLinePoints(New Point(200, 300), New Point(150, 290), New Point(110, 110))
9txtannot.SetBorderStyle(New Annot.BorderStyle(Annot.BorderStyle.Style.e_solid, 1, 10, 20))
10txtannot.SetEndingStyle(Line.EndingStyle.e_ClosedArrow)
11txtannot.SetColor(New ColorPt(0, 1, 0))
12txtannot.SetQuaddingFormat(1)
13first_page.AnnotPushBack(txtannot)
14txtannot.RefreshAppearance()
Add or edit PDF annotations sample
Full code sample which shows how to add or edit PDF annotations (e.g. hyperlink, intra-document link, stamp, rubber stamp, file attachment, sound, text, free-text, line, circle, square, polygon, polyline, free text, squiggly, caret, and ink).
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales