none
PrintDialog with Microsoft Print to PDF RRS feed

  • Question

  • Hi all,

    I would like to know if there's a way to send a *.xps to "Microsoft Print to PDF" printer, without opening the save file dialog of the result .pdf file name.

    I have the following code:

    PrintDialog pDialog = new PrintDialog(); pDialog.PrintQueue = new PrintQueue(new PrintServer(), "Microsoft Print to PDF"); PrintServer printServer = new PrintServer(); pDialog.PageRangeSelection = PageRangeSelection.AllPages; pDialog.UserPageRangeEnabled = true; XpsDocument xpsDocument = new XpsDocument(@"C:\test.xps", FileAccess.Read); FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();

    pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "test.xps");


    Best Regards


    Wednesday, May 11, 2016 10:36 AM

Answers

  • Hi Miguel,

    Since Pdf is a third-party product, there is no method or class to help you implement this in .Net framework. Here I searched on the line, you can print PDF to XPS without a dialog using Aspose API Aspose API

    //Create PdfViewer object and bind PDF file
    PdfViewer pdfViewer = new PdfViewer();
    pdfViewer.OpenPdfFile("input.pdf");
    
    //Set PrinterSettings and PageSettings
    System.Drawing.Printing.PrinterSettings printerSetttings = new System.Drawing.Printing.PrinterSettings();
    printerSetttings.Copies = 1;
    printerSetttings.PrinterName = "Microsoft XPS Document Writer";
    
    //Set output file name and PrintToFile attribute
    printerSetttings.PrintFileName = "C:\\tempfiles\\printoutput.xps";
    printerSetttings.PrintToFile = true;
    
    **//Disable print page dialog**
    **pdfViewer.PrintPageDialog = false;**
    
    //Pass printer settings object to the method
    pdfViewer.PrintDocumentWithSettings(printerSetttings);
    pdfViewer.ClosePdfFile();

    Please also try to replace with each other. Hope this helps!

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 12, 2016 3:11 AM

All replies

  • Hi Miguel,

    Since Pdf is a third-party product, there is no method or class to help you implement this in .Net framework. Here I searched on the line, you can print PDF to XPS without a dialog using Aspose API Aspose API

    //Create PdfViewer object and bind PDF file
    PdfViewer pdfViewer = new PdfViewer();
    pdfViewer.OpenPdfFile("input.pdf");
    
    //Set PrinterSettings and PageSettings
    System.Drawing.Printing.PrinterSettings printerSetttings = new System.Drawing.Printing.PrinterSettings();
    printerSetttings.Copies = 1;
    printerSetttings.PrinterName = "Microsoft XPS Document Writer";
    
    //Set output file name and PrintToFile attribute
    printerSetttings.PrintFileName = "C:\\tempfiles\\printoutput.xps";
    printerSetttings.PrintToFile = true;
    
    **//Disable print page dialog**
    **pdfViewer.PrintPageDialog = false;**
    
    //Pass printer settings object to the method
    pdfViewer.PrintDocumentWithSettings(printerSetttings);
    pdfViewer.ClosePdfFile();

    Please also try to replace with each other. Hope this helps!

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 12, 2016 3:11 AM
  • This is a solution based on Spire.PDF, for more details plz check here.

    PdfDocument doc = new PdfDocument();
    doc.LoadFromFile(@"example.pdf");
    
    //specify the printer name
    doc.PrintDocument.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
    //print file to XPS
    doc.PrintDocument.PrinterSettings.PrintToFile = true;
    doc.PrintDocument.PrinterSettings.PrintFileName = "PrintToXps.xps";
    
    doc.PrintDocument.Print();

    Friday, January 20, 2017 8:57 AM