PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sat Jul 05, 2025 11:35 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Mar 12, 2016 10:25 am 
Offline

Joined: Sat Mar 12, 2016 10:19 am
Posts: 4
hi,
I want to build a container around an existing pdf page, so actually enlarge that document and put it in the middle so that I can write more things into.

What I tried so far :
Code:
                            // Open the file
                        PdfDocument inputDocument = PdfReader.Open(filename, PdfDocumentOpenMode.Import);// PdfReader.Open(filename, PdfDocumentOpenMode.Modify);

                        PdfDocument newContainerDocument = new PdfDocument();

                        // Create an empty page or load existing
                        for (int idx = 0; idx < inputDocument.PageCount; idx++)
                        {
                            PdfPage page = new PdfPage(); //this should be the actual container
                            page.Width = tempWidth;
                            page.Height = tempHeight;

                            //gfx.DrawImage(image, (page.Width / 2) - (width / 2), (page.Height / 2) - (height / 2), width, height); //put it in the middle of  the container, this would only work with IMAGES ... using "XGraphics"

                            // Add the page and save it
                            newContainerDocument.AddPage(inputDocument.Pages[idx]);
                           
                        }

                        newContainerDocument.Save(String.Format("{0} - Page {1}_expandedFile.pdf", insertName,DateTime.Now.Ticks.ToString()));

                        inputDocument.Close();
                        newContainerDocument.Close();


But I get:

Quote:
The document cannot be modified


What is wrong here ?

Thank you


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 12, 2016 3:49 pm 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1051
Location: CCAA
Hi!

Answer can be found here:
http://stackoverflow.com/a/35959688/1015447

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


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 69 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