Printing PDFs with changed default printer settings

喜欢而已 提交于 2019-12-18 08:54:30

问题


Google/Bing didnt bring up any solution to my following problem, hope someone can help me:

We have to print various PDF files in our C# based program. Before we can print, we have to configure the printer, e.g. setting the orientation to landscape.

I tried to change the default printer settings e.g. like this:

PrinterSettings settings = new PrinterSettings();
settings.PrinterName = "\\\\SomeNetworkPrinter\\";
settings.DefaultPageSettings.Landscape = true;
settings.Duplex = Duplex.Horizontal;

We send the PDF to the printer via PDFSharp, which basically works, but my settings are completly ignored. Isn't it possible to change the default printer settings this way? Do we have any chance to change the settings and print our PDF-files?

Thank you very much in advance!


回答1:


No, I don't think that's going to work.

You're creating a local PrinterSettings object which can be used to configure a PrintDocument which in turn can be sent to the printer using PrintDocument.Print().

If you're calling out to PDFSharp to orchestrate the printing, it's going to use whatever printer settings it defaults to, unless you're somehow passing your PrinterSettings to PDFSharp via the API?

If you can post the code you use to invoke PDFSharp, it would be of help in figuring out how to do this.




回答2:


To answer my own question ...

After 3 days of trial and error I dont think there is any chance to configure the printer via .NET and print PDFs afterwards. You cant use the System.Drawing.Printing.PrintDocument class in combination with PDFs, but using PrintDocument seems to be a prerequisit to change the printer settings.

My solution to configure the printer was inspired by this post on codeplex: http://www.codeproject.com/KB/dotnet/NET_Printer_Library.aspx

To finally print the pdf I send it via commandline parameters to Adobe Reader.



来源:https://stackoverflow.com/questions/6900744/printing-pdfs-with-changed-default-printer-settings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!