繁体   English   中英

用C#打印PDF

[英]Printing a PDF in C#

我正在制作一个用于打印PDF的C#Windows应用程序。

当我打开应用程序时,它只打开Acrobat Reader窗口而不再打印。 在Print()的功能中有什么我错过的吗?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.Win32;


namespace PrintDocumentsApplication
   {
public partial class PrintForm : Form
{
    public PrintForm()
    {
        InitializeComponent();
    }

    private void printPdfButton_Click(object sender, EventArgs e)
    {
        String File = @"C:\Documents and Settings\larasasasrylo\Desktop\QRCODE_DEMO\test.pdf";
        String Printer = "\\vhssadasdasoftaweafs\\HP Color LaserJet 5550 PCL 6";
            Print(File, Printer);
    }

    public static bool Print(string file, string printer)
    {
        try
        {

            Process.Start(
               Registry.LocalMachine.OpenSubKey(
                    @"SOFTWARE\Microsoft\Windows\CurrentVersion" +
                    @"\App Paths\AcroRd32.exe").GetValue("").ToString(),
               string.Format("/h /t \"{0}\" \"{1}\"", file, printer));

            return true;

        }
        catch { }
        return false;

    }
}

}

你试试这个

Process process = new Process();

process.StartInfo.FileName = pathToPdfOrDocFile; 
process.UseShellExecute = true;
process.StartInfo.Verb = "printto";
process.StartInfo.Arguments = "\"" + printerName + "\""; 
process.Start();

process.WaitForInputIdle();
process.Kill();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM