C#PDFを画像に共有するテクノロジー(PDFLibNet.dll)



C Technology Sharing Pdf Into Picture Pdflibnet



最近、長い間探しているインターネット上の画像へのPDFの問題に遭遇し、現在さまざまな方法をテストして、三者DLLを使用する場所を見つけ、PDF転送画像を実現できます。

PDFLibNet.dllは、透かしが入ったバージョンがない場合、32ビットシステムのみをサポートします。



public enum Definition { One = 1, Two = 2, Three = 3, Four = 4, Five = 5, Six = 6, Seven = 7, Eight = 8, Nine = 9, Ten = 10 }

これは列挙、定義画像の明快さです、おそらく他のブログで見られました、実際、数字が大きいほどより明確になります

public static bool ConvertPDF2Image(string pdfInputPath, string imageOutputPath, string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, Definition definition) { bool Img = true PDFWrapper pdfWrapper = new PDFWrapper() try { pdfWrapper.LoadPDF(pdfInputPath) if (!System.IO.Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath) } if (startPageNum pdfWrapper.PageCount) { endPageNum = pdfWrapper.PageCount } if (startPageNum > endPageNum) { int tempPageNum = startPageNum startPageNum = endPageNum endPageNum = startPageNum } // start to convert each page for (int i = startPageNum i <= endPageNum i++) { pdfWrapper.ExportJpg (imageOutputPath + imageName + '.jpg', i, i, 150, 90) // can set the output image where pages, size, and picture quality //if (pdfWrapper.IsJpgBusy) { System.Threading.Thread.Sleep(50) } System.Threading.Thread.Sleep(50) } } catch(Exception ex) { Img = false Console.WriteLine ( 'abnormal error') } finally { pdfWrapper.Dispose() } return Img }

これは、いくつかの判断、または少なくとも最初のページを実行し、最後に数ページで終了し、トラバースの下部で実行し、次に以下の適切なファイルパスに移動します。



public static bool Run(string FileName, string FileOrder) { string Path = 'D:\wwwroot\UploadData\' + FileOrder + '\' string pdfInputPath = Path + FileName + '.pdf' string imageOutputPath = Path return ConvertPDF2Image(pdfInputPath, imageOutputPath, FileName, 1, 1, ImageFormat.Jpeg, Definition.One) }

最後に、ここにメインメソッドの呼び出しがあります。PDFからローカルの公式ラインに写真を撮った後に登り、JPG形式に変換します。次に、ここから始めて、エンドシートが1つです。セットは1で、最初の2つのパラメーターはファイルパスであり、PDFからJPG形式の画像もパスに変換します。3番目のパラメーターはファイルの名前です。

これらがお役に立てば幸いです