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

相關文章
相關標籤/搜索