PDFiumCore就是这样一个库,它是Google的PDFium库的C#绑定。PDFium是一个开源的PDF渲染引擎,最初由Foxit Software提供,并被Google采用在其Chrome浏览器中以提供PDF查看功能。PDFiumCore使得C#开发人员可以在他们的应用程序中轻松地实现PDF相关的功能。
PDFiumCore通常具有以下特点:
nuget 安装PDFiumCore
C#public partial class Form1 : Form
{
FpdfDocumentT document;
int curPage = 0;
public Form1()
{
InitializeComponent();
}
private void btnLoadPdf_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "PDF|*.pdf";
if (openFile.ShowDialog() == DialogResult.OK)
{
fpdfview.FPDF_InitLibrary();
// 打开PDF文档
document = fpdfview.FPDF_LoadDocument(openFile.FileName, null);
lblCount.Text = fpdfview.FPDF_GetPageCount(document).ToString();
LoadPdf();
}
}
private void LoadPdf()
{
var page = fpdfview.FPDF_LoadPage(document, curPage);
var width = (int)fpdfview.FPDF_GetPageWidth(page);
var height = (int)fpdfview.FPDF_GetPageHeight(page);
var bitmap = fpdfview.FPDFBitmapCreate(width, height, 0);
fpdfview.FPDFBitmapFillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF);
fpdfview.FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0);
var stride = fpdfview.FPDFBitmapGetStride(bitmap);
var scan0 = fpdfview.FPDFBitmapGetBuffer(bitmap);
var image = new Bitmap(width, height, stride, PixelFormat.Format32bppArgb, scan0);
picPdf.Image = image;
}
private void btnPre_Click(object sender, EventArgs e)
{
if (curPage > 0)
{
curPage--;
LoadPdf();
}
}
private void btnNext_Click(object sender, EventArgs e)
{
if (curPage < int.Parse(lblCount.Text))
{
curPage++;
LoadPdf();
}
}
}
安装PdfiumViewer.Native.x86_64.v8-xfa与PdfiumViewer.Updated
C#private void Form1_Load(object sender, EventArgs e)
{
DisplayPdf();
}
public void DisplayPdf()
{
PdfViewer pdfViewer = new PdfViewer();
this.Controls.Add(pdfViewer);
pdfViewer.Document = PdfDocument.Load(@"D:\book\系统之美.pdf");
pdfViewer.Dock=DockStyle.Fill;
}
本文作者:技术老小子
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!