做网站的主题,济南网站,滕州本地网站建设,定制开发电商网站建设1.NuGet 安装 O2S.Components.PDFView4NET.WPF 2.添加组件
工具箱中#xff0c;空白处 右键#xff0c;选择项 WPF组件 界面#xff0c;选择NuGet安装库对面路径下的 O2S.Components.PDFView4NET.WPF.dll 3.引入组件命名空间#xff0c;并使用
Windowxmlnshtt…1.NuGet 安装 O2S.Components.PDFView4NET.WPF 2.添加组件
工具箱中空白处 右键选择项 WPF组件 界面选择NuGet安装库对面路径下的 O2S.Components.PDFView4NET.WPF.dll 3.引入组件命名空间并使用
Windowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:PDFViewxmlns:PageViewWPFclr-namespace:O2S.Components.PDFView4NET.WPF;assemblyO2S.Components.PDFView4NET.WPFx:ClassPDFView.MainWindowmc:IgnorabledTitleMainWindow Height450 Width800 LoadedWindow_LoadedGridGrid.ColumnDefinitionsColumnDefinition//Grid.ColumnDefinitionsPageViewWPF:PDFPageView x:NamePdfControl HorizontalAlignmentLeft Heightauto VerticalAlignmentTop Widthauto PageDisplayLayoutCustom WorkModePanAndScan HighlightFormFieldsTrue//Grid
/Windowusing O2S.Components.PDFView4NET;
using System.Windows;namespace PDFView
{/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{public MainWindow(){InitializeComponent();}private void Window_Loaded(object sender, RoutedEventArgs e){PdfControl.Document new PDFDocument() { FilePath .\\4.pdf };}}
}4.PDF转换成图片
听说有破解版无水印找到了两个版本两个不同O2S.Components.PDFRender4NET破解版
百度网盘地址链接https://pan.baidu.com/s/1onJG6pkmXAR-pT1ZzeIy4A 提取码dlfe 版本2.0.1.0 对于我的测试PDF使用正常
版本4.5.1.2 对于我的测试PDF使用异常
PdfToImage(.\\4.pdf, Environment.CurrentDirectory, 4, ImageFormat.Png, Definition.Eight);
/// summary/// PDF文档所有页全部转换为图片/// /summary/// param namepdfInputPathPDF文件流/param/// param nameimageOutputPath图片输出路径/param/// param nameimageName生成图片的名字/param/// param nameimageFormat设置所需图片格式/param/// param namedefinition设置图片的清晰度数字越大越清晰/parampublic static void PdfToImage(string pdfStream, string imageOutputPath, string imageName, ImageFormat imageFormat, Definition definition){PDFFile pdfFile PDFFile.Open(pdfStream);int startPageNum 1;int endPageNum pdfFile.PageCount;for (int i startPageNum; i endPageNum; i){try{Bitmap pageImage pdfFile.GetPageImage(i - 1, 56 * (int)definition);int canKao pageImage.Width pageImage.Height ? pageImage.Height : pageImage.Width;int newHeight canKao 1080 ? pageImage.Height / 2 : pageImage.Height;int newWidth canKao 1080 ? pageImage.Width / 2 : pageImage.Width;Bitmap newPageImage new Bitmap(newWidth, newHeight);Graphics g Graphics.FromImage(newPageImage);g.InterpolationMode System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;g.DrawImage(pageImage, new Rectangle(0, 0, newWidth, newHeight),new Rectangle(0, 0, pageImage.Width, pageImage.Height), GraphicsUnit.Pixel);newPageImage.Save(imageOutputPath imageName (endPageNum 2 ? (- i) : ) . imageFormat);// i.ToString() imageFormatg.Dispose();newPageImage.Dispose();pageImage.Dispose();}catch (Exception ex){string ss ex.ToString();}}pdfFile.Dispose();}/// summary/// 转换的图片清晰度1最不清醒10最清晰/// /summarypublic enum Definition{One 1, Two 2, Three 3, Four 4, Five 5, Six 6, Seven 7, Eight 8, Nine 9, Ten 10}
5.附上官方代码库链接
PDFView4NET https://github.com/o2solutions/pdfview4net/tree/main