PDFsharp & MigraDoc Foundation http://forum.pdfsharp.com/ |
|
Getting error SplittingPDF into Mulitple PDFs http://forum.pdfsharp.com/viewtopic.php?f=2&t=51 |
Page 1 of 1 |
Author: | dustin [ Fri Jan 12, 2007 5:43 pm ] |
Post subject: | Getting error SplittingPDF into Mulitple PDFs |
I get this error in PdfSharp.pdf folder- PdfPages.cs- ImportExternalPage when I try to use the sample code for SplitDocument: A PDF document must be opened with PdfDocumentOpenMode.Import to import pages from it. I'm really not sure what I am doing wrong, since the code seems very straight forward. Here is the code I use that gets the error: filename = "test.PDF"; File.Copy(Path.Combine(@"C:\PDFs\", filename), Path.Combine(Directory.GetCurrentDirectory(), filename), true); // Open the file PdfDocument inputDocument = PdfReader.Open(filename, PdfDocumentOpenMode.ReadOnly); string name = Path.GetFileNameWithoutExtension(filename); for (int idx = 0; idx < inputDocument.PageCount; idx++) { // Create new document PdfDocument outputDocument = new PdfDocument(); outputDocument.Version = inputDocument.Version; outputDocument.Info.Title = String.Format("Page {0} of {1}", idx + 1, inputDocument.Info.Title); outputDocument.Info.Creator = inputDocument.Info.Creator; // Add the page and save it outputDocument.AddPage(inputDocument.Pages[idx]); outputDocument.Save(String.Format("{0} - Page {1}.pdf", name, idx + 1)); } Thanks in advance for any help. |
Author: | Stefan Lange [ Thu Mar 08, 2007 11:02 pm ] |
Post subject: | |
If you replace PdfDocumentOpenMode.ReadOnly by PdfDocumentOpenMode.Import (as the error message says) your code will work. |
Author: | jamesgraylock [ Thu Nov 26, 2009 6:53 am ] |
Post subject: | Re: Getting error SplittingPDF into Mulitple PDFs |
Stefan , How to do it? I found PdfDocumentOpenMode is a property in PdfDocument, but it's internal. Thanks James |
Author: | Thomas Hoevel [ Thu Nov 26, 2009 9:23 am ] |
Post subject: | Re: Getting error SplittingPDF into Mulitple PDFs |
jamesgraylock wrote: How to do it? I found PdfDocumentOpenMode is a property in PdfDocument, but it's internal. It's a parameter of Code: PdfReader.Open() PdfReader.Open returns the opened PdfDocument. |
Author: | jamesgraylock [ Thu Nov 26, 2009 9:39 am ] |
Post subject: | Re: Getting error SplittingPDF into Mulitple PDFs |
Thomas This my code: pulic void MyMethod(PdfPage pdfPage) { PdfDocument pdfDocument = new PdfDocument(); pdfDocument.Pages.Add(pdfPage); GS ghostscript = new GS(); System.Drawing.Image image = ghostscript.PdfToPng(pdfDocument, 1, 96); Stream stream = new MemoryStream(); image.Save(stream, System.Drawing.Imaging.ImageFormat.Png); ... } I try to use Reader.Open(), but it need pass in some parameters, I don't know what it stand for. Please help me, thanks James |
Author: | Thomas Hoevel [ Thu Nov 26, 2009 9:43 am ] |
Post subject: | Re: Getting error SplittingPDF into Mulitple PDFs |
Where is that PdfPage pdfPage coming from? Dat's de place where you have to use PdfReader.Open(). Read this thread here carefully: viewtopic.php?p=105#p105 Look at the first post and at the answer in the second post. Look for PdfReader.Open ... |
Author: | jamesgraylock [ Thu Nov 26, 2009 9:48 am ] |
Post subject: | Re: Getting error SplittingPDF into Mulitple PDFs |
PdfPage pdfPage is come from base class in another assembly which I have no source code, I just try to override the abstract method. I don't know if base class use Reader.Open() or not |
Author: | Thomas Hoevel [ Thu Nov 26, 2009 10:31 am ] |
Post subject: | Re: Getting error SplittingPDF into Mulitple PDFs |
That other assembly must be changed - or replaced. No source code? Try .NET Reflector ... PdfReader.Open(...) returns the PdfDocument. You must specify at open that you want to open the document for import. |
Author: | jamesgraylock [ Fri Nov 27, 2009 1:12 am ] |
Post subject: | Re: Getting error SplittingPDF into Mulitple PDFs |
Thanks Thomas, |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |