Sibi John
Sibi John

Reputation: 485

Print a in memory pdf in Java

I am developing a module where i am supposed to print documents from the server. Following are the requirements :

  1. the module should be able to print a pdf from a url, with & without saving
  2. the module should be able to accept page numbers as parameters and only print/save those page numbers.
  3. the module should be able to accept the printer name as a parameter and use only that printer

Is there any library available for this? How should i go about implementing this?

Upvotes: 0

Views: 213

Answers (1)

Sibi John
Sibi John

Reputation: 485

The answer was Apache PDFBox . I was able to load the PDF into a PDDocument object like this :

PDDocument pdf = PDDocument.load(new URL(download_pdf_from).openStream());

Splitting the document was as easy as :

Splitter splitter = new Splitter();
List<PDDocument> splittedDocuments = splitter.split(pdf);

Now, to get a reference to any particular page:

splittedDocuments.get(pageNo);

Saving the entire document or even a given page number :

pdf.save(path); //saving the entire document to device
splittedDocuments.get(pageNo).save(path); //saving a particular page number to device

For the printing part, this answer helped me.

Upvotes: 1

Related Questions