PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 10:24 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Aug 31, 2018 1:23 pm 
Offline

Joined: Wed Feb 14, 2018 10:28 am
Posts: 9
Hi,

I am loading a PDF document into a PDFSharp Form which contains text comments (or annotations, I mean the same thing). Using PDFSharp GDI 1.50.4845-RC2a I am creating a new PDF from the existing one, changing the page size, adding a margin and saving the new PDF. The saved PDF loses the 2 comments that were in the original PDF.

I found this comment in PDFSharp.PdfPages from GitHub source control:
Code:
/// Important: In contrast to PdfFormXObject adding an external page always make a deep copy
/// of their transitive closure.


I found the following thread that didn't seem to answer/close this off for me, as the issue referred to is fixed in 1.50.4845-RC2a, and I don't think comes into play when using XPdfForm
viewtopic.php?f=3&t=3659

When I load the Form, form.Page.HasAnnotations = true, and there are (correctly) two annotations in the page elements

Is there a way to keep the annotations in original PDF when creating the new one? Any guidance appreciated, many thanks

Code:
 
           form = XPdfForm.FromFile(Path.Combine(sourceDirectory, sourceFileName));

// Create the output document
 

            PdfSharp.Pdf.PdfDocument outputDocument = new PdfSharp.Pdf.PdfDocument();
            XGraphics gfx;
            XRect box;

            try
            {
                for (int idx = 0; idx < form.PageCount; idx++)
                {
                    // Add a new page to the output document
                    PdfSharp.Pdf.PdfPage page = outputDocument.AddPage();
                    XSize size = PageSizeConverter.ToSize(PdfSharp.PageSize.Letter);

                    if (form.PixelWidth > form.PixelHeight)
                    {
                        page.Width = size.Height;
                        page.Height = size.Width;
                    }
                    else
                    {
                        page.Width = size.Width;
                        page.Height = size.Height;
                    }

                    int rotate = page.Elements.GetInteger("/Rotate");

                    gfx = XGraphics.FromPdfPage(page);

                    box = new XRect(0, 25, page.Width, (page.Height - 25));
                    // Draw the page identified by the page number like an image
                    gfx.DrawImage(form, box);
                    form.PageNumber++;
                }

                form = null;

               
                pdfFileName = sourceFileName;
                outputDocument.Save(Path.Combine(sourceDirectory, pdfFileName));

                isSuccess = true;
             
            }
            catch (Exception ex)
            {
                errorMessage = string.Format("GeneratePDFFromPDF: There was an exception when adding existing PDF <{0}> to Header-formatted final document, ex {1}", sourceFileName, ex);

            }


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 27, 2020 3:52 pm 
Offline

Joined: Thu Aug 27, 2020 3:10 pm
Posts: 2
I had this exact issue using version 1.50.5147.0 (Nuget package). When i copy over annotations they do not scale and actually duplicate the content they are annotating.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 145 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group