Printing to a print queue with a document name

I want to print my Words document to a print queue by specifying the name of the printer AND i want to be able to name the document in the print queue. The overloads of the Print method dont seeem to allow this.

@aultmike

To print a Word document to a specific printer and also set a custom name for the document in the print queue, you can utilize the Print method of the Aspose.Words Document class. This method allows you to specify printer settings and a custom document name.

Here’s a code example demonstrating how to achieve this:

using System;
using System.Drawing.Printing;
using Aspose.Words;

class Program
{
    static void Main()
    {
        // Load the document
        Document doc = new Document("YourDocument.docx");

        // Create PrinterSettings object
        PrinterSettings printerSettings = new PrinterSettings();
        
        // Specify the printer name
        printerSettings.PrinterName = "YourPrinterName";

        // Set the print range if needed
        printerSettings.PrintRange = PrintRange.SomePages;
        printerSettings.FromPage = 1;
        printerSettings.ToPage = 1;

        // Print the document with a custom name in the print queue
        doc.Print(printerSettings, "My Custom Document Name");
    }
}

In this example:

  • Replace "YourDocument.docx" with the path to your Word document.
  • Set "YourPrinterName" to the name of the printer you want to use.
  • The Print method is called with the PrinterSettings object and a custom name for the document in the print queue.

This approach allows you to control both the printer selection and the document name as it appears in the print queue, fulfilling your requirements effectively.

For more detailed information, you can refer to the official documentation on printing documents with Aspose.Words here which provides additional context and examples.

If you have any further questions or need additional assistance, feel free to ask!

1 Like

PUUUUURRRRRFECT! Thanks!

1 Like

I notice that there are AutoResize and AutoRotate properties on the PdfViewer. Are there equivalent properties in Aspose.Words I can set for printing?

@aultmike No, there are no such properties in Aspose.Words print document.

Understood. What I’m seeing is once the document is printed to a print queue it looks like the paper size is off. Is there a way to specify the PageSettings when printing using Aspose Words?

@aultmike Pager tray can be explicitly specified using PageSetup.FirstPageTray and PageSetup.OtherPagesTray. But please note the value is implementation (printer) specific.
If the trays are properly setup in the template, printing should work as expected. You can use the following code to check what paper source is selected:

PrinterSettings settings = new PrinterSettings();
settings.PrinterName = "my printer";

for (int i = 0; i < settings.PaperSizes.Count; i++)
    Console.WriteLine(settings.PaperSizes[i]);

Console.WriteLine("====================================");

for (int i = 0; i < settings.PaperSources.Count; i++)
    Console.WriteLine(settings.PaperSources[i]);

Console.WriteLine("====================================");

Document doc = new Document(@"C:\Temp\in.docx");
for (int i = 0; i < doc.PageCount; i++)
{
    PageInfo pageInfo = doc.GetPageInfo(i);
    Console.WriteLine(pageInfo.GetDotNetPaperSize(settings.PaperSizes));
    Console.WriteLine(pageInfo.GetSpecifiedPrinterPaperSource(settings.PaperSources, settings.DefaultPageSettings.PaperSource));
    Console.WriteLine("---------------------------------");
}

Thanks for all your help! I seem to be having formatting issues… no matter what i do the top margin doesnt change. What can i provide to you to help me figure out this issue? Can I save it as a word doc?

I THOUGHT there used to be a document explorer where i could traverse parts of the document and see what its made up of. Yknow, document, section, paragraph, etc but cant seem to find it anymore.

@aultmike Could you please attach your input document here for testing? We will check the issue and provide you more information.

DocumentExplorer is a demo application. You can get DocumentExplorer sources from our Github .

My input document is a blob of text. I create a new instance of Document and then use builder to insert the teext into the body and then build a header and footer…

@aultmike You can try saving your document as MS Word (DOCX) document and as PDF (the same document layout engine is used for printing and for rendering to PDF). Then compare the results.

Here is a picture from Document explorer… could my problem be:

  1. i have inserted a table into the header and its not responding to the margins?
  2. i have margins or padding in the header itsself?

@aultmike Actually it is not quite clear what your problem is. If possible please provide you document, actual and expected output documents or screenshots. We will check the issue and provide you more information.