Java Magazine, July/August 2018
ORACLE COM JAVAMAGAZINE JULY AUGUST 2018 17 libraries add new ListItem Never gonna say goodbye add new ListItem Never gonna tell a lie and hurt you div add list document add div Image img new Image ImageDataFactory create IMG setFixedPosition 300 625 document add img document close Lets examine this code step by step Low level document and writer objects First we created a PdfDocument instance using a PdfWriter as a parameter These are low level objects The PdfWriter is responsible for writing the PDF bits and bytes to a destination In this case the destination is a String defining the path to a file Alternatively the PdfWriter accepts a file or an OutputStream For instance if you want to create a document that exists only in memory you can create a PdfWriter with a ByteArrayOutputStream This is typically done when the file is created on a server but served to a client as is the case with a web application You could now use the You can use the many features available through the iText API to program your document so that it looks exactly the way you want it to look but you can also use shortcuts PdfDocument instance to create a PdfPage instance and then draw content on that page using the low level operators and operands that are described in the PDF ISO 32000 standard However that would be a very tedious job Fortunately you can keep all this heavy lifting under the hood by using iTexts high level options High level objects We used the PdfDocument instance to create a Document object We can then create objects such as Paragraph List and Image and add these objects to the Document
You must have JavaScript enabled to view digital editions.