PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Getting an error when trying to add page numbers.

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
Kennyj



Joined: 19 Nov 2008
Posts: 1

PostPosted: Tue Nov 25, 2008 1:38 pm    Post subject: Getting an error when trying to add page numbers. Reply with quote

I'm getting this error where is says
gfx = XGraphics.FromPdfPage(page);

can someone explain how I need to fix this?

Cannot create XGraphics for a page of a document that cannot be modified. Use PdfDocumentOpenMode.Modify.

Code:

if (checkBox1.Checked == true)
                {
                    MessageBox.Show("Printing Page Numbers.");
                    PdfDocument outputDocument = new PdfDocument();

                    XFont font = new XFont("Verdana", 10, XFontStyle.Bold);
                    XStringFormat format = new XStringFormat();
                    format.Alignment = XStringAlignment.Center;
                    format.LineAlignment = XLineAlignment.Far;
                    XGraphics gfx;
                    XRect box;

                    foreach (string file in pdfList.Items)
                    {

                        PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import);
                        int count = inputDocument.PageCount;

                        for (int idx = 0; idx < count; idx++)
                        {
                            PdfPage page = inputDocument.PageCount > idx ?
                            inputDocument.Pages[idx] : new PdfPage();
                            gfx = XGraphics.FromPdfPage(page);
                            box = page.MediaBox.ToXRect();
                            box.Inflate(0, -10);
                            gfx.DrawString(String.Format("{0} • {1}", file, idx + 1),
                            font, XBrushes.Red, box, format);

                            outputDocument.AddPage(page);


                        }
                    }


Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Wed Nov 26, 2008 8:46 am    Post subject: Reply with quote

The page was opened in Import mode (for import only, i. e. read-only).

It's in the error message: use PdfDocumentOpenMode.Modify instead of PdfDocumentOpenMode.Import if you really want to modify the PDF file you opened.
Or create a new PDF file, copy the contents of the old file and add page numbers to the new file.

With PdfDocumentOpenMode.Modify the source file will not change if you don't call Save.
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com