Search code examples
.netvb.netpdfprintingxps

VB.NET PrintDialog Print to file


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.


Solution

  • 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();
        }