windows form 列印 pdf 程式

 

一個 windows form 列印 pdf 程式範例如下

Form1.cs

using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public static void printPDFWithAcrobat()
        {
            string Filepath = @"D:\123.pdf";

            using (PrintDialog Dialog = new PrintDialog())
            {
                Dialog.ShowDialog();

                ProcessStartInfo printProcessInfo = new ProcessStartInfo()
                {
                    Verb = "print",
                    CreateNoWindow = true,
                    FileName = Filepath,
                    WindowStyle = ProcessWindowStyle.Hidden
                };

                Process printProcess = new Process();
                printProcess.StartInfo = printProcessInfo;
                printProcess.Start();

                printProcess.WaitForInputIdle();

                Thread.Sleep(3000);

                if (false == printProcess.CloseMainWindow())
                {
                    printProcess.Kill();
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            printPDFWithAcrobat();
        }

    }
}

 

參考資料:

How to print a PDF from your Winforms application in C#

CODE-使用 C# 批次列印 PDF 檔案