This discussion is archived
1 Reply Latest reply: Oct 22, 2012 2:12 PM by Hurukan RSS

PageRanges issue -- printing

Hurukan Newbie
Currently Being Moderated
Greetings,

I'm trying to print some pages from a pdf document (special thanx to the iText library team) (i.e: 4,9 and 12).
I think I did all good but the printer prints the entire document (bypassing the PrintRequestAttribute object passed to the print() method).

When steppin' into the code, I got the right number of Attributes, and the Attributes map let me check if the PageRanges object is getting the right values: that is the case.
Boolean testPrint=false;
testPrint=Reglages.add(new PageRanges(4));
dpjCSSMBulletins.print(DocToPrint, Reglages);
testPrint=Reglages.remove(PageRanges.class);
testPrint=Reglages.add(new PageRanges(12));
dpjCSSMBulletins.print(DocToPrint, Reglages);
testPrint=Reglages.remove(PageRanges.class);
testPrint=Reglages.add(new PageRanges(9));
dpjCSSMBulletins.print(DocToPrint, Reglages);
Each time the add() and remove() returned "true", and I can see the changes in the debug window in the IDE.
I can't explain why when I'm looking at the printer status (using lpq on Linux) the document to be printed is full (250000 bytes) and when printing I got the first page instead of the fourth... I stopped right there and never went further.

The javadoc information says:
public PageRanges(int member)

    Construct a new page ranges attribute containing a single integer. That is, only the one page is to be printed. 
Is anybody knows if there is limitations or particular bugs using this class ?
Thanx in advance ^^
  • 1. Re: PageRanges issue -- printing
    Hurukan Newbie
    Currently Being Moderated
    I have a work around to those who are in the same situation: if this is not possible to print a particular page then it is better to create a file with this page (here I worked on a pdf using the iText library)
      private void CopyPageToSinglePagedPDFdfFile(String source, String target, int PageNumber) throws java.io.FileNotFoundException, DocumentException, IOException
      {
           Document doctocopy=new Document();
           PdfCopy copy = new PdfCopy(doctocopy, new FileOutputStream(target));
                
           doctocopy.open();
                
           PdfReader SourceFile=new PdfReader(source);
    
           PdfImportedPage pagetocopy;
           PdfCopy.PageStamp stamp;
    
           pagetocopy=copy.getImportedPage(SourceFile, PageNumber);
           stamp = copy.createPageStamp(pagetocopy);
    
           copy.addPage(pagetocopy);
    
           doctocopy.close();
           copy.close();
           SourceFile.close();
      }
    Hope it will help you as it did for me ^^

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points