word转图片使用的Aspose组件,Aspose.word.dll 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  public  bool  Word2Png( string  docFile,  string  pngDir,  out  int  pngCount)
         {
             ImageSaveOptions options =  new  ImageSaveOptions(SaveFormat.Png);
             options.Resolution = 300;
             options.PrettyFormat =  true ;
             options.UseAntiAliasing =  true ;
 
             pngCount = 0;
             try
             {
                 Aspose.Words.Document doc =  new  Aspose.Words.Document(docFile);
                 for  ( int  i = 0; i < doc.PageCount; i++)
                 {
                     options.PageIndex = i;
                     doc.Save(pngDir + i +  ".png" , options);
 
                     pngCount++;
                 }
                 return  true ;
             }
             catch
             {
                 return  false ;
             }
         }

PDF 转图片使用的是Aspose.pdf.dll 组件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  public  bool  PDF2PNG( string  srcPdfPath,  string  desPicPath)
         {
             try
             {
                 Aspose.Pdf.Document pdf =  new  Aspose.Pdf.Document(srcPdfPath);
                 for  ( int  pageCount = 1; pageCount <= pdf.Pages.Count; pageCount++)
                 {
                     using  (FileStream imageStream =  new  FileStream(desPicPath +  "\\"  + pageCount +  ".png" , FileMode.Create))
                     {
                         //create Resolution object
                         Aspose.Pdf.Devices.Resolution resolution =  new  Aspose.Pdf.Devices.Resolution(300);
                         Aspose.Pdf.Devices.PngDevice pngDevice =  new  Aspose.Pdf.Devices.PngDevice(resolution);
 
                         //convert a particular page and save the image to stream
                         pngDevice.Process(pdf.Pages[pageCount], imageStream);
                         //close stream
                         imageStream.Close();
                     }
                 }
                 return  true ;
             }
             catch  (Exception e)
             {
                 return  false ;
 
             }
         }

     本文转自Eumenides_s 51CTO博客,原文链接:http://blog.51cto.com/xiaoshuaigege/1889703,如需转载请自行联系原作者