在打印PDF时如何设置打印机设置 [英] How to set Printer Settings while printing PDF
问题描述
我正在尝试使用Process对象打印PDF文件.在某种程度上,我可以成功打印它.但是,现在我想设置打印机属性..例如无份数,纸张尺寸等.但是我看不到任何属性可以设置这些值. 我正在使用以下代码来打印PDF
I'm trying to print a PDF file using Process object. And up to certain extent I could print it successfully. But now I want to set printer properties.. like no of copies, Paper size etc. But I don't see any property to set these values. I'm using following code to print PDFs
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);
}
}
推荐答案
我编写了一个可批量打印PDF文件的应用程序.
I have written an application that does batch printing of PDF files.
无法指定要使用的打印机设置.如果您将COM界面与Adobe Standard/Pro版本一起使用,则什至不可能.
It's not possible to specify the printer settings that you want to use. It's not even possible if you use the COM interface with the Adobe Standard/Pro versions.
您可以选择以下两种方式之一:
Your options are to either:
- 向第三方PDF渲染器购买许可证,您可以将其用于将PDF转换为位图并使用PrintDocument来控制PrinterSettings
- 使用GhostScript之类的工具将PDF文件转换为BMP文件,然后使用PrintDocument类打印BMP文件.然后,您可以控制PrinterSettings.
这篇关于在打印PDF时如何设置打印机设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!