Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Oct 21, 2022 3:36 am

I'm using Spire.Doc and have my service printing without a user interface. When I'm testing locally without access to a printer I would like to change the printer to "Microsoft Print to PDF".
If I do this it pops up a prompt for the output filename. I would really like to be able to specify the filename and have it print without a dialog appearing.

I have read about Word having a PrintOut method which has a parameter for specifying the output file. Is there anything like this available with Spire.Doc and the PrinterSettings or StandardPrintController?

Les43625
 
Posts: 12
Joined: Tue Feb 22, 2022 1:41 am

Fri Oct 21, 2022 9:53 am

Hello,

Thanks for your inquiry.
For your requirement, please refer to the following code.
If you have any issue, just feel free to contact us.
Code: Select all
//Load the document
            string input = @"..\..\data\input.pdf";
            Document doc = new Document();
            doc.LoadFromFile(input);
           
            PrintDocument printDoc = doc.PrintDocument;

            //Set the printer name
            printDoc.PrinterSettings.PrinterName = "Microsoft Print to PDF";

           
            //Add the property PrintController to hide the print processing dialog
            printDoc.PrintController = new StandardPrintController();

            //Specify the output file
            printDoc.PrinterSettings.PrintToFile = true;
            printDoc.PrinterSettings.PrintFileName = @"../../output/result.pdf";

            //Print the word document
            printDoc.Print();


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Mon Oct 31, 2022 7:14 am

Hello,

Greeting from E-iceblue.
Does the code I provided meet your requirement? Looking forward to your feedback. Have you a nice day!

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.Doc