Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Jun 16, 2021 5:08 am

Hi
I am spliting files into multiple pdf and processing those pdf to save each page as image. But I am getting below exception
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at spr?.?()
at spr?.?()
at spr?.?()
at spr?.?(spr? A_0)
at spr?.?(spr? A_0)
at spr?.?(String[] A_0)
at spr?.?(spr? A_0)
at spr?.?()
at spr?.?(Boolean A_0)
at spr?.?(Graphics A_0, spr? A_1, spr? A_2)
at spr?.?(String[] A_0)
at spr?.?(spr? A_0)
at spr?.?()
at spr?.?(Boolean A_0)
at spr?.?(Graphics A_0, spr? A_1, spr? A_2, spr? A_3, Image A_4)
at spr?.?(Int32 A_0, Int32 A_1, Int32 A_2)
at Spire.Pdf.PdfDocumentBase.?(Int32 A_0, Int32 A_1, Int32 A_2)
at Spire.Pdf.PdfDocument.SaveAsImage(Int32 pageIndex, Int32 dpiX, Int32 dpiY)

Program:
PdfDocument pdfDocument = new PdfDocument(@"HDFC_2020.pdf");

PdfDocument pdf1 = new PdfDocument();
PdfDocument pdf2 = new PdfDocument();
PdfDocument pdf3 = new PdfDocument();
PdfDocument pdf4 = new PdfDocument();
PdfPageBase page;

for (int i = 0; i <= 100; i++)
{
page = pdf1.Pages.Add(pdfDocument.Pages[i].Size, new Spire.Pdf.Graphics.PdfMargins(0));
pdfDocument.Pages[i].CreateTemplate().Draw(page, new System.Drawing.PointF(0, 0));
}
//pdf1.Close();


for (int i = 101; i <= 200; i++)
{
page = pdf2.Pages.Add(pdfDocument.Pages[i].Size, new Spire.Pdf.Graphics.PdfMargins(0));
pdfDocument.Pages[i].CreateTemplate().Draw(page, new System.Drawing.PointF(0, 0));
}

for (int i = 201; i <= 300; i++)
{
page = pdf3.Pages.Add(pdfDocument.Pages[i].Size, new Spire.Pdf.Graphics.PdfMargins(0));
pdfDocument.Pages[i].CreateTemplate().Draw(page, new System.Drawing.PointF(0, 0));
}

for (int i = 301; i <= 422; i++)
{
page = pdf4.Pages.Add(pdfDocument.Pages[i].Size, new Spire.Pdf.Graphics.PdfMargins(0));
pdfDocument.Pages[i].CreateTemplate().Draw(page, new System.Drawing.PointF(0, 0));
}

pdfDocument.Close();
pdfDocument.Dispose();


for (int i = 0; i <= 100; i++)
{
var image = pdf1.SaveAsImage(i, 300, 300);
Console.WriteLine("Saved Image :" + i);
//image.Save(str);
//Console.WriteLine(str);
}

Application developed in .net core 3.1.

I am unable to attach file as it is more than 2MB, but file can be downloaded from
https://www.bseindia.com/bseplus/Annual ... 100320.pdf


How to resolve this exception ?

raman123
 
Posts: 4
Joined: Wed Jan 13, 2021 10:20 am

Wed Jun 16, 2021 8:39 am

Hello,

Thanks for your inquiry.
I'm sorry that the PDF file in the link you provided is not available. I simulated a PDF file and tested your case, but I did not reproduce your issue. To help us reproduce your issue and help you solve it, please provide your input file to help us investigate further. You could send it to us (support@e-iceblue.com) via email. Thanks in advance.

Sincerley,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Thu Jun 17, 2021 9:13 am

Hello Raman,

Thanks for providing your input file via email.
I tested your case and did reproduce your issue. I have logged it in our bug tracking system with the ticket SPIREPDF-4392. If there is any update, we will let you know. Apologize for the inconvenience caused.
If you have any other questions related to our products, please feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Jun 18, 2021 10:39 am

Hello Raman,

Hope you are doing well.
This is to tell you the update about the issue SPIREPDF-4392. After further investigation, we found that it is because before converting pdf1 object to image, you invoked the methods "pdfDocument.Close()” and ”pdfDocument.Dispose()" to release the pdfDocument object. Actually, before your saving pdf1 to files, it will always maintain the reference to the object pdfdocument.
Thus, please invoking the two methods "pdfDocument.Close()” and ”pdfDocument.Dispose()" after the conversion is finished.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Thu Jun 24, 2021 9:34 am

Hello Raman,

Has your issue been resolved? Any feedback will be greatly appreciated.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.PDF