Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 阅读PDF c中的所有页面#_C#_Pdfium - Fatal编程技术网

C# 阅读PDF c中的所有页面#

C# 阅读PDF c中的所有页面#,c#,pdfium,C#,Pdfium,我想阅读PDF的所有页面并将其保存为图像,到目前为止,我所做的只是先定义页面0=1等。。我是否有可能定义一个范围 static void Main(string[] args) { try { string path = @"C:\Users\test\Desktop\pdfToWord\"; foreach (string file in Directory.EnumerateFiles(path, "*.pdf")) { using (var

我想阅读PDF的所有页面并将其保存为图像,到目前为止,我所做的只是先定义页面
0=1
等。。我是否有可能定义一个范围

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;
    }

如果您的文档对象提供了pagecount

你可以代替

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

for(int index=0;index
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);
}