To this method you need to pass the type and size of the font.ĬtFont( font_type, font_size ) You can set the font of the text to the required style using the setFont() method of the PDPageContentStream class as shown below. Using the newLineAtOffset() method, you can set the position on the content stream in the page. Therefore, begin the text using the beginText() method as shown below. While inserting text in a PDF document, you can specify the start and end points of the text using the beginText() and endText() methods of the PDPageContentStream class as shown below. PDPageContentStream contentStream = new PDPageContentStream(doc, page) You need to pass the document object and the page object to the constructor of this class therefore, instantiate this class by passing these two objects created in the previous steps as shown below. You can insert various kinds of data elements using the object of the class PDPageContentStream. Retrieve the object of the required page by passing its index to this method as shown below. You can get the required page in a document using the getPage() method. Therefore, instantiate this class and load the required document as shown below.įile file = new File("Path of the document") You can load an existing document using the load() method of the PDDocument class. You can add contents to a document using the PDFBox library, this provides you a class named PDPageContentStream which contains the required methods to insert text, images, and other types of contents in a page of a PDFDocument.įollowing are the steps to create an empty document and add contents to a page in it. In this chapter, we will discuss how to add text to an existing PDF document. In the previous chapter, we discussed how to add pages to a PDF document.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |