【问题标题】:iTextSharp convert to pdf .net Tiles are not supported不支持 iTextSharp 转换为 pdf .net Tiles
【发布时间】:2013-11-20 09:44:17
【问题描述】:

我正在尝试从磁盘读取TIFF 文件并使用iTextSharp 转换为PDF 格式

它工作正常,但除了一些 TIFF 将一些图像放入其中。在这一行出现Tiles are not supported 错误iTextSharp.text.Image.GetInstance(documentPath)

这是我使用的代码

string documentPath="somefile.TIFF";

try
{
  Image myImage = Image.GetInstance(documentPath); //Error here     
  documentPDF.Add(myImage);
  byte[] bytes= ms.GetBuffer();
}
catch (Exception ex)
{
  // Error says tiles are not supported
}

堆栈跟踪:

在 iTextSharp.text.pdf.codec.TiffImage.GetTiffImage(RandomAccessFileOrArray s,Int32 页面,布尔直接)在 iTextSharp.text.pdf.codec.TiffImage.GetTiffImage(RandomAccessFileOrArray s,Int32 页面)在 iTextSharp.text.Image.GetInstance(Uri url) 在 iTextSharp.text.Image.GetInstance(字符串文件名)

有人可以帮我解决这个问题吗?新版本修复了吗?

查看代码 here 后,他们似乎检查了 TIFF 中存在的 Tiles。

是否有任何 pdf 创建者通过 TIFF with Tiles for C# 阅读?

【问题讨论】:

  • 你是在循环运行上面的代码吗?
  • @Sudhakar,不,它不在循环中。只打开一个文档
  • 你编辑的和我建议的一样。干得好我的朋友。你是一个很好的学习者。
  • 几个思路:尝试转换tiff或者通过System.Drawing.Image使用GetInstance(System.Drawing.Image image,

标签: c# asp.net pdf itextsharp tiff


【解决方案1】:

Docotic.Pdf library 也可以从平铺的 TIFF 和其他流行格式创建 PDF。

这里是一个示例代码,它从图像(平铺的 TIFF 或不平铺的 TIFF)创建 PDF。图像被缩放以适应页面。

public static void createPdfFromImage(string imageFile, string output)
{
    using (PdfDocument doc = new PdfDocument())
    {
        PdfImage img = doc.AddImage(imageFile);

        PdfPage page = doc.Pages[0];
        double widthRatio = (double)page.Width / (double)img.Width;
        double heightRatio = (double)page.Height / (double)img.Height;
        double ratio = Math.Min(Math.Min(widthRatio, heightRatio), 1);

        page.Canvas.DrawImage(img, 0, 0,
            (float)(img.Width * ratio), (float)(img.Height * ratio), 0f);

        doc.Save(output);
    }
}

免责声明:我为图书馆的供应商工作。

【讨论】:

  • 它是开源的并且免费供开发/商业使用吗?
  • @Billa 它既不是免费的也不是开源的。
猜你喜欢
  • 1970-01-01
  • 2018-02-14
  • 2016-03-28
  • 2022-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多