Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Printing issue affecting the PaperSize settings?

Hello All,

I am working on a fairly straightforward Windows Forms app that takes in data and arranges it into a standard form. This form is then printed in one layout to standard office printers, and in another layout to a specialized roll-fed printer. I’m using VB.Net for this.

When printing to the roll-fed printer I need to be able to programmatically set the desired length of the printed page so that the printer cuts the label at the correct length without requiring the user to set it manually in the properties dialog. However, I’m having trouble affecting the page height of the print job as it’s sent to the printer.

If I attempt to set the paper size with the following code, the output shows the correct size in the print preview but when sent to the printer itself it still cuts the sheet using the current setting in the printer’s properties:

            Dim pkCustomSize1 As New PaperSize("Custom", 425, (NumericUpDown1.Value * 100))

            mDoc.DefaultPageSettings.PaperSize = pkCustomSize1

Why would it render correctly for the print preview, but still use the settings in the driver when actually sent to the printer? Does this mean that the driver in some way works incorrectly and applies the settings differently than the .NET Framework expects it to?

If I try to just set the height of the current paper size, I get an error saying that the height can only be set on a PaperSize if its kind = Custom. Checking the current kind, it returns that the PaperSize.Kind = Custom. Of course the PaperSize.Kind is ReadOnly, so it cannot be set.

Even stranger, if I use the following code, it still gives the error message that it can’t be changed unless the type is custom, when it would only be attempting to change it if it were custom:

        If mDoc.DefaultPageSettings.PaperSize.Kind = PaperKind.Custom Then

            mDoc.DefaultPageSettings.PrinterSettings.PaperSizes(6).Height = (NumericUpDown1.Value * 100)
        End If

If I just check the PaperSize value it returns: “[PaperSize custom Kind=Custom Height=0 Width=0]”, and checking Papersize.kind returns: “Papersize.kind = Custom” It seems odd that the Height and Width are set to 0. I’m assuming that the settings are being applied AFTER the print job is processed and as it is sent to the printer, taking the values currently held in the driver.

So, how do I access this page length setting in VB.NET? Is there something more I need to do to apply this custom size, or might they be using a custom or non-standard property for this length that I must access in another way? I’ve seen mention of DevMode and working with the API direct, but I’m not familiar with this. Do I need to actually access and set this property in the driver directly? How would I go about doing that?

I’ve search tirelessly through the web, books, and all MS documentation, but I have only found others who report the same problems and no solutions. Thanks in advance for your help with this.



Saturday, March 22, 2003

*  Recent Topics

*  Fog Creek Home