如何在打印PDF时设置打印机设置

use*_*613 6 c# printing pdf properties

我正在尝试使用Process对象打印PDF文件.在某种程度上,我可以成功打印它.但现在我想设置打印机属性..比如没有副本,纸张大小等.但我没有看到任何属性来设置这些值.我正在使用以下代码来打印PDF

string fileName = "";
string arguments = "";
string verbToUse = "";
int i = 0;
ProcessStartInfo startInfo = new ProcessStartInfo();
OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
    if ((fileName = openFileDialog1.FileName) != null)
    {
        startInfo = new ProcessStartInfo(fileName);

        if (File.Exists(fileName))
        {
            i = 0;
            foreach (String verb in startInfo.Verbs)
            {
                // Display the possible verbs.
                MessageBox.Show(i.ToString() + ". " + verb);
                i++;
            }
        }
    }

    //Console.WriteLine("Select the index of the verb.");
    string index = "2";
    if (Convert.ToInt32(index) < i)
        verbToUse = startInfo.Verbs[Convert.ToInt32(index)];
    else
        return;

    startInfo.Verb = verbToUse;
    if (verbToUse.ToLower().IndexOf("printto") >= 0)
    {
        //Printer Name
        arguments = @"\\hydfsvt02\HPLaserJ";
        startInfo.Arguments = arguments;
    }

    Process newProcess = new Process();
    newProcess.StartInfo = startInfo;

    try
    {
        newProcess.Start();

        MessageBox.Show(newProcess.ProcessName + " for file " + fileName + " started successfully with verb " + startInfo.Verb);
    }
    catch (System.ComponentModel.Win32Exception ex)
    {
        MessageBox.Show(" Win32Exception caught!");
        MessageBox.Show(" Win32 error = " + ex.Message);
    }
    catch (System.InvalidOperationException)
    {
        MessageBox.Show("File " + fileName + " started with verb " + verbToUse);
    }
}
Run Code Online (Sandbox Code Playgroud)

Chr*_*son 1

我编写了一个可以批量打印 PDF 文件的应用程序。

无法指定您想要使用的打印机设置。如果您在 Adob​​e Standard/Pro 版本中使用 COM 接口,这甚至是不可能的。

您的选择是:

  1. 购买第三方 PDF 渲染器的许可证,您可以使用该许可证将 PDF 转换为位图,并使用 PrintDocument 控制 PrinterSettings
  2. 使用 GhostScript 之类的工具将 PDF 文件转换为 BMP 文件,然后使用 PrintDocument 类打印 BMP 文件。然后您可以控制打印机设置。