我是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