iTextSharp writer.AddDirectImageSimple throws exception

﹥>﹥吖頭↗ 提交于 2019-12-13 02:57:29

问题


What could be the problem for writer to throw an error, when the code seems correct? Image also exists.

var img2 = iTextSharp.text.Image.GetInstance("C:\\2.bmp");

writer.AddDirectImageSimple(img2);

at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at iTextSharp.text.pdf.PdfWriter.AddDirectImageSimple(Image image, PdfIndirectReference fixedRef)
at iTextSharp.text.pdf.PdfWriter.AddDirectImageSimple(Image image)

回答1:


That's not how you add an image to a PDF. The method AddDirectImageSimple is to be usd by specialists only.

What is your purpose when you use that method? If you want to add an Image to the document, you should use:

document.Add(img2);


来源:https://stackoverflow.com/questions/31095521/itextsharp-writer-adddirectimagesimple-throws-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!