PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

Problem in PDF document after version changed
http://forum.pdfsharp.de/viewtopic.php?f=2&t=2795
Page 1 of 1

Author:  koolprasad2003 [ Wed Apr 16, 2014 12:13 pm ]
Post subject:  Problem in PDF document after version changed

Hello all
I have a pdf file with version 1.5 and I want to change it to 1.4, I used following code it works fine ! but all hyerplinks and books marks from my PDF document has removed, How can I persist them ?

Here is my code to change version, I used iTextSharp for it
Code:
     public static string WriteCompatiblePdf(string sFilename)
        {
            string sNewPdf = "D:\\test.pdf";

            iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(sFilename);

            // we retrieve the total number of pages
            int n = reader.NumberOfPages;
            // step 1: creation of a document-object
            iTextSharp.text.Document document = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(1));
            // step 2: we create a writer that listens to the document
            iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(sNewPdf, FileMode.Create));
            //write pdf that pdfsharp can understand
            writer.SetPdfVersion(iTextSharp.text.pdf.PdfWriter.PDF_VERSION_1_4);
            // step 3: we open the document
            document.Open();
            iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
            iTextSharp.text.pdf.PdfImportedPage page;

            int rotation;

            int i = 0;
            while (i < n)
            {
                i++;
                document.SetPageSize(reader.GetPageSizeWithRotation(i));
                document.NewPage();
                page = writer.GetImportedPage(reader, i);
                rotation = reader.GetPageRotation(i);
                if (rotation == 90 || rotation == 270)
                {
                    cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
                }
                else
                {
                    cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
                }
            }
            // step 5: we close the document
            document.Close();
            return sNewPdf;
        }


Please help to resolve issue ? or is there any other way so that I can change PDF version ?

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/