简体   繁体   English

将pdf页面转换为1000张以上的图像

[英]Convert pdf pages to images more than 1000

I could convert the pdf pages into images. 我可以将pdf页面转换为图像。 if it is less than 50 pages its working fast... if any pdf large than 1000 pages... it acquires lot of time to complete. 如果少于50页,则其工作速度很快。如果任何pdf大于1000页,则需要花费大量时间才能完成。 any one can review this code and make it work for large file size... i have used PdfLibNet dll(will not work in 4.0) in .NET3.5 here is my sample code: 任何人都可以查看此代码,并使其适合较大的文件大小...我在.NET3.5中使用了PdfLibNet dll(在4.0中不起作用),这是我的示例代码:

public void ConverIMG(string filename)
    {          
        PDFWrapper wrapper = new PDFWrapper();
        wrapper.RenderDPI = Dpi;
        wrapper.LoadPDF(filename);
        int count = wrapper.PageCount;
        for (int i = 1; i <= wrapper.PageCount; i++)
        {
            string fileName = AppDomain.CurrentDomain.BaseDirectory + @"IMG\" + i.ToString() + ".png";
            wrapper.ExportJpg(fileName, i, i, (double)100, 100);
            while (wrapper.IsJpgBusy)
            {
                Thread.Sleep(50);
            }
        }
        wrapper.Dispose();            
    }

PS: we need to split pages and convert to images parallely and we need to get completed status. PS:我们需要拆分页面并并行转换为图像,并且需要获得完整的状态。 页数和时间消耗

If PDFWrapper performance degrades for documents bigger then 50 pages it suggests it is not very well written. 如果对于大于50页的文档, PDFWrapper性能PDFWrapper ,则表明它的书写方式不是很好。 To overcome this you could do conversion in 50 page batches and recreate PDFWrapper after each batch. 为了克服这个问题,您可以分50页进行批量转换,并在PDFWrapper之后重新创建PDFWrapper There is an assumption that ExportJpg() gets slower with number of calls and its initial speed does not depend on the size of PDF. 假设ExportJpg()随着调用次数的增加而变慢,并且其初始速度不取决于PDF的大小。

This is only a workaround for apparent problems in PDFWrapper and a proper solution would be to use a fixed library. 这只是解决PDFWrapper明显问题的一种解决方法,正确的解决方案是使用固定库。 Also I would suggest Thread.Sleep(1) if you really need to wait with yielding. 如果您真的需要等待Thread.Sleep(1)我也建议Thread.Sleep(1)

public void ConverIMG(string filename)
{
    PDFWrapper wrapper = new PDFWrapper();
    wrapper.RenderDPI = Dpi;
    wrapper.LoadPDF(filename);
    int count = wrapper.PageCount;
    for (int i = 1; i <= count; i++)
    {
        string fileName = AppDomain.CurrentDomain.BaseDirectory + @"IMG\" + i.ToString() + ".png";
        wrapper.ExportJpg(fileName, i, i, (double) 100, 100);
        while (wrapper.IsJpgBusy)
        {
            Thread.Sleep(1);
        }

        if (i % 50 == 0)
        {
            wrapper.Dispose();
            wrapper = new PDFWrapper();
            wrapper.RenderDPI = Dpi;
            wrapper.LoadPDF(filename);
        }
    }
    wrapper.Dispose();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM