我在使用 itextsharp 从 .tiff 中的图像创建 pdf 时遇到问题。 这是一些代码:
iTextSharp.text.Document d = new iTextSharp.text.Document();
PdfWriter pw = PdfWriter.GetInstance(d, new FileStream(filename, FileMode.Create));
d.Open();
PdfContentByte cb = pw.DirectContent;
foreach (Image img in imgs)
{
d.NewPage();
d.SetPageSize(new iTextSharp.text.Rectangle(0, 0, img.Width, img.Height));
iTextSharp.text.Image timg = iTextSharp.text.Image.GetInstance(img, iTextSharp.text.BaseColor.WHITE);
timg.SetAbsolutePosition(0, 0);
cb.AddImage(timg);
cb.Stroke();
}
d.Close();
它创建了两页的 pdf,但第一页上的图像太大了。
该页面具有图像的大小,但它缩放了图像的左下角。
它只对 tiff 图像执行此操作,如果我使用 png,它工作正常。
有什么解决办法吗?
最佳答案
感谢mkl的评论,我找到了。 在新页面命令(NewPage)之前设置页面大小(SetPageSize)
关于c# - 使用 itextsharp 创建的 pdf 中的错误尺寸图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13046711/