Question

When sending a document, lets say TIFF images to a printer we can send meta-data with the image such as the paper size "Legal, Photo etc". The printer is able to use this information to select a paper tray matching this paper size.

I have a program that generates a tif document and uses PrintDocument to generate a Print job. This process occurs programmatically (no UI). Is it possible to alter the metadata of the tif image programmatically before I send the job to the printer?

E.G. I want to change the paper size of the image to "Legal". This way I can tell the printer which tray to use. I have explored generating an XPS document out of the TIF. Then going back through a XPS API to set the property. However, this solution feels a little heavy. I hope for someone with more experience in this type of programming to point me in the right direction.

Was it helpful?

Solution

The paper size option is available in PrintDocument

private void SetPaperSize()
{
    int legalPaperIndex = 5;//See all types: http://msdn.microsoft.com/en-us/library/system.drawing.printing.papersize.rawkind.aspx
    for (int i = 0; i < printDocument.PrinterSettings.PaperSizes.Count - 1; i++)
    {
        if (printDocument.PrinterSettings.PaperSizes[i].RawKind == legalPaperIndex)
        {
            printDocument.DefaultPageSettings.PaperSize = printDocument.PrinterSettings.PaperSizes[i];
        }
    }    
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top