aspose file tools*
The moose likes Blatant Advertising and the fly likes Add Simple/Underline Text or Border Around Text in a PDF File Using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Blatant Advertising
Bookmark "Add Simple/Underline Text or Border Around Text in a PDF File Using Java" Watch "Add Simple/Underline Text or Border Around Text in a PDF File Using Java" New topic
Author

Add Simple/Underline Text or Border Around Text in a PDF File Using Java

sherazam khan
Ranch Hand

Joined: Mar 10, 2010
Posts: 293
This technical tip shows how to Java Developers can add text in an existing PDF file using Aspose.Pdf for Java. To add text to an existing PDF file Open the input PDF using the Document object and get the particular page to which you want to add the text. After that create a TextFragment object with the input text along with other text properties. The TextBuilder object created from that particular page – to which you want to add the text – allow you to add the TextFragment object to the page using the AppendText method. Now just call the Document object's Save method and save the output PDF file.

The following code snippet shows you how to add text in an existing PDF file.

[Java]

//open document

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("input.pdf");

//get particular page

com.aspose.pdf.Page pdfPage = pdfDocument.getPages().get_Item(1);

//create text fragment

com.aspose.pdf.TextFragment textFragment = new com.aspose.pdf.TextFragment("main text");

textFragment.setPosition(new com.aspose.pdf.Position(100, 600));


//set text properties

textFragment.getTextState().setFont(com.aspose.pdf.FontRepository.findFont("Verdana"));

textFragment.getTextState().setFontSize(14);

textFragment.getTextState().setForegroundColor(Color.BLUE);

textFragment.getTextState().setBackgroundColor(Color.GRAY);


// create TextBuilder object

com.aspose.pdf.TextBuilder textBuilder = new com.aspose.pdf.TextBuilder(pdfPage);

// append the text fragment to the PDF page

textBuilder.appendText(textFragment);
<bt>// save updated PDF file

pdfDocument.save("Text_Added.pdf");

Overview: Aspose.Pdf for Java

Aspose.Pdf is a Java PDF component to create PDF documents without using Adobe Acrobat. It supports Floating box, PDF form field, PDF attachments, security, Foot note & end note, Multiple columns document, Table of Contents, List of Tables, Nested tables, Rich text format, images, hyperlinks, JavaScript, annotation, bookmarks, headers, footers and many more. Now you can create PDF by API, XML and XSL-FO files. It also enables you to converting HTML, XSL-FO and Excel files into PDF.

More about Aspose.Pdf for Java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Add Simple/Underline Text or Border Around Text in a PDF File Using Java