PDF组件Spire.PDF 教程:在C#中显示PDF文件的打印预览

本文演示如何使用Spire.PDF和c#在Windows窗体应用程序中显示PDF文件的打印预览。this

在使用下面的代码以前,咱们须要建立一个Windows窗体应用程序,在窗体中添加一个PrintPreviewControl控件,并将Spire.Pdf.dll引用到应用程序中。spa

using System;
using System.Windows.Forms;
using Spire.Pdf;

namespace PreviewPDF
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
               
        private void printPreviewControl1_Click(object sender, EventArgs e)
        {
            //Load PDF file
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("New Zealand.pdf");

            //Set the PrintPreviewControl.Rows and PrintPreviewControl.Columns properties to show multiple pages
            this.printPreviewControl1.Rows = 2;
            this.printPreviewControl1.Columns = 2;

            //Preview the pdf file
            pdf.Preview(this.printPreviewControl1);  
        }             
    }
}

截图:orm

图片1

相关文章
相关标签/搜索