本文介绍了iTextSharp writer.AddDirectImageSimple抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当代码看起来正确时,编写器抛出错误可能会出现什么问题?图像也存在。

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)


推荐答案

这不是您将图像添加到PDF的方式。方法 AddDirectImageSimple 仅供专家使用。

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);

这篇关于iTextSharp writer.AddDirectImageSimple抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 04:25