2016-09-29 66 views
1

我想阅读我的PDF的所有网页,并将它们保存为图像,到目前为止,我所做的只是让我定义的网页0 = 1第一等。有没有机会,我可以定义一个范围?阅读所有从PDF页面#

static void Main(string[] args) 
{ 
    try 
    { 
     string path = @"C:\Users\test\Desktop\pdfToWord\"; 
     foreach (string file in Directory.EnumerateFiles(path, "*.pdf")) { 
     using (var document = PdfiumViewer.PdfDocument.Load(file)) 
     { 
     int i = 1; 
     var image = document.Render(0,300,300, true); 
     image.Save(@"C:\Users\test\Desktop\pdfToWord\output.png", ImageFormat.Png); 
      } 
     } 
    } 
    catch (Exception ex) 
    { 
     // handle exception here; 
    } 

回答

6

如果您的文档对象给你PAGECOUNT,

你可以通过

for(int index = 0; index < document.PageCount; index++) 
{ 
    var image = document.Render(index,300,300, true); 
    image.Save(@"C:\Users\test\Desktop\pdfToWord\output"+index.ToString("000")+".png", ImageFormat.Png); 
} 
更换

int i = 1; 
var image = document.Render(0,300,300, true); 
image.Save(@"C:\Users\test\Desktop\pdfToWord\output.png", ImageFormat.Png);