954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PDF printing in Wrong Size from JAVA

Hello everybody!!
I'm trying to print a *.pdf file from Java code, and the printer out gives the right document, but smaller than the original pdf (smaller text, images, margins, everything), the print result seems shrinked from the original...
Here is the code I'm using:

File f = new File("\\Some.pdf");
        FileInputStream fis = new FileInputStream(f);
        FileChannel fc = fis.getChannel();
        Paper paper = new Paper();
        paper.setImageableArea(20, 40, paper.getWidth() - 20, paper.getHeight() - 40);
        ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
        PDFFile pdfFile = new PDFFile(bb);
        PDFPrintPage pages = new PDFPrintPage(pdfFile);
        PrinterJob pjob = PrinterJob.getPrinterJob();
        PageFormat pf = PrinterJob.getPrinterJob().defaultPage();
        pf.setPaper(paper);
        pf = pjob.validatePage(pf);
        pjob.setJobName(f.getName());
        Book book = new Book();
        book.append(pages, pf, pdfFile.getNumPages());
        pjob.setPageable(book);
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        aset.add(MediaSizeName.NA_LETTER);
        aset.add(MediaTray.MIDDLE);
        pjob.print(aset);

Thanks for your possible help,
Greetings!

sick35
Newbie Poster
1 post since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Even I need to know the reason why it happens. If anybody replies it will be helpfull.

sbhavan
Light Poster
45 posts since Oct 2008
Reputation Points: 40
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: