Bad performance convert tif to pdf using ITextSharp

后端 未结 7 1320
猫巷女王i
猫巷女王i 2021-02-15 17:03

Summary: How can I reduce the amount of time it takes to convert tifs to pdfs using itextsharp?

Background: I\'m convertin

7条回答
  •  悲&欢浪女
    2021-02-15 17:21

    The trouble is with the length of time it takes for iTextSharp to finishing messing around with your System.Drawing.Image object.

    To speed this up to literally a 10th of a second in some tests I have run you need to save the selected frame out to a memory stream and then pass the byte array of data directly to the GetInstance method in iTextSharp, see below...

    bm.SelectActiveFrame(FrameDimension.Page, k);
    
    iTextSharp.text.Image img;
    using(System.IO.MemoryStream mem = new System.IO.MemoryStream())
    {
        // This jumps all the inbuilt processing iTextSharp will perform
        // This will create a larger pdf though
        bm.Save(mem, System.Drawing.Imaging.ImageFormat.Png);
        img = iTextSharp.text.Image.GetInstance(mem.ToArray());
    }
    
    img.ScalePercent(72f / 200f * 100);
    

提交回复
热议问题