我是Aspose PDF的新手。我不明白为什么我得到这个交叉引用错误。当图像被添加到PDF文件时发生这种情况。在AddImage函数中找不到交叉引用表或交叉引用流
以下是代码示例。
// 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;
}
我试图得到一些有价值的信息,为什么AddImage()
期间发生的错误,我也试图理解为什么发生错误以及如何解决它,但没有成功。我能找到的最接近的就是这些链接。
我希望你能帮助我与此有关。谢谢
UPDATE
不知道这会有所帮助,但这里的堆栈跟踪,当问题发生在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)
您好,我作为阅读Aspose支持开发人员合作,以验证这一点。我已经使用Aspose.Pdf for .NET 17.7在我的示例PDF中测试了该场景,并且我无法注意到您提到的AddImage()方法中的异常。有时,这个问题很可能与特定的文档或输入文件有关。您可否将样本文件与示例图片一起分享,以便我们可以再次测试该场景并相应地解决它。 –
此外,如果您可以共享方法“ReadFileFromFileServer()”的定义以及样本文档的特定页码(试图添加图像的位置),那么也会很感激。我们将在示例Asp.NET应用程序中测试场景并相应地回复您。 –
@AsadAli,'ReadFileFromFileServer()'从服务器获取文件并将其转换为字节数组。但可悲的是,我不能分享样本文件或图片,因为这是保密的。但是,当您说问题与特定文档或输入文件有关时,您能否提供更多信息?像发生了什么特定问题? – Musikero31