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

PDFSharp 1.5 beta3b loses form fields that 1.32 handled ok
http://forum.pdfsharp.com/viewtopic.php?f=3&t=3345
Page 1 of 1

Author:  pettys [ Thu Apr 21, 2016 7:05 pm ]
Post subject:  PDFSharp 1.5 beta3b loses form fields that 1.32 handled ok

I use PDFSharp to combine multiple PDF's into a single one. Some of our PDF's have iref's, so I updated to 1.5 beta3b. Our irefs work now (yay!) but the fillable fields in other PDF's no longer pass through unchanged -- their shape is there, but their fill-ability is gone.

I've attached the sample-pdfs.zip, which contains the input file used, the good 1.32 output PDF, and the bad 1.5 beta3b output PDF.

Here's my code used to generate the outputs:

Code:
[TestCase("input.pdf")]
public void Test(string fileCsv) {
   var files = fileCsv.Split(',');
   var mainDoc = new PdfDocument();
   foreach (var file in files) {
      var fullPath = Path.Combine(@"..\..\Pdfs", file);
      var toAppend = PdfReader.Open(fullPath, PdfDocumentOpenMode.Import);
      foreach (PdfPage page in toAppend.Pages) {
         mainDoc.AddPage(page);
      }
   }
   mainDoc.Save(@"..\..\Pdfs\combine-" + fileCsv);
}


If you can point me in the right general direction on the github source, with a bit of narrative of what may have changed, I'd be glad to see what I can do with it. Or if we can hire you for a few hours to fix it, that might be an option, too.

Thanks!
Jason

Attachments:
sample-pdfs.zip [28.16 KiB]
Downloaded 373 times

Author:  zaryk [ Mon Nov 28, 2016 5:09 pm ]
Post subject:  Re: PDFSharp 1.5 beta3b loses form fields that 1.32 handled

Hey, not sure if this has been addressed, but annotations are missing from the bad pdf. It looks like the annotations are not being copied over. I have not looked into the reason why this may be.

Code:
        PdfPage ImportExternalPage(PdfPage importPage)
        {
            if (importPage.Owner._openMode != PdfDocumentOpenMode.Import)
                throw new InvalidOperationException("A PDF document must be opened with PdfDocumentOpenMode.Import to import pages from it.");

            PdfPage page = new PdfPage(_document);

            // ReSharper disable AccessToStaticMemberViaDerivedType for a better code readability.
            CloneElement(page, importPage, PdfPage.Keys.Resources, false);
            CloneElement(page, importPage, PdfPage.Keys.Contents, false);
            CloneElement(page, importPage, PdfPage.Keys.MediaBox, true);
            CloneElement(page, importPage, PdfPage.Keys.CropBox, true);
            CloneElement(page, importPage, PdfPage.Keys.Rotate, true);
            CloneElement(page, importPage, PdfPage.Keys.BleedBox, true);
            CloneElement(page, importPage, PdfPage.Keys.TrimBox, true);
            CloneElement(page, importPage, PdfPage.Keys.ArtBox, true);
#if true
            // Do not deep copy annotations.
            //CloneElement(page, importPage, PdfPage.Keys.Annots, false);
#else
            // Deep copy annotations.
            CloneElement(page, importPage, PdfPage.Keys.Annots, true);
#endif
            // ReSharper restore AccessToStaticMemberViaDerivedType
            // TODO more elements?
            return page;
        }

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