PDF Printing not using Default Printer Preferences

Hello all,

I am trying out the evaluation version to see if it will suit the needsa of my company. So far it is working nicly to print off the PDSs from a file directory. However, it does not appear to be utilizing the default printers printing preferences which I set in the "Devices and Printers" section.

In my preferences, I set the default paper source to be Tray 2, and an input option to always print the first page of a document from Tray 1. Additionally, I increased the Quality setting to a 1200dpi resolution and maxed the darness value.

When I print the PDFs from my .NET application, they always print every page from Tray 1 and from what I can tell, the dpi resolution is not printing at 1200 dpi either.

Is Aspose capable of utilizing the saved printer preferences on the default printer? If so, how do I get it to do this? If not, can this please be added?

Here is the code I use for those interested:

DirectoryInfo tempDir = new DirectoryInfo(System.Configuration.ConfigurationManager.AppSettings.Get("ExportPath"));

foreach (FileInfo file in tempDir.GetFiles("*.pdf"))

{

PdfViewer viewer = new PdfViewer();

viewer.OpenPdfFile(tempDir + file.Name);

//set attributes for printing

viewer.AutoResize = false; //print the file with adjusted size

viewer.AutoRotate = false; //print the file with adjusted rotation

viewer.PrintPageDialog = false; //do not produce the page number dialog when printing

//create objects for printer and page settings and PrintDocument

System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();

System.Drawing.Printing.PrintDocument prtdoc = new System.Drawing.Printing.PrintDocument();

ps.PrinterName = prtdoc.PrinterSettings.PrinterName;

viewer.PrintDocumentWithSettings(ps);

viewer.Close();

}

Hello,

I see there have been many posts since this one that have been replied to by Aspose. Could I please have some help?

-Shawn

Hi Shawn,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the details and sorry for a delay in reply.

Aspose.Pdf for .NET applies the default printer settings / preferences if no settings are specified in the code. I checked your issue and I verified that Aspose.Pdf for .NET applies the default printer settings. I assigned the default tray as Tray 2 in my printer preferences and it works fine. However, I did not find the setting on my printer as “an input option to always print the first page of a document from Tray 1”. I think that might be causing the issue at your end. Could you please share the details regarding how are you setting this option? It might help me setup and test the issue further. I will further check the details of my printer and see if this option is support. I will update you regarding the progress.

Sorry for the inconvenience,

That option is part of the Printer Preferences on my Lexmark Printer and its supplied driver. I'm not certain what kind of printer and driver you have at your site.

When I enter my printer preferences, I have many tabs to choose from, one says "Paper/Finishing" where I set my multiple input options for different trays based on criteria(page 1 for example). Then the "Quality" tab is where I can set the dpi of the print job. I save all of these settings as part of my default print settings. Neither of these settings are being picked up by the Aspose software and I cannot seem to find ways to code it using the objects provided.

Can these features be programmed using the aspose objects by any chance?

If you provide me an email address I can also send screenshots of the settings.

Also, because I have had good luck getting Aspose to work on my .NET solution, I am looking for a way to code my resolution and multi pagesource needs into the solution as well. I have found some code to set a print resolution but am having troubles finding a way to set a pagesource for each page of the document.

I see that we can call PrintDocumentWithSettings and pass both a PrinterSettings and PageSettings object as parameters. How can I setup these parameters to use "Tray 1" on the first page and "Tray 2" on all other pages? It looks like it may be possible.

I think the following will work to set the resolution I need.

System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();

System.Drawing.Printing.PrintDocument prtdoc = new System.Drawing.Printing.PrintDocument();

System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();

foreach (System.Drawing.Printing.PrinterResolution res in ps.PrinterResolutions)

{

if (res.Kind.ToString() == "High")

ps.DefaultPageSettings.PrinterResolution = res;

}

viewer.PrintDocumentWithSettings(pgs, ps);

Hi Shawn,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the feedback.

Regarding your requirement of printing a document on multiple trays, you can use PageSettings class to set PaperSource (the paper tray). You can also set FromPage and ToPage properties to set the starting and ending page to be printed in this particular paper source.

Now, as you want to print different pages to different paper sources, you'll have to perform the print job separately for each set of pages with particular paper source and from page and to page settings separately. For example, first send page range 1 - 1 to printer tray one and then page range 2 – last page to printer tray two.

Also,
to achieve the above scenario with a single print call, we already have a
feature request in our issue tracking system with issue id:
PDFNEWNET-34180. However, we don’t have
a confirmed plan for its implementation yet. I have associated this thread with
that issue and you will be notified regarding any updates against this feature.
</o:p>

Please
do let us know if this fulfills your requirement.<o:p></o:p>

Thank You & Best Regards,

Hello, thanks for the response. Your recommendation is exactly what I ended up coding yesterday. :) As you mentioned, combining it into a single print job would be nice but isn't a show stopper for me.

Thanks again for the support!

Hi Shawn,

Thank you for the feedback.

I am pleased to know that you were able to implement the solution as per your requirement. Regarding the single call printing as per your scenario, I have already linked the issue in our issue tracker with this forum thread and as soon as there is any update, you will be notified via this thread.

Thank You & Best Regards,

@sp213

To pass different paper size settings for different pages, please use the PdfViewer.PdfQueryPageSettings event:

public static void Print(string inputFile, string printerName, int duplexMode, int firstTray, int followerTray)
{
    _firstTray = firstTray;
    _followerTray = followerTray;

    PdfViewer viewer = new PdfViewer();
    Aspose.Pdf.Printing.PrinterSettings settings = new Aspose.Pdf.Printing.PrinterSettings();
    Aspose.Pdf.Printing.PageSettings pageSettings = new Aspose.Pdf.Printing.PageSettings();
    PrintDocument doc = new PrintDocument();

    viewer.OpenPdfFile(inputFile);

    settings.PrinterName = doc.PrinterSettings.PrinterName;

    if (ConverterConfig.Instance != null)
        viewer.Resolution = ConverterConfig.Instance.PdfSettings.PdfPrintResolution;

    PrintSettings = settings;

    if (!printerName.IsNullOrEmpty())
        settings.PrinterName = printerName;

    if ((duplexMode == 1 || duplexMode == 2 || duplexMode == 3) && doc.PrinterSettings.CanDuplex)
        settings.Duplex = duplexMode == 1 
            ? Aspose.Pdf.Printing.Duplex.Simplex
            : duplexMode == 2
                ? Aspose.Pdf.Printing.Duplex.Vertical
                : Aspose.Pdf.Printing.Duplex.Horizontal;

    currentPageNumber = 1;
    // Subscribe to the PdfQueryPageSettings event to pass customized settings for each page
    viewer.PdfQueryPageSettings += new PdfQueryPageSettingsEventHandler(doc_QueryPageSettings);

    viewer.PrintDocumentWithSettings(pageSettings, settings);

}

static void doc_QueryPageSettings(object sender, PdfQueryPageSettingsEventArgs e, PdfPrintPageInfo info)
{
    currentPageNumber++;
    foreach (System.Drawing.Printing.PaperSource source in PrintSettings.PaperSources)
    {
        if (source.RawKind == _firstTray)
        {
            e.PageSettings.PaperSource = source.ToAsposePaperSource();
        }
    }

    if (currentPageNumber > 1)
    {
        foreach (System.Drawing.Printing.PaperSource source in PrintSettings.PaperSources)
        {
            if (source.RawKind == _followerTray)
            {
                e.PageSettings.PaperSource = source.ToAsposePaperSource();
            }
        }
    }
}