locked
Customize PaperSize RRS feed

  • Question

  • User238179898 posted
    I have been having problems trying to customize a PaperSize propery in a print command. The program needs to print to a tractor feed printer that will be printing cards that are 3.375w x 2.125h. The customer needs the ability to print 1 card or 1000 cards at the click of a button. The problem is that while the amount of cards actually printed is correct the printer will still roll out several unprinted cards because it thinks its printing an 8 x 11 sheet of paper. To customize the page size I wrote the following subs (I am using the System.Drawing.Printing namespace): Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Print Card Dim pd As New PrintDocument AddHandler pd.PrintPage, AddressOf myPagePrintFunction pd.PrinterSettings.PrinterName = "Generic" pd.DocumentName = "Card" pd.DefaultPageSettings.PaperSize.Width = 3.375 pd.DefaultPageSettings.PaperSize.Height = 2.125 pd.Print() End Sub Sub myPagePrintFunction(ByVal sender As Object, ByVal e As PrintPageEventArgs) e.PageSettings.PaperSize.Height = 2.125 e.PageSettings.PaperSize.Width = 3.375 e.HasMorePages = False End Sub The error returned is: System.ArgumentException: Cannot change a PaperSize unless its Kind is Custom. So I added this line to the myPagePrintFunction: e.PageSettings.PaperSize.Kind = PaperKind.Custom Now this error is being returned: BC30526: Property 'Kind' is 'ReadOnly'. Has anyone encountered a simular problem before? Is there a way to tell the printer that the PaperSize is only 2 inches high and not 11.
    Tuesday, February 8, 2005 9:39 AM

All replies

  • User-226509506 posted

    I just encountered the same problem, the line highlighted in red should solve the problem.

    e.PageSettings.PaperSize = new PaperSize("Custom", 800, 500);

    Response.Write(e.PageSettings.PaperSize.Kind);

    if(e.PageSettings.PaperSize.Kind == PaperKind.Custom)

    {

    e.PageSettings.PaperSize.Height = e.PageSettings.PaperSize.Height / 2;

    e.PageSettings.PaperSize.Width = e.PageSettings.PaperSize.Width;

    }

    Tuesday, October 18, 2005 3:37 AM
  • User-226509506 posted

    If your printer software settings does support Custom paper size, you will not be able to print on Custom size paper, even if you set paper size programatically.

    Monday, October 24, 2005 10:30 AM
  • User1598201143 posted

    how could I set the Report1.Rdlc Page Size

    Tuesday, May 6, 2008 5:04 AM
  • User-604346143 posted

    Hi, I just posted a solution to set the papersize and also to change margins and pagesize at runtime...

    http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=6718&lngWId=10

    Hope it helps!!

    Wednesday, July 23, 2008 2:52 PM
  • User-1928360866 posted

    e.PageSettings.PaperSize = new PaperSize("Custom", 800, 500); Paper Size should be the size in inches multiplied by 100 public PaperSize(string name, int width, int height); width: The width of the paper, in hundredths of an inch. eight: The height of the paper, in hundredths of an inch.

    Tuesday, October 13, 2009 5:58 AM
  • User-1928360866 posted

    e.PageSettings.PaperSize = new PaperSize("Custom", 800, 500);

    Paper Size should be the size in inches multiplied by 100

    public PaperSize(string name, int width, int height);

    width: The width of the paper, in hundredths of an inch.

    height: The height of the paper, in hundredths of an inch.

    Tuesday, October 13, 2009 6:02 AM