none
Need to convert A4 PDF to Letter PDF with editable contents in C# .Net RRS feed

  • General discussion

  • Hi,

    I have a A4 size PDF doc. There are some fields which is editable in this doc.

    When I am trying to convert A4 to letter , the data in the editable fields are missing.

    Is there any way to convert to letter format from A4 including editable field data?

    I am using below c# code for this.

    inPDF - (A4 format)

    outPDF - (Letter format)

    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;

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

                    if (page.Width <= page.Height)
                        doc.SetPageSize(PageSize.LETTER);
                    else
                        doc.SetPageSize(PageSize.LETTER.Rotate());
                    doc.NewPage();

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

    Wednesday, September 16, 2015 1:41 AM