Null reference error while saving the document

Hi,

I am trying to create transaparent rectangle into the existing pdf as below:

int alpha = 125;
int green = 255;
int red = 255;
int blue = 0;

Aspose.Pdf.Color alphaColor = Aspose.Pdf.Color.FromArgb(alpha, red, green, blue);

Aspose.Pdf.Document document = new Aspose.Pdf.Document(@“C:\files\pdf\1633407387.pdf”);

Aspose.Pdf.Page page = (Aspose.Pdf.Page)document.Pages[2];

page.PageInfo.Margin.Left = page.PageInfo.Margin.Right = page.PageInfo.Margin.Bottom = page.PageInfo.Margin.Top = 0;
int width = Convert.ToInt32(page.PageInfo.Width);
int height = Convert.ToInt32(page.PageInfo.Height);
Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(width, height);

var left = 272.96013f;//- 100.000f;
var bottom = 442.28571f;// +60.000f;
var hwidth = 316.16611f - 272.96013f;
var hheight = 452.45183f - 442.28571f;
[//Aspose.Pdf.Drawing.Rectangle](https://aspose.pdf.drawing.rectangle/) rect = new Aspose.Pdf.Drawing.Rectangle(0, 0, width, height);
Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(left, bottom, hwidth, hheight);

rect.GraphInfo.Color = (Aspose.Pdf.Color.Yellow);
rect.GraphInfo.LineWidth = 0.01f;
rect.GraphInfo.FillColor = (alphaColor);
[//rect.GraphInfo.T](https://rect.graphinfo.t/)

// Add rectangle object to shapes collection of Graph object
graph.Shapes.Add(rect);
page.Paragraphs.Add(graph);

document.Save(@“C:\files\pdf\1633407387-out.pdf”);

While excuting document.save method it is throwing null refernece error as below:

[NullReferenceException: Object reference not set to an instance of an object.]
Aspose.Pdf.Drawing.Shape.(String , Page , Color , List1 ) +584 Aspose.Pdf.Drawing.Shape.(Page , Color , Color , List
1 ) +91
Aspose.Pdf.Drawing.Shape.(List
1 , Page ) +1292 Aspose.Pdf.Drawing.Graph.(Double& , Double& , Boolean , Lis
1 , Page ) +1873
.() +2868
Aspose.Pdf.Page.(Page ) +1792
Aspose.Pdf.Page.() +50
Aspose.Pdf.Document.ProcessParagraphs() +766
Aspose.Pdf.Document.Save(Stream output) +110
Aspose.Pdf.Document.Save(String outputFileName) +100
_Default.savePdfusingAspose() in c:\Users\mindoriya\Documents\Visual Studio 2012\WebSites\WebSite2\Default.aspx.cs:87
_Default.Page_Load(Object sender, EventArgs e) in c:\Users\mindoriya\Documents\Visual Studio 2012\WebSites\WebSite2\Default.aspx.cs:16
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Can someone please help on this?
Quick response will be really appreciated.

Thanks,
Manish

I tried debugging in it and found that due to alpha getting the error and only for some of the pdf files getting the error while excuting document.save method. when I am removing alpha parameter from the Aspose.Pdf.Color.FromArgb method and keeping it like Aspose.Pdf.Color.FromArgb(red,green,blue) then its executing fine but not getting the color transparency. Attaching the pdf file with it I am getting the error.


Can someone please help on this?

Hi Manish,


Thanks for using our API’s.

I have tested the scenario and have managed to reproduce same problem. For the sake of correction, I have logged it as PDFNET-41463 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Can you please suggest any alternate immediate solution for this issue because this is affecting the release.

Hi Manish,


We are sorry for the inconvenience. I am afraid it is difficult to suggest you any thing before completion of issue investigation. We will share any workaround/ETA with you as soon your issue investigation is completed.

Thanks for your patience and cooperation.

Best Regards,

Hi Ahmad,





Any update on this issue?

Hi Manish,


Thanks for your inquiry. I am afraid your issue is still not resolved as we have recently noticed it. It is pending for investigation in the queue. We will notify you as soon as we made some significant progress towards issue resolution.

We are sorry for the inconvenience.

Best Regards,

Hi Ahmad,

Any update on this issue?

Hi Manish,


Thanks for your patience.

I am afraid the earlier reported issue is still pending for review and is not yet resolved. However the product team will surely consider investigating it as per their development schedule and as soon as we have some definite updates regarding its resolution, we will let you know.

Any update on this issue?

Hi Manish,


Thanks for your patience.

I am afraid the earlier reported issue is still pending for review as the team has been busy fixing other previously reported issues. However the product team will surely consider investigating/fixing it as per development schedule and as soon as we have some definite updates regarding its resolution, we will let you know. Please be patient and spare us little time. We are sorry for this delay and inconvenience.

Hi,

Any update on this as I’ve hit the same issue, only on certain PDFs and as the original poster mentions only if I add an alpha component to the FillColor.

Failing that any known workaround, this is using the latest 19.5 PDF lib

Given how long this issue has been outstanding I can’t believe there isn’t a fix or workaround for it yet?

Simon

@simon.fairey

We apologize that earlier logged issue could not get resolved due to other high priority issues and tasks in the queue. However, we have recorded your concerns and will definitely consider them during investigation of the issue. As soon as we make some significant progress towards issue resolution, we will share with you. Please spare us little time.

We are sorry for the inconvenience.

@simon.fairey

We regret to inform you that the earlier logged ticket is not yet resolved as it is under the phase of investigation at the moment. As soon as its investigation is completed and we have some news about its fix ETA, we will update you within this forum thread. We highly appreciate your patience and comprehension in this regard. Please give us some time.

We apologize for the inconvenience.

The issues you have found earlier (filed as PDFNET-41463) have been fixed in Aspose.PDF for .NET 21.6.