Follow Us

jPDFProcess

Streaming large PDF documents from java servlet one page at at a time

posted Jun 7, 2012, 2:22 PM by Leila Holmann   [ updated Jun 7, 2012, 2:27 PM ]

Q: My primary goal from this library is to allow the PDF to stream from java servlet to jsp page. Many of the  pdfs are large document and contain tiffs. It takes a while for the user to see anything display on the screen. Is there a way to bring back the 1st pages of the pdf & immediately display them to the user screen WHILE the rest of the PDF loads ?

A:
Yes, you can do this with our PDF library jPDFProcess:  You will just need to tell jPDFProcess to save the document as a "linearized" document.  Linearized documents contain all the information to render the first page of a PDF document at the top of the file.  If the end user is opening the document with Adobe Reader in the browser, Reader will display the first page as soon as it downloads its data, and then continue to download the rest of the document in the background.

To do this, instead of calling one of the saveDocument() methods, you will need to call the saveDocumentLinearized() method:               

PDFDocument.saveDocumentLinearized (OutputStream outStream)

Read more information about PDF linearization.

PDF overlay and imposition

posted Mar 27, 2012, 10:49 AM by Leila Holmann   [ updated Mar 27, 2012, 11:22 AM ]

Q:How can I generate a PDF document from overlaying one pdf document on another? We're trying to overlay our company's letterhead onto existing documents.

A:Our Java PDF library jPDFProcess can overlay one document on top of another. 

The function to look at is called appendPageContent and is found at the page level.

Note that the same function can be used for many purposes:

  • overlay one page on top of another

  • but also draw or impose multiple pages on a big page  (this process is also called imposition in the pre-press / print industry).


The following lines of code illustrate how to load two documents, overlay the first page from one document onto the first page of the first document, and then save the resulting document:

            PDFDocument pdf1 = new PDFDocument("input1.pdf", null);

            PDFDocument pdf2 = new PDFDocument("input2.pdf", null);


            PDFPage page1 = pdf1.getPage(0);

            PDFPage page2 = pdf2.getPage(0);

           

            page1.appendPageContent(page2, 0, 0, 1, 1);

           

            pdf1.saveDocument("output.pdf");

 

The arguments are the x, y positions on the target page and the x and y scales.  You can find the details in the Javadoc documentation.

Linearizing existing PDF documents

posted Mar 19, 2012, 12:04 PM by Leila Holmann   [ updated Mar 29, 2012, 7:06 AM ]

Q: Can jPDFProcess create linearized PDF documents / save existing PDF documents as linearized?

A: Yes, as of version 4.70, released in March 2012, jPDFProcess can create linearize PDF documents. 

To linearize a PDF document with Qoppa's java PDF library jPDFProcess, a single line of code does the trick:

    new PDFDocument(“file.pdf”).saveDocumentLinearized(new FileOutputStream(“linearizedfile.pdf”));

What is PDF linearization and why are PDF documents linearized?

A linearized PDF is a PDF file that has all the objects ordered in a specific way and with a couple of additional special objects added. The linearized PDF format is completely compatible with the regular pdf format, and a viewer does not need to know anything about linearization to process a linearized PDF .

The purpose of linearization is so that a viewer that does understand the linearization format can display the first page in the document as quickly as possible over a potentially slow network connection and then to subsequently jump to any other individual page requested by the user as quickly as possible, without ever having to download data that is only required for other pages.

A linearized PDF file starts with a linearization dictionary, a cross reference table for all of the first page objects, a special PDF stream object called the hint stream,  and then  all of the objects needed to render the first page. After that all of the objects for all the other pages appear in the file grouped by the page they belong to or, if used by more than one page, in the shared object group. And finally any objects not necessarily needed for page rendering appear followed by a cross reference table for the non-first page objects.

The hint stream is a compact table that can tell a linearization aware viewer which objects are required for any one page, and the file offsets of each of those objects. That way the viewer need only download the first part of the file up to the end of the hint stream, and then send download requests for specific file segments to a web server to be able to display any other page the user may wish to view (e.g. by following a link in the bookmarks, etc.)

Code Sample: Create PDF with embedded files

posted Jan 26, 2012, 8:10 AM by Leila Holmann   [ updated Feb 28, 2012, 7:48 AM ]

This java program create a single page PDF document and adds 3 embedded files within the PDF document as file attachments using http://www.qoppa.com/pdfprocess.

http://www.qoppa.com/pdfprocess/guide/sourcesamples/FileAttachments.java

jPDFProcess java API

posted Nov 10, 2011, 7:20 AM by Leila Holmann

Q: Where can I find jPDFProcess javadoc API?

A: You can find the API specification for the latest version of our library jPDFProcess on our website at this link. jPDFProcess is a java library to modify and manipulate PDF documents in Java.

Add a Table of Content (TOC) to a PDF document with Java

posted Aug 23, 2011, 12:56 PM by Leila Holmann

This Java program creates a table of contents at the head of the document using Qoppa's PDF library jPDFProcess. This sample adds a page at the top of the document and then adds a page title and a link to every page in the document.

Click here to view the java code.

Code Sample: Add a bookmark for every page of a PDF document with java

posted Aug 23, 2011, 12:52 PM by Leila Holmann

This Java programs adds a bookmark for every page in a PDF document using Qoppa's library jPDFProcess.

Click here to view the java code.


Code Sample: Flatten PDF Interactive Form Fields in Java

posted Aug 23, 2011, 12:44 PM by Leila Holmann   [ updated Aug 23, 2011, 12:52 PM ]

This Java program "flattens" field data into the PDF content layer using Qoppa's PDF library jPDFProcess.

This means that the field contents will become part of the PDF content and so the document will not be editable anymore.

Click here to view java code.

jPDFProcess supports many PDF functions to work with PDF documents within Java. If you're only looking to work with interactive PDF Forms, please look at our library jPDFFields.


Code Sample: Add watermark to PDF document in Java

posted Aug 23, 2011, 12:35 PM by Leila Holmann   [ updated Mar 29, 2012, 6:55 AM ]

This Java program adds a semi-transparent watermark to a PDF document using Qoppa's library jPDFProcess.

http://www.qoppa.com/pdfprocess/guide/sourcesamples/AddWatermark.java.

Code Sample: Print a PDF document in Java

posted Aug 23, 2011, 12:30 PM by Leila Holmann   [ updated Feb 28, 2012, 7:49 AM ]

A simple Java program that prints a PDF document using Qoppa's PDF library jPDFProcess.

Click here to view the java code.

jPDFProcess is a library that supports many PDF functions to work with PDF documents in Java. If you're only looking to print PDF documents, our library jPDFPrint may be enough.


1-10 of 12