PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Document null, cant read
PostPosted: Fri Oct 12, 2007 6:26 am 
Offline

Joined: Fri Oct 12, 2007 6:17 am
Posts: 3
Location: Johannesburg Southafrica
I get the following error and i am trying to read a few pdf files to merge them.
This is my read statement: PdfDocument inputDocument = PdfReader.Open(filename1, PdfDocumentOpenMode.ReadOnly);

and it throws this exception at : Debug.Assert(kid.Elements.GetName(Keys.Type) == "/Pages");
PdfPage.InheritValues(kid, ref values);
ArrayList list = new ArrayList();
PdfArray kids = kid.Elements["/Kids"] as PdfArray;
foreach (PdfReference xref2 in kids)

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="PdfSharp"
StackTrace:
at PdfSharp.Pdf.PdfPages.GetKids(PdfReference iref, InheritedValues values, PdfDictionary parent) in C:\Documents and Settings\Wade\My Documents\Work\PDFsharp\PdfSharp\PdfSharp.Pdf\PdfPages.cs:line 359
at PdfSharp.Pdf.PdfPages.FlattenPageTree() in C:\Documents and Settings\Wade\My Documents\Work\PDFsharp\PdfSharp\PdfSharp.Pdf\PdfPages.cs:line 315
at PdfSharp.Pdf.Advanced.PdfCatalog.get_Pages() in C:\Documents and Settings\Wade\My Documents\Work\PDFsharp\PdfSharp\PdfSharp.Pdf.Advanced\PdfCatalog.cs:line 102
at PdfSharp.Pdf.PdfDocument.get_Pages() in C:\Documents and Settings\Wade\My Documents\Work\PDFsharp\PdfSharp\PdfSharp.Pdf\PdfDocument.cs:line 590
at PdfSharp.Pdf.PdfDocument.get_PageCount() in C:\Documents and Settings\Wade\My Documents\Work\PDFsharp\PdfSharp\PdfSharp.Pdf\PdfDocument.cs:line 480
at Pdf_Merge.Form1..ctor() in C:\Documents and Settings\Wade\My Documents\Work\Projects\Pdf Merge\Pdf Merge\Form1.cs:line 67
at Pdf_Merge.Program.Main() in C:\Documents and Settings\Wade\My Documents\Work\Projects\Pdf Merge\Pdf Merge\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Please Please help. could it be that there is a problem with my PDF file even though it opens fine in acrobat 8.
Thank you very much.
Wade :cry:


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 12, 2007 6:35 am 
Offline

Joined: Fri Oct 12, 2007 6:17 am
Posts: 3
Location: Johannesburg Southafrica
Oh and i have also tried to use this code to get my pdf file: PdfDocument inputDocument = PdfReader.Open(filename1, PdfDocumentOpenMode.Import);


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 15, 2007 8:48 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
wadeholm wrote:
Please Please help. could it be that there is a problem with my PDF file even though it opens fine in acrobat 8.

This could be the case - we'd need the PDF file to have a closer look.
I presume your PDF file is untypical - maybe a special case PDFsharp is not prepared for, maybe a buggy PDF file.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 15, 2007 9:52 am 
Offline

Joined: Fri Oct 12, 2007 6:17 am
Posts: 3
Location: Johannesburg Southafrica
Can i just send it to your email or how do i go about doing that
Thank you


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 15, 2007 4:20 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!

I was able to replicate the problem.
It'll work with this change (File PdfPages.cs, around Line 358):

Code:
        PdfArray kids = kid.Elements["/Kids"] as PdfArray;
        //newTHHO 15.10.2007 begin
        if (kids == null)
        {
          PdfReference xref3 = kid.Elements["/Kids"] as PdfReference;
          kids = xref3.Value as PdfArray;
        }
        //newTHHO 15.10.2007 end
        foreach (PdfReference xref2 in kids)
          list.AddRange(GetKids(xref2, values, kid));


There are 5 new lines.

The fix will be included with the next release of PDFsharp.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 17, 2016 2:33 pm 
Offline

Joined: Fri Jun 17, 2016 2:30 pm
Posts: 1
Additionally, the cast to PdfReference needs to be null checked.
I have a pdf that still gets the object ref error from the following:
kids = xref3.Value as PdfArray;


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 20, 2016 8:17 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!
patman wrote:
I have a pdf that still gets the object ref error from the following [...]
Thanks for the feedback.

patman wrote:
Additionally, the cast to PdfReference needs to be null checked.
Checking for null and throwing an exception would be a bit better than not checking for null and getting an exception when using the null object.
Checking for null does not help opening the document.

Would be nice to have that PDF for investigation and testing purposes. Is that possible?

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

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