Posts Tagged ‘PDF’

Print PDF with JPedal

Sunday, August 16th, 2009

Researching a bit about the handling of a PDF document I found a library called JPedal for manipulating PDF documents from Java.
Like other libraries I’ve seen among other iText and iReport, which are very comprehensive and allow you to do many tasks, including printing. Disadvantage that the latter is that you need to have installed Acrobat Reader and for many users this is not possible.
But even with JPedal lets you see the Acrobat Reader tools within the Java application, providing a task pane for the PDF to manipulate.

With PrinterJob.lookupPrintServices can get the services available and print them PrinterJob a concrete one.

PrintService[] psService = PrinterJob.lookupPrintServices();
PrinterJob pjPrintJob = PrinterJob.getPrinterJob();
pjPrintJob.setPrintService(psService[0]);

// Assigns the size of the paper to A4.

Paper paper = new Paper();
paper.setSize(595, 842);
paper.setImageableArea(0, 0, 595, 842);
PageFormat pf = pjPrintJob.defaultPage();
pf.setPaper(paper);

Loads the PDF to be printed. The file is called wc_PDF.pdf printed and given format.

PdfDecoder pdfD = null;
pdfD = new PdfDecoder(true);
pdfD.openPdfFile("wc_PDF.pdf");
pdfD.setPageFormat(pf);

It sends the file to print

printJob.setPageable(pdfD);
printJob.print();

And to finalize the document is closed.

pdf.closePdfFile();

Download JPedal..

The example would then complete as follows:

import java.awt.print.Paper;
import java.awt.print.PrinterJob;
import java.awt.print.PageFormat;
import javax.print.PrintService;
import org.jpedal.PdfDecoder;

public final void wc_PrintPDF() {
    PdfDecoder pdfD = null;
    try {
        PrintService[] psService = PrinterJob.lookupPrintServices();
        PrinterJob pjPrintJob = PrinterJob.getPrinterJob();
        pjPrintJob.setPrintService(psService[0]);

        Paper paper = new Paper();
        paper.setSize(595, 842);
        paper.setImageableArea(0, 0, 595, 842);
        PageFormat pf = pjPrintJob.defaultPage();
        pf.setPaper(paper);

        pdfD = new PdfDecoder(true);
        pdfD.openPdfFile("wc_PDF.pdf");
        pdfD.setPageFormat(pf);

        pjPrintJob.setPageable(pdfD);
        pjPrintJob.print();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        pdfD.closePdfFile();
    }
}

Online HTML to PDF Converter

Wednesday, March 4th, 2009

It’s a simple service to convert the web pages to PDF files. No need to install applications on your computer.
It’s free and without registration!

Enter your URL &  Click button  to create a PDF file.

I converted one of my site. Completed in about 30 seconds.

We saved successfully downloaded to your desktop. PDF is quite accomplished in the sort of outcome, as the screenshots. 

HTML-PDF-converter.com

html2pdf