1

I'm new to Aspose PDF. I don't understand why I'm getting this cross reference error. This happens when the image is being added to the pdf file.

Below is the code sample.

// Gets the image file to be merged with the document
var b1 = GetDocumentFile(imageLayer.UNIQUE_ID);
if (b1.File.DocumentLayer?.PAGE_NUMBER != null)
{
    var i = b1.File.DocumentLayer.PAGE_NUMBER.Value;
    var pngBin = EFSUtil.ReadFileFromFileServer(b1.File.FullFilePathAndName, b1.Server);

    pngBin = CheckIfWebPAndProcess(pngBin);

    //open document based ont eh stream
    var pdfDocument = new Document(pdfMemoryStream);
    var rect = pdfDocument.Pages[i].GetPageRect(true);
    pdfDocument.Pages[i].AddImage(new MemoryStream(pngBin), rect); <-- Error hit here

    var bMemStrm = new MemoryStream();
    pdfDocument.Save(bMemStrm);
    pdfMemoryStream = bMemStrm;
}

I tried to get some valuable information as to why the error happened during the AddImage() and I also tried to understand why the error happened and how to resolve it but was unsuccessful. The nearest that I could look for are these links.

Manipulate Images

Page class

I hope you can help me with this. Thank you

UPDATE

Not sure if this would help, but here's the stacktrace when the issue occurred in the AddImage

   at   .   ​()
   at   .(Int32 , Int32& )
   at   .   ​(Int32 )
   at ​  .(Int32 )
   at Aspose.Pdf.OperatorCollection.79au5vc3bv4m9r8vf6tce224vh3rwyeh ​()
   at Aspose.Pdf.OperatorCollection.(IList )
   at Aspose.Pdf.OperatorCollection.(IList ,  )
   at Aspose.Pdf.OperatorCollection.(List`1 )
   at Aspose.Pdf.OperatorCollection.Add(ICollection ops)
   at Aspose.Pdf.Page.(Stream , Rectangle , Matrix , CompositingParameters , Boolean , Boolean ,   & )
   at Aspose.Pdf.Page.(Stream , Rectangle , Matrix , CompositingParameters ,   & )
   at Aspose.Pdf.Page.AddImage(Stream imageStream, Rectangle imageRect)
Musikero31
  • 3,115
  • 6
  • 39
  • 60
  • Hi, I work as support developer at Aspose. I have tested the scenario with one of my sample PDFs while using Aspose.Pdf for .NET 17.7, and I was unable to notice the exception at AddImage() method, which you have mentioned. Sometimes, it is quite possible that issue is related to specific document or input files. Would you please share your sample document along with the sample image, so that we can test the scenario again and address it accordingly. – Asad Ali Aug 01 '17 at 21:25
  • Furthermore, it would also be appreciated if you please can share the definition of the method "ReadFileFromFileServer()" and specific page number of your sample document, where you are trying to add the image. We will test the scenario in sample Asp.NET Application and get back to you accordingly. – Asad Ali Aug 01 '17 at 21:28
  • @AsadAli, `ReadFileFromFileServer()` gets the file from the server and converts it to byte array. But sad to say, I cannot share the sample document or the image as this is confidential. However, could you give more information when you said that the issue is related to specific document or input file? Like what certain issues that this happens? – Musikero31 Aug 01 '17 at 22:47
  • performance of the API depends upon many factors, i.e structure and complexity of the input document, API version, Environment in which you are using the API, etc. In case if you cannot share your document here, you may post a private inquiry on official Aspose.Pdf forums at https://forum.aspose.com/c/pdf. This way your document will only be accessible for Aspose Staff. – Asad Ali Aug 02 '17 at 14:41

1 Answers1

2

I found out that my PDF did have problems. I was able to validate this through this link

3-HEIGHTS™ PDF VALIDATOR ONLINE TOOL

Musikero31
  • 3,115
  • 6
  • 39
  • 60