how to create user defined paper size to a netwrok printer

Answered how to create user defined paper size to a netwrok printer

  • Thursday, September 30, 2010 1:11 PM
     
     

    Hi, 

    How can I create a user defined paper size to a network printer on Windows XP ?

All Replies

  • Thursday, September 30, 2010 1:58 PM
     
     Answered
    new PaperSize("Custom", Width, Height)
  • Friday, October 01, 2010 1:53 PM
     
     

    This does not work

  • Friday, October 01, 2010 2:14 PM
     
     

    This does not work


    What does not work?  Post your code.
  • Wednesday, October 06, 2010 9:19 AM
     
     

    I created two custom pages size.

    Dim pCustomeSize1 As New PaperSize("Custom_01", 100, 200)
    Dim pCustomeSize2 As New PaperSize("Custom_02", 100, 300)

    How can I add these to a printers sizes "PrintDocument.PrinterSettings.PaperSizes" is readonly property?

    Even if I tries to change the default page size of the printer with these created custom page size (see the code below). It does not work becuase these page sizes does not exist on the printer.

    Dim pdPrinting As New PrintDocument
    pdPrinting.PrinterSettings.DefaultPageSettings.PaperSize = pCustomeSize1

    So, How can I Add these customer paper sizes to a printer?

  • Wednesday, October 06, 2010 11:13 AM
     
     
    You can't change the Windows dialogs.  You can only change the PaperSize used by the PrintDocument in the PrintPage event.
  • Wednesday, October 06, 2010 11:58 AM
     
      Has Code

    Can you explain some more.

    I can change the page size if the page size exists on the printer for example:

    Private WithEvents pdPrinting As New PrintDocument
    ...........
          For Each PZ As Printing.PaperSize In pdPrinting.PrinterSettings.PaperSizes
            If PZ.PaperName = sPaperSizeName Then
              pdPrinting.DefaultPageSettings.PaperSize = PZ
              Exit For
            End If
          Next
    

    This works and print is on the assigned size But I need to create my own sizes; then which i want to use for printing?

  • Wednesday, October 06, 2010 12:16 PM
     
     

    See my first post.  Set the PrintDocument paper size tto the new PaperSize.

  • Wednesday, October 06, 2010 1:41 PM
     
      Has Code

    HI, I have following code int the PrintPage EventHandler. It changes the page size here but the actual print out is on not this assigned page size.

     

        Dim pCustomeSize1 As New PaperSize("Custom_01", 1000, 1969)
        e.PageSettings.PaperSize = pCustomeSize1
    

     

    I also think when once print is sent i.e. "PrintDocument.Print()". then size of the page cannot be changed. If changed then it has no effect of the actual printer output.

  • Wednesday, October 06, 2010 1:53 PM
     
     
    You can change the paper size any time before the execution of the PrintPage event for the page being printed.  If you change the paper size within the PrintPage event, the change will apply on the next page printed.  But your code in the last post doesn't do anything.  The e arguments of the PrintPageEventArgs are all Gets.  If you do as I have recommended in this thread, set the paper size of the PrintDocument, the setting will persist.
  • Wednesday, October 06, 2010 2:14 PM
     
      Has Code
    Dim pdPrinting As New PrintDocument
    AddHandler pdPrinting.PrintPage, AddressOf PrintPageHandler
    
    Dim sPrinterName As String = pdPrinting.PrinterSettings.PrinterName
    
    Dim pzCustom01 As New PaperSize("custom_01", 1000, 1500)
    pdPrinting.PrinterSettings.DefaultPageSettings.PaperSize = pzCustom01
    pdPrinting.Print()
    
    Private Sub PrintPageHandler(ByVal sender As Object, ByVal e As PrintPageEventArgs)
    e.HasMorePages = False
    End Sub
    
    This does not work with custom sizes (As I mentioned in this thread). This would only works if the size is already exist on the printing properties of the printer.
  • Wednesday, October 06, 2010 2:25 PM
     
     
    I don't understand your code.  Why don't you set the PrintDocument's paper size to the size you want?
  • Wednesday, October 06, 2010 2:36 PM
     
     Answered
    Imports System.Drawing.Printing
    Public Class Form1
      
    Dim WithEvents PD As New PrintDocument
      
    Private Sub Button1_Click(ByVal sender As Object, _
                                
    ByVal e As EventArgs) _
                                
    Handles Button1.Click
        PD.DefaultPageSettings.PaperSize = 
    New PaperSize("Custom01", 100, 200)
        PD.Print()
      
    End Sub
      Private Sub PD_QueryPageSettings(ByVal sender As Object, _
                                       
    ByVal e As QueryPageSettingsEventArgs) _
                                       
    Handles PD.QueryPageSettings
        Console.WriteLine(e.PageSettings.PaperSize)
        e.PageSettings.PaperSize = 
    New PaperSize("Custom02", 100, 300)
      
    End Sub
      Private Sub PD_PrintPage(ByVal sender As Object, _
                               
    ByVal e As PrintPageEventArgs) _
                               
    Handles PD.PrintPage
        Console.WriteLine(e.PageSettings.PaperSize)
        e.Cancel = 
    True
      End Sub
    End
     Class