I'm trying to rotate pages of a document. I'm having an issue with the
PdfReader. When created with the FileInputStream constructor pages are
rotated, when created with the RandomAccessFileOrArray pages are not
rotated. I'm using the 2.1.7.  Here is test class.

public class TestRotate {

        
        public static void main(String[] args) throws IOException,
DocumentException {
                String inputFile = "/home/user/ChapterSection.pdf";
                String outFile = "/home/user/RotatedChapterSection.pdf";
                String outFile2 = 
"/home/user/RotatedChapterSectionWithRandomArray.pdf";
                
                //first
                PdfReader pdfReader = new PdfReader(new 
FileInputStream(inputFile));
                rotate(pdfReader, outFile);
                
                //second
                PdfReader pdfReader2 = new PdfReader(new
RandomAccessFileOrArray(inputFile), null);
                rotate(pdfReader2, outFile2);
        

        }
        
        private static void rotate(PdfReader pdfReader, String outFile) throws
FileNotFoundException, DocumentException, IOException{
                PdfStamper pdfStamper;                          
                int pdfNumberOfPages = pdfReader.getNumberOfPages();
                
                for(int j=1; j<=pdfNumberOfPages; j++){
                        PdfDictionary dictionary = pdfReader.getPageN(j);
                        int rotationDegrees = 
(90+pdfReader.getPageRotation(j))%360;
                        dictionary.put(PdfName.ROTATE, new 
PdfNumber(rotationDegrees));                         
                }
                
                pdfStamper = new PdfStamper(pdfReader, new 
FileOutputStream(outFile));
                pdfStamper.close();
                pdfReader.close();
                System.out.println(outFile+" created");
        }

}
-- 
View this message in context: 
http://www.nabble.com/Pages-rotation-and-RandomAccessFileOrArray-tp24665651p24665651.html
Sent from the iText - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to