pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gyenes István <gist...@mve.hu>
Subject PDDocument getPrintable endless loop - resolved
Date Thu, 21 Nov 2013 10:19:16 GMT
*Dear Everibody!*

*I found a solution!**
**
**The print method is same:*
         PDDocument pdf = 
PDDocument.load("c:\\Java\\nb74_projects\\lpu\\AISB08.pdf");
         PrintService[] ps = PrinterJob.lookupPrintServices();
         int x=0;
         for (x=0; x<ps.length; x++) System.out.println(ps[x].getName());
         for (x=0; x<ps.length; x++)  if 
(ps[x].getName().compareTo("Canon Generic PCL6 Driver")==0) break;
         PrinterJob pj = PrinterJob.getPrinterJob();
         pj.setPrintService(ps[x]);
         PrintRequestAttributeSet pset = new HashPrintRequestAttributeSet();
         pset.add(MediaTray.MIDDLE);
         pj.setPrintable(new LpuPrintable123(pdf.getPrintable(0)));
         pj.print(pset);

*But I use an own Object: LpuPrintable, and this Object print only one 
page:*
public class LpuPrintable123 implements Printable{
     private Printable po;
     public Printable getPo() {
         return po;
     }
     public void setPo(Printable po) {
         this.po = po;
     }
     public int print(Graphics graphics, PageFormat pageFormat, int 
pageIndex) throws PrinterException {
        if (pageIndex<1) {
         System.out.println(pageIndex);
         return po.print(graphics, pageFormat, pageIndex);
        }
        return Printable.NO_SUCH_PAGE;
     }
     public LpuPrintable123(Printable po) {
         super();
         this.po = po;
     }
}

*It is may be help for others!*

*Stephen Gyenes*



2013.11.21. 9:02 keltezéssel, Gyenes István írta:
> Dear Gilad Denneboom,
>
> thank you advices, I modify my code, but it still not working.
> The print command looping and newer end. Not one page send to printer, 
> unending page number is sending.
> This is my code now:
>         PDDocument pdf = 
> PDDocument.load("c:\\Java\\nb74_projects\\lpu\\AISB08.pdf");
>         PrintService[] ps = PrinterJob.lookupPrintServices();
>         int x=0;
>         for (x=0; x<ps.length; x++)  if 
> (ps[x].getName().compareTo("Canon Generic PCL6 Driver")==0) break;
>         PrinterJob pj = PrinterJob.getPrinterJob();
>         pj.setPrintService(ps[x]);
>         PrintRequestAttributeSet pset = new 
> HashPrintRequestAttributeSet();
>         pset.add(MediaTray.TOP);
>         pj.setPrintable(pdf.getPrintable(0));
>         System.out.println("print start");
>         pj.print(pset);
>         System.out.println("this message never appear");
>
> Anybody know how should I print one page from a pdf to a specified tray?
>
>
>
>
>
> 2013.11.20. 16:53 keltezéssel, Gilad Denneboom írta:
>> Not sure why it's happening, but why not add a break command when you 
>> find
>> the printer you want to print to (after you sent the print command, of
>> course)?
>> Also, Java arrays are zero-based, so the initial value of x should 
>> probably
>> be 0, not 1.
>>
>>
>> On Wed, Nov 20, 2013 at 4:26 PM, Gyenes István <gistvan@mve.hu> wrote:
>>
>>> Hi All!
>>>
>>> I'm new in BDFBox.
>>> I try to print one page to specified tray, but it is make an endless
>>> printing loop. I do something wrong or it is a bug in the library?
>>> My source code is:
>>>   PDDocument pdf = 
>>> PDDocument.load("c:\\Java\\nb74_projects\\lpu\\AISB08.
>>> pdf");
>>>          PrintService[] ps = PrinterJob.lookupPrintServices();
>>>          for (int x=1; x<ps.length; x++) {
>>>              System.out.println(ps[x].getName());
>>>              if (ps[x].getName().compareTo("Canon Generic PCL6
>>> Driver")==0) {
>>>                  PrinterJob pj = PrinterJob.getPrinterJob();
>>>                  pj.setPrintService(ps[x]);
>>>                  PrintRequestAttributeSet pset = new
>>> HashPrintRequestAttributeSet();
>>>                  pset.add(MediaTray.TOP);
>>>                  pj.setPrintable(pdf.getPrintable(0));
>>>                  pj.print(pset);
>>>              }
>>>          }
>>>
>>> Big thanks for any help!
>>> Stephen Gyenes
>>>
>
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message