specifying number of pages to print in C#
how can I specify printer and the number of pages to print,here is my code which prints all pages in pdf file,also it always uses default printer.
private void printPDFFile(string fileName)
{
PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
Process proc = new Process();
pd.PrinterSettings.FromPage = 1;
pd.PrinterSettings.ToPage = 2;
pd.PrinterSettings.PrintRange = PrintRange.SomePages;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //Hide the window.
proc.StartInfo.FileName = @"C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe";
proc.StartInfo.Arguments = "-p \""+ fileName+ "\" \"" +pd.PrinterSettings.PrinterName+"\"";
开发者_高级运维 proc.StartInfo.CreateNoWindow = true;//!! Don't create a Window.
proc.Start();
proc.CloseMainWindow();
}
}
The printing is not done in C#, but from Foxit Reader.
Look at its manual (pdf) for the options that control what you need. Use -t <Printer>
to print to a specific printer. It seems you can't print a specific page though, try to combine -t
with -n
.
精彩评论