当前位置: 首页 > 编程语言 > C#

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

时间:2023-04-10 15:41:15 C#

打印PDF时如何设置打印机设置在某种程度上,我可以成功打印它。但是现在我想设置打印机属性..比如没有副本,纸张大小等。但是我没有看到任何属性来设置这些值。我正使用以下代码来打印PDFstringfileName="";字符串参数="";stringverbToUse="";诠释我=0;ProcessStartInfostartInfo=newProcessStartInfo();OpenFileDialogopenFileDialog1=newOpenFileDialog();openFileDialog1.InitialDirectory="c:\";openFileDialog1.Filter="pdf文件(*.pdf)|*.pdf|所有文件(*.*)|*.*";openFileDialog1.FilterIndex=2;openFileDialog1.RestoreDirectory=true;如果(openFileDialog1.ShowDialog()==DialogResult.OK){如果((fileName=openFileDialog1.FileName)!=null){startInfo=newProcessStartInfo(fileName);如果(File.Exists(fileName)){i=0;foreach(StringverbinstartInfo.Verbs){//显示可能的动词。MessageBox.Show(i.ToString()+"."+verb);我++;}}}//Console.WriteLine("选择动词的索引。");字符串索引="2";if(Convert.ToInt32(index)=0){//打印机名称参数=@"\hydfsvt02HPLaserJ";startInfo.Arguments=参数;}进程newProcess=newProcess();新进程.StartInfo=开始信息;尝试{newProcess.Start();MessageBox.Show(newProcess.ProcessName+"forfile"+fileName+"startedsuccessfullywithverb"+startInfo.Verb);}catch(System.ComponentModel.Win32Exceptionex){MessageBox.Show("Win32Exception被捕获!");MessageBox.Show("Win32错误="+ex.Message);}catch(System.InvalidOperationException){MessageBox.Show("文件"+文件名+"以动词"+verbToUse开头);}}privatevoidstartPrintingButton_Click(objectsender,EventArgse){OpenFileDialogofd=newOpenFileDialog();如果(DialogResult.OK==ofd.ShowDialog(this)){PrintDocumentpdoc=newPrintDocument();pdoc.DefaultPageSettings.PrinterSettings.PrinterName="ZDesignerGK420d";pdoc.DefaultPageSettings.Landscape=true;pdoc.DefaultPageSettings.PaperSize.Height=140;pdoc.DefaultPageSettings.PaperSize.Width=104;打印(pdoc.PrinterSettings.PrinterName,ofd.FileName);}}privatevoidPrint(stringprinterName,stringfileNa我){尝试{ProcessStartInfogsProcessInfo;进程gsProcess;gsProcessInfo=newProcessStartInfo();gsProcessInfo.Verb="PrintTo";gsProcessInfo.WindowStyle=ProcessWindowStyle.Hidden;""";gsProcess=Process.Start(gsProcessInfo);if(gsProcess.HasExited==false){gsProcess.Kill();}gsProcess.EnableRaisingEvents=true;gsProcess.Close();}catch(Exception){}}此代码将打印PDF文件以及调整打印设置可以选择:以上是C#学习教程:打印PDF时如何设置打印机设置,全部内容分享,如果对大家有用,需要详细了解C#学习教程,希望大家多多付出注意-购买第三方PDF渲染器您可以使用渲染器将PDF转换为位图并使用PrintDocument来控制PrinterSettings使用类似GhostScript的东西将PDF文件转换为BMP文件,然后使用PrintDocument类打印BMP文件,然后就可以控制PrinterSettings了,本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: