Set the Default Paper Size for a Document to Legal with vb.net

Good Morning! Well it was a pretty quiet week. I had a lot of work related things to do so that is what I pretty much did. My daughter has been released to huber so that has got us all in an uproar as she needs many things. It will be interesting to see how this turns out. I pray for her daily despite everything that has happened.

Today’s topic is one that confounds many programmers. The PrintDocument object! Yes I can hear the snarling and gnashing of teeth going on out there. What we want to do is make the PrintDocument object follow our orders to make the document of legal size. If you have any experience with this you know this is not an easy task! Don’t forget if your printer does not support legal paper size (it happens) this will not work. Anyway, make it a great day!

Dim storedPageSettings As PageSettings = New PageSettings()
        Dim PSize As PaperSize = Nothing
        For Each PaperSizeContained As PaperSize In PrintDocument1.PrinterSettings.PaperSizes
            If (PaperSizeContained.RawKind = Printing.PaperKind.Legal) Then
                PSize = PaperSizeContained
                Exit For
            End If
        Next PaperSizeContained
        If (PSize Is Nothing) Then
            Throw New Exception("Oops! Can’t find Legal paper for this printer.")
        End If
        storedPageSettings.PaperSize = PSize    ‘<– this is the issue
        storedPageSettings.Landscape = True
        Dim dlg As New PrintPreviewDialog()
        PrintDocument1.DefaultPageSettings = storedPageSettings
        dlg.BringToFront()
        dlg.Document = PrintDocument1
        dlg.ShowDialog()

Technorati Tags: ,,,,,,,,,,,,,
,,,,,,,,

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: