Printing to a Network Printer Does Not Work.

210 views
Skip to first unread message

Vincent Ycasas

unread,
May 8, 2013, 1:26:09 PM5/8/13
to pdfne...@googlegroups.com
Question:
When I try to print with a local printer, I was able to print PDF documents using the following code:
PrintDialog pDlg = new PrintDialog();
pDlg.UserPageRangeEnabled = true;
Nullable<Boolean> result = pDlg.ShowDialog();
if (result == true)
{
    PrintQueue pq = pDlg.PrintQueue;
    PrintTicket pt = pDlg.PrintTicket;
    PageSet ps = new PageSet(pDlg.PageRange.PageFrom, pDlg.PageRange.PageTo);
    if (pDlg.PageRangeSelection == PageRangeSelection.AllPages)
        ps = new PageSet(1, view.GetPageCount());
    PrinterMode pm = new PrinterMode();
    pm.SetCopyCount(pt.CopyCount.HasValue ? pt.CopyCount.Value : 1);
    if (view.GetRotation() == pdftron.PDF.Page.Rotate.e_90 || view.GetRotation() == pdftron.PDF.Page.Rotate.e_270)
        pm.SetOrientation(PrinterMode.Orientation.e_Orientation_Landscape);
    else
        pm.SetOrientation(PrinterMode.Orientation.e_Orientation_Portrait);
    view.GetPDFDoc().Lock();
    try
    {
        Print.StartPrintJob(view.GetPDFDoc(), pq.Name, view.GetPDFDoc().GetFileName(), "", ps, pm);
    }
    catch
    {
        MessageBox.Show("Print Failed");
    }
    view.GetPDFDoc().Unlock();
}

But if I try to select a network printer, the printing process failed with the following error message:
 Message: Could not start XPS print job
    Conditional expression: SUCCEEDED(hr)
    Filename   : PDFPrintDocSpoolerWin.cpp
    Function   : trn::PDF::Print::PDFPrintDocSpoolerWin::StartXpsPrintJob

Vincent Ycasas

unread,
May 8, 2013, 1:28:43 PM5/8/13
to pdfne...@googlegroups.com
Answer:
The problem lies on how the PrintDialog's PrintQueue property obtains the network name. If the printer is a network printer, you may have to use the FullName property of PrintQueue instead of just the name. To do this, change the following line:

Print.StartPrintJob(view.GetPDFDoc(), pq.Name, view.GetPDFDoc().GetFileName(), "", ps, pm);
to:
Print.StartPrintJob(view.GetPDFDoc(), pq.FullName, view.GetPDFDoc().GetFileName(), "", ps, pm);

This should let you print to the network printer.
Reply all
Reply to author
Forward
0 new messages