![]()
Add ( fragment ) dataDir = dataDir + "OTFFont_out.pdf" // Save resulting PDF document. IsEmbedded = true // Add TextFragment to paragraphs collection of Page instance Even if specific font is not installed/present over target machineįragment. OpenFont ( dataDir + "space age.otf" ) // Specify to emend font inside PDF file, so that its displayed properly, Or you can even specify the path of OTF font in system directoryįragment. #How to insert text on a pdf pro= FontRepository.FindFont("HelveticaNeueLT Pro 45 Lt") TextFragment fragment = new TextFragment ( "Sample Text in OTF font" ) // Find font inside system font directory Add () // Create TextFragment instnace with sample text GetDataDir_AsposePdf_Text () // Create new document instanceĭocument pdfDocument = new Document () // Add page to pages collection of PDF fileĪspose. ![]() NET 10.3.0, we have provided the support for Open Type Fonts. NET offers the feature to use Custom/TrueType fonts while creating/manipulating PDF file contents so that file contents are displayed using contents other than default system fonts. Add ( tf ) dataDir = dataDir + "AddHyperlinkToTextSegment_out.pdf" // Save resulting PDF document.Īspose.PDF for. Add ( segment ) // Add TextFragment to paragraphs collection of page object Segment = new TextSegment ( "TextSegment without hyperlink" ) // Add segment to segments collection of TextFragment Italic // Create another TextSegment object WebHyperlink ( ") // Set forground color for text segment Add ( segment ) // Set hyperlink for TextSegment Segment = new TextSegment ( "Link to Google" ) // Add segment to segments collection of TextFragment Add ( segment ) // Create a new TextSegment ![]() Text Segment 1." ) // Add segment to segments collection of TextFragment TextSegment segment = new TextSegment ( ". Right // Create a textsegment with sample text TextFragment tf = new TextFragment ( "Sample Text Fragment" ) // Set horizontal alignment for TextFragment GetDataDir_AsposePdf_Text () // Create document instanceĭocument doc = new Document () // Add page to pages collection of PDF file #How to insert text on a pdf codePlease try using the following code snippet to accomplish this requirement. In order to set hyperlink for TextSegment, Hyperlink property of TextSegment class can be used while providing the object of instance. Save ( dataDir ) Add Hyperlink to TextSegmentĪ PDF page may comprise of one or more TextFragment objects, where each TextFragment object can have one or more TextSegment instance. AppendParagraph ( paragraph ) dataDir = dataDir + "AddTextUsingTextParagraph_out.pdf" // Save resulting PDF document.ĭoc. AppendLine ( fragment1 ) // Add paragraphīuilder. FontSize = 12 // Add fragment to paragraph FindFont ( "Times New Roman" ) fragment1. TextFragment fragment1 = new TextFragment ( "the quick brown fox jumps over the lazy dog" ) fragment1. Rectangle ( 100, 300, 200, 700 ) // Specify word wraping mode SubsequentLinesIndent = 20 // Specify the location to add TextParagraph TextParagraph paragraph = new TextParagraph () // Set subsequent lines indent Add () TextBuilder builder = new TextBuilder ( page ) // Create text paragraph #How to insert text on a pdf how toThe following code snippet shows you how to add text in PDF document using TextParagraph class.ĭocument doc = new Document () // Add page to pages collection of Document object TextFragment textFragment = new TextFragment ( "Hello world" ) if ( fontFile != "" ) Add Text using TextParagraph Pages ) // Create text fragment with sample string TextBuilder textBuilder = new TextBuilder ( doc. GetDataDir_AsposePdf_Text () string fontFile = "" // Load input PDF fileĭocument doc = new Document ( dataDir + "input.pdf" ) // Create text builder object for first page of document The following code snippet shows how to load Font from Stream object when adding text to PDF document. Save ( dataDir ) Loading Font from Stream AppendText ( textFragment ) dataDir = dataDir + "AddText_out.pdf" // Save resulting PDF document. TextBuilder textBuilder = new TextBuilder ( pdfPage ) // Append the text fragment to the PDF page FindFont ( "TimesNewRoman" ) textFragment. Position = new Position ( 100, 600 ) // Set text properties TextFragment textFragment = new TextFragment ( "main text" ) textFragment. GetDataDir_AsposePdf_Text () // Open documentĭocument pdfDocument = new Document ( dataDir + "input.pdf" ) // Get particular page For complete examples and data files, please go to The following code snippet shows you how to add text in an existing PDF file. Call the Document object’s Save method and save the output PDF file.The TextBuilder object created from that particular page – to which you want to add the text – allows you to add the TextFragment object to the page using the AppendText method. ![]() Create a TextFragment object with the input text along with other text properties.Get the particular page to which you want to add the text.Open the input PDF using the Document object.Specify character Spacing when adding Text.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |