Musikero31
Musikero31

Reputation: 3153

Cross reference table or cross reference stream not found in AddImage function

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)

Upvotes: 1

Views: 2501

Answers (1)

Musikero31
Musikero31

Reputation: 3153

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

3-HEIGHTS™ PDF VALIDATOR ONLINE TOOL

Upvotes: 2

Related Questions