Results 1 to 1 of 1
Thread: PDF Printing - Margin Problem
- 01-24-2011, 10:15 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
PDF Printing - Margin Problem
Java JRE version 1.6.0_18
Hi there,
I'm trying to set the margin of a pdf page that is being sent to my printer from an applet. The two methods I've tried are setImageableArea and I've also tried to pass PrintRequestAttributeSet to the print job but neither seem to work.
Is there any other way to set the margin on my printout?
thanks,
faoilean.
Java Code:import javax.print.PrintService; import java.awt.print.Book; import java.awt.print.PageFormat; URL pdfFile = new URL(pdfURLStr); write_message("Printing URL: " + pdfURLStr); document = PDDocument.load(pdfFile); List pages = document.getDocumentCatalog().getAllPages(); if (pages.isEmpty()) { write_message("Pages list is empty"); } else { write_message("Pages list is NOT empty"); Iterator it = pages.iterator(); while (it.hasNext()) { PDPage currentPage = (PDPage) it.next(); Map map = currentPage.findResources().getFonts(); write_message("Map is: "+map.toString()); Set mySet = map.keySet(); Iterator setInt = mySet.iterator(); while (setInt.hasNext()) { String val = (String)setInt.next(); PDType1Font pdt = (PDType1Font)map.get(val); write_message("'"+val+""+pdt.getFontDescriptor().getFontName()+"'"); PDFont currFont = this.loadFontByName(document,pdt.getFontDescriptor().getFontName(),val); if(currFont != null) { currentPage.findResources().getFonts().put(val,currFont); } } } } PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintService(currentPrintService); PageFormat pForm = new PageFormat(); Paper paper = new Paper(); paper.setSize(594.936, 841.536); [B]double margin = 36; // half inch paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2, paper.getHeight() - margin * 2); pForm.setPaper(paper);[/B] Book book = new Book(); book.append(document.getPrintable(0), pForm, (int)document.getDocumentCatalog().getPages().getCount()); printJob.setPageable(book); [B]PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); float xmargin = 0.5f; float ymargin = 0.5f; float w = 595; float h = 842; attributes.add(new MediaPrintableArea(xmargin, ymargin, w - 2*xmargin, h - 2*ymargin, MediaPrintableArea.INCH));[/B] printJob.print(attributes); document.close();
Similar Threads
-
Printing problem
By justlynn in forum NetBeansReplies: 5Last Post: 08-03-2010, 02:41 PM -
Problem printing an array
By denial in forum New To JavaReplies: 3Last Post: 11-01-2009, 10:09 PM -
Printing only one page problem
By AndreiDMS in forum Java 2DReplies: 0Last Post: 10-09-2009, 03:03 AM -
Problem after Printing GUI.
By coldblood22 in forum AWT / SwingReplies: 1Last Post: 04-05-2008, 02:43 PM -
printing problem
By ntpl in forum AWT / SwingReplies: 0Last Post: 11-27-2007, 11:20 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks