Hi all;

I'm merging some pdf files , and while doing this i'm checking whether pages
must be rotate it.
I used the code suggested in the book (using the stamper) :

When executing the code i got the error : =>No such file or directory
and as a result the second doc was not merged into the final
document....(the stamper can't be used 2 times may be ...)
Any idea about how to use the stamper correctly in this case ????? thank u
all.

<code>
 public static void main(String[] args) {
            try {
              List<FileInputStream> pdfs = new ArrayList<FileInputStream>();
              pdfs.add(new
FileInputStream("X:/XXXX//Librairies/lasnscape.pdf"));
              pdfs.add(new
FileInputStream("X:/XXXX//Librairies/RapportLandscape.pdf"));
              FileOutputStream output = new
FileOutputStream("X:/XXXX/Librairies/mergeedFile.pdf");
              MergePDF.concatPDFs(pdfs, output, true);
             
            } catch (Exception e) {
              e.printStackTrace();
            }
          }

         
         
         
          public static void concatPDFs(List<FileInputStream>
streamOfPDFFiles, FileOutputStream outputStream, boolean paginate) {
               
                 Document document = new Document();
                 PdfStamper stamper = null;
            try {
              //Initialize local Params
              Iterator<FileInputStream> iteratorPDFs =
streamOfPDFFiles.iterator();
              List<PdfReader> readersList = new ArrayList<PdfReader>();
              PdfReader pdfReader =null;
              //Create the Final Document
             
              PdfWriter writer = PdfWriter.getInstance(document,
outputStream);
              document.open();
             
              // Create Readers for the pdfs.
              while (iteratorPDFs.hasNext()) {
            System.out.println("--------------------------");
            //Get the File Stream
            FileInputStream pdf = iteratorPDFs.next();
                //Create the PDF reader
            pdfReader = new PdfReader(pdf);
                //Explore the Pages and Build the Final Doc
            // Create a new page in the target for each source page.
            System.out.println("***The Number of Pages
:"+pdfReader.getNumberOfPages());
                for (int pageOfCurrentReaderPDF=1; pageOfCurrentReaderPDF <=
pdfReader.getNumberOfPages();pageOfCurrentReaderPDF++) {
                  document.newPage();
                  PdfImportedPage page = writer.getImportedPage(pdfReader,
pageOfCurrentReaderPDF);
                  System.out.println("My Width => "+page.getWidth()+" My
Height => "+page.getHeight());
                  if(page.getWidth() > page.getHeight()){
                PdfDictionary pageDict =
pdfReader.getPageN(pageOfCurrentReaderPDF);
                pageDict.put(PdfName.ROTATE, new PdfNumber(270));
                System.out.println("The Rotation was done");
                  }//END IF  
                }//END WHILE
                //Add the Reader
                readersList.add(pdfReader);
                stamper = new PdfStamper(pdfReader,outputStream);
                stamper.close();
              }//END WHILE
             
            } catch (Exception e) {
              System.err.println("=>"+e.getMessage());
            } finally{}
          }
        }
</code>
-- 
View this message in context: 
http://itext-general.2136553.n4.nabble.com/Rotate-pages-while-merging-PDF-files-tp3175626p3175626.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to