PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 9:18 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Fri Jan 12, 2007 5:43 pm 
Offline

Joined: Fri Jan 12, 2007 5:36 pm
Posts: 1
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Mar 08, 2007 11:02 pm 
Offline
empira Employee
User avatar

Joined: Thu Oct 12, 2006 10:07 pm
Posts: 49
Location: Cologne, Germany
If you replace PdfDocumentOpenMode.ReadOnly by PdfDocumentOpenMode.Import (as the error message says) your code will work.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 26, 2009 6:53 am 
Offline

Joined: Thu Nov 26, 2009 1:34 am
Posts: 10
Stefan ,

How to do it? I found PdfDocumentOpenMode is a property in PdfDocument, but it's internal.

Thanks
James


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 26, 2009 9:23 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 26, 2009 9:39 am 
Offline

Joined: Thu Nov 26, 2009 1:34 am
Posts: 10
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 26, 2009 9:43 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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 ...

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 26, 2009 9:48 am 
Offline

Joined: Thu Nov 26, 2009 1:34 am
Posts: 10
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 26, 2009 10:31 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 27, 2009 1:12 am 
Offline

Joined: Thu Nov 26, 2009 1:34 am
Posts: 10
Thanks Thomas,


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 361 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