问题
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