tags:

views:

12

answers:

0

How do I scale a pdf page, while maintaining rotation in itextsharp? I have the following, but I lose rotation:

    public static void ScaleToLetter(string inPDF, string outPDF)
    {
        PdfReader reader = new PdfReader(inPDF);
        Document doc = new Document(PageSize.LETTER);
        Document.Compress = true;
        PdfWriter writer = PdfWriter.GetInstance(doc, 
            new FileStream(outPDF, FileMode.Create));
        doc.Open();
        PdfContentByte cb = writer.DirectContent;
        int rotation;

        PdfImportedPage page;
        for (int pageNumber = 1; pageNumber <= reader.NumberOfPages; pageNumber++)
        {
            page = writer.GetImportedPage(reader, pageNumber);
            rotation = reader.GetPageRotation(pageNumber);

            cb.AddTemplate(page, 
                PageSize.LETTER.Width / reader.GetPageSize(pageNumber).Width, 
                0, 0, 
                PageSize.LETTER.Height / reader.GetPageSize(pageNumber).Height, 
                0, 0);
            doc.NewPage();
        }
        doc.Close();
    }