VB.NET PrintDialog Print to file

别说谁变了你拦得住时间么 提交于 2019-12-11 13:28:16

问题


I am using .NET (VB) Graphics to print/preview reports in a pre-defined format (like tax forms), which works just fine.

I would also like to be able to have the ability to accumulate one or more different reports and save them to a file for later conversion to PDF or to use the XPS print driver to print them.

When I check the "print to file" box (for a regular laser printer or the XPS print driver), and click "Print", I do not get an Open File dialog as this article suggests I should ( http://www.functionx.com/vcnet/controls/print.htm ). The operation seems to proceed normally, but I have no idea where to find the file, if in fact one is created.

What am I missing? Can anyone offer an alternative method of accumulating Graphics reports and printing or printing to a file?

TIA for your time.


回答1:


Is the print dialog actually associated with the PrintDocument instance? Code like this works well:

    private void button1_Click(object sender, EventArgs e) {
        printDocument1.PrinterSettings.PrintToFile = true;
        printDocument1.PrinterSettings.PrintFileName = @"c:\temp\test.xps";
        printDocument1.Print();
    }



回答2:


Why not use a PDF Printer? On the net you will find numerous free solutions.
The one I like more is BullZip but there are other options. If you look for this kind of solution be aware of the dead ends (like adware toolbar or strange licensing terms).
However, this scenario has definite advantages, like you can define a folder as your document base and every time you print, you PDF printer remembers where to create a PDF document.



来源:https://stackoverflow.com/questions/9675494/vb-net-printdialog-print-to-file

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