【发布时间】:2010-05-27 06:34:01
【问题描述】:
我确定我在这里犯了一些愚蠢的错误,但是在将 tiff 文件转换为 PDF 时,颜色会反转。我不知道为什么。这是我的代码:
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Image.pdf", FileMode.Create));
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(@"C:\Temp\338814-00.tif");
int total = bm.GetFrameCount(FrameDimension.Page);
document.Open();
PdfContentByte cb = writer.DirectContent;
for (int k = 0; k < total; ++k)
{
bm.SelectActiveFrame(FrameDimension.Page, k);
MemoryStream ms = new MemoryStream();
bm.Save(ms, ImageFormat.Tiff);
Image img = Image.GetInstance(ms.ToArray());
img.ScalePercent(72f / (float)img.DpiX * 100);
img.SetAbsolutePosition(0, 0);
cb.AddImage(img);
document.NewPage();
}
document.Close();
谢谢。
【问题讨论】:
-
您能上传一个在某处造成问题的示例 tiff 图像吗?
-
我复制并粘贴了您的代码(为 iTextSharp.text.Document 类型的文档添加声明)并将 844 页 TIFF 转换为 PDF,但没有看到颜色反转。有没有你没有给我们看的代码?
-
这就是现在所有的代码(错过了我刚刚添加的文档声明行)。已将 tiff 文件上传到此处:2shared.com/photo/tomEXEAS/338814-00.html,但它发生在我扔给它的每张 tiff 图像上。
标签: c# pdf itextsharp tiff