| | |
Java Printing only one page problem
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2009
Posts: 28
Reputation:
Solved Threads: 2
Hi,
I have a printable class that needs to print some text only on 1 page.
The thing is that when I hit print the printer prints 3 pages:
page 1 - with correct content
page 2 - empty page
page 3 - page with content translated some how
then the printing stops.
Here is the code:
Any help would be appreciated!
Thanks!
I have a printable class that needs to print some text only on 1 page.
The thing is that when I hit print the printer prints 3 pages:
page 1 - with correct content
page 2 - empty page
page 3 - page with content translated some how
then the printing stops.
Here is the code:
Java Syntax (Toggle Plain Text)
private static final double FACTOR = 2.83; private double width, height; private void setupJob(){ // page width and height width = 75*FACTOR; height = 50*FACTOR; job = PrinterJob.getPrinterJob(); pf = new PageFormat(); //PageFormat pf =job.pageDialog(job.defaultPage()); aset = new HashPrintRequestAttributeSet(); // Create a letter sized piece of paper with one inch margins paper = new Paper(); // resize the paper and the imageable area paper.setSize(width, height); paper.setImageableArea(0, 0, width, height); // set paper for the pageFormat pf.setPaper(paper); // set the job printable by calling the painter of this object with the pf pageFormat job.setPrintable(this, pf); job.setCopies(1); // set the media printable area in mm aset.add(new MediaPrintableArea( 0f, 0f, 75f, 50f, MediaPrintableArea.MM)); try { job.print(aset); } catch (PrinterException e) { e.printStackTrace(); } } @Override public int print(Graphics g, PageFormat pf, int page) throws PrinterException { if (page > 0) { // We have only one page return NO_SUCH_PAGE; }else{ Graphics2D g2d = (Graphics2D)g; // no translation needed // g2d.translate(11.34f, 0); // scale to fit page size double sx = 0, sy = 0; sx = width/(75*4); sy = height/(50*4); double scale = Math.min(sx, sy); g2d.scale(scale,scale); // draw the elements for (int i=0; i<4; i++){ texts[i].drawText(g); } } return PAGE_EXISTS; }
Any help would be appreciated!
Thanks!
•
•
Join Date: Nov 2009
Posts: 2
Reputation:
Solved Threads: 0
I don't know why it's not working for you. This class definitely allows me to print multi-page files. Are you sure the page is fully loaded before you try to start printing? Could that be your problem
Techstore are specialists in a range of Printing Services.
![]() |
Similar Threads
- Need help with substitution cipher in Javascript (JavaScript / DHTML / AJAX)
- JSP Login Page (JSP)
- Printing problem (Java)
- problem with my java (Java)
- Data in spreadsheet is not printing on same page (Visual Basic 4 / 5 / 6)
- help needed in printing in java :( (Java)
- problem ragarding printing a page (HTML and CSS)
- Lexmark printer Z53 stops printing in middle of page (OS X)
- Printing in Java (Java)
- DSO Exploit + VX2/F problem along with brower home page problem (Viruses, Spyware and other Nasties)
Other Threads in the Java Forum
- Previous Thread: JButton text color
- Next Thread: How can my LAN-Chat work over INTERNET?
Views: 1227 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for java, print, problem
.net 6 actuate advice ajax android api apple applet application array asp automation binary browser bug c# c++ class classes code component constructor convert database design development digit display draw eclipse encode error event exception file firefox fractal game google gui homework html hyper image input int integer java javafx javascript jetbrains jmf jsp julia linux linuxmagazine loop magazines method microsoft mysql netbeans newbie news object openjavafx oracle page php post print problem programming project python search security server set signing size socket software sort springsource stop string sun swing template test threads time tomcat transfer tree ubuntu web windows






