

Consider following simple Struts Action class which uses this mechanism to generate a dummy PDF and sent the output to browser.

Hence the PDF should be generated on fly and sent to client browser. the path of the file where the PDF is to be created. The constructor of this class accepts a string, i.e. The PdfWriter class represents the DocWriter for a PDF. These are the steps that should be followed to Draw a line in a PDF using java. Generate PDF as Output Stream in HTTP request Sometime we may want to add the PDF generation functionality to a web application, where user on clicking some link or button is served with PDF output. For drawing a line in a PDF, we will use the iText library. Thus in our case we have created a output file and sent output to it. Also, by supplying OutputStream object to getInstance() method sends the output to OutputStream.
#Pdfwriter android code
OutputStream file = new FileOutputStream( new File( "D:\\Test.pdf")) ĭocument.add( new Paragraph( "Hello World, iText")) ĭocument.add( new Paragraph( new Date().toString())) Ĭode language: Java ( java )In above code snippet we have created Document object which represents our PDF document. After you execute this, a file Test.pdf will be created in C: drive (If you are using Linux, you may want to have /usr/test.pdf as path). All you have to do is to put itext.jar in your class path and paste following code in GeneratePDF.java class and compile and execute it. Getting iText Download iText jar from its home page iText core: iText-5.2.1.jar Generate simple PDF in Java using free Java-PDF library It is very easy to generate a simple PDF file in Java using iText. Technical Requirements to use iText You should have JDK 1.4 or later to integrate iText PDF generation in your application.
