Set Page Width and Height Programmatically

Is there any way to set the page width and height within the driver? Or possibly choose the stock. I have a service that prints labels (created as Crystal Reports) and I need a way to change the size of the label in the driver. My only other option is to create a several printers instances with different sizes for each physical printer. For reference I am using .net with c#.

Robin West
You can use the PrintDocument

You can use the PrintDocument class to set the page size.  Specifically the PrintDocument.PrinterSettings.PaperSizes allows you to access standard sizes and create custome page sizes.

From https://docs.microsoft.com/en-us/dotnet/api/system.drawing.printing.printersettings.papersizes?view=dotnet-plat-ext-5.0
// Add list of supported paper sizes found on the printer. 
// The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSize.DisplayMember = "PaperName";

PaperSize pkSize;
for (int i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++){
    pkSize = printDoc.PrinterSettings.PaperSizes[i];
    comboPaperSize.Items.Add(pkSize);
}

// Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
PaperSize pkCustomSize1 = new PaperSize("First custom size", 100, 200);

comboPaperSize.Items.Add(pkCustomSize1);

 

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments