簡體   English   中英

閱讀PDF c#中的所有頁面

[英]Read all pages from PDF c#

我想閱讀我的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;
    }

如果您的document-object為您提供了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 < 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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM