2013-11-15 71 views

回答

1

尝试:

PdfDocument inputDocument = PdfReader.Open(fileNames[i], PdfDocumentOpenMode.Import); 

         // for each page create a new PDF file and save it on the disk 
         for (int pageCount = 0; pageCount < inputDocument.PageCount; pageCount++) 
         { 
    fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileNames[i]); 
           fileName = string.Format("{0}\\Documents\\{1}", Session.CentralWorkingDirectory, String.Format("{0} ({1}-{2}).pdf", fileNameWithoutExtension, pageCount + 1, inputDocument.PageCount)); 

    pdfFile = PDFFile.Open(fileName); 
       pdfFile.SerialNumber = Configurations.PDFVIEW_KEY; 

       // Get image file name 
       string imageFileName = string.Format("{0}.png", fileName.Remove(fileName.Length - 4)); 

       // If thumbnail already exists delete it 
       if (File.Exists(imageFileName)) 
       { 
        File.Delete(imageFileName); 
       } 

       // Convert page to PNG and save it. 
       //Bitmap pageImage = pdfFile.GetPageImage(0, 32); 


       Bitmap pageImage = pdfFile.GetPageImage(0, 92); 
       pageImage.Save(imageFileName, ImageFormat.Png); 

       // Cleanup resources 
       pageImage.Dispose(); 
       pdfFile.Dispose(); 


    } 

在这里,我用下面的命名空间...

using PdfSharp.Drawing; 
using O2S.Components.PDFRender4NET; // Thrid party components so you use PDF sharp with this componets 
using System.Drawing.Imaging; 
相关问题