How to print in C# html document in ONE page

John Conor

How to print in C# html document in ONE page on windows printer? I need to print bill with different length and it must be at one page. But in my example with many amount of strings in bill it is separate to few pages.

I was use this example of code for printing html:

private void PrintHelpPage()
{
    // Create a WebBrowser instance. 
    WebBrowser webBrowserForPrinting = new WebBrowser();

    // Add an event handler that prints the document after it loads.
    webBrowserForPrinting.DocumentCompleted +=
        new WebBrowserDocumentCompletedEventHandler(PrintDocument);

    // Set the Url property to load the document.
    webBrowserForPrinting.Url = new Uri(@"\\myshare\bill.html");
}

private void PrintDocument(object sender,
    WebBrowserDocumentCompletedEventArgs e)
{
    // Print the document now that it is fully loaded.
    ((WebBrowser)sender).Print();

    // Dispose the WebBrowser now that the task is complete. 
    ((WebBrowser)sender).Dispose();
}

I know how to read hight of my page from WebBrowser control wb.Document.Body.ScrollRectangle.Height

And try to change dimensions of page by few different ways:

PrintDocument pd = new PrintDocument();
PaperSize pkCustomSize1 = new PaperSize("First custom size", 310, 250);

pd.DefaultPageSettings.PaperSize = pkCustomSize1;
System.Drawing.Printing.PaperSize("Custom Paper Size", 250, 550);

pd.SDefaultPageSettings.PaperSize.Kind = PaperKind.Custom;
pd.DefaultPageSettings.PaperSize.Height = 1633;

But it still separate to few pages while printing. Thanks

John Conor

I was found solution here https://gist.github.com/huanlin/5671168 Helper classes for change printer settings with P/Invoke.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to print in C# html document in ONE page

From Dev

How do I print 4 impressions of a one page document onto a single page in Word?

From Dev

How can I make Word print a one-page document multiple times on one single sheet?

From Dev

How to Print more than one page in C#

From Dev

PDFBox. Java: How to print only one page of PDF instead of full document?

From Dev

How to print 8 copies of a one page LibreOffice document to 2 sheets of paper?

From Dev

Is there a way to print multiple worksheets into one document, with correct page numbers?

From Dev

print multiple pages from a word document on one page

From Dev

How to print a document using C# code?

From Dev

C# print html document from html string

From Dev

How to force an empty page in a paged HTML document?

From Dev

Android: How to print an HTML page directly on Samsung Mobile Print

From Dev

Print preview one page

From Dev

How to call a function in one html page in another html page

From Dev

VueJS Print HTML to Page

From Dev

Print html to multiple page

From Dev

How to print page title of parent and up to one child only in WordPress

From Dev

How to set 'Fit all columns on one page' in print tab

From Dev

How to print multiple pages per side with one(right) page blank?

From Dev

How can I print one page enlarged to multiple pages?

From Dev

How do I print multiple images to one page on Chrome OS?

From Dev

How to achieve print with "Fit sheet on one page" using javascript

From Dev

How does one make a html scrolling page

From Dev

Why won't my HTML page print according to my CSS document?

From Dev

how many `<main>` main tag can be used in a html document / Page

From Dev

How to use document.write() method to write into current html page?

From Dev

How do I convert a word document into a single .html web page?

From Dev

How to output a String into an HTML document page from a native Function API

From Dev

Chrome Print - Save as PDF - Print to One Page

Related Related

  1. 1

    How to print in C# html document in ONE page

  2. 2

    How do I print 4 impressions of a one page document onto a single page in Word?

  3. 3

    How can I make Word print a one-page document multiple times on one single sheet?

  4. 4

    How to Print more than one page in C#

  5. 5

    PDFBox. Java: How to print only one page of PDF instead of full document?

  6. 6

    How to print 8 copies of a one page LibreOffice document to 2 sheets of paper?

  7. 7

    Is there a way to print multiple worksheets into one document, with correct page numbers?

  8. 8

    print multiple pages from a word document on one page

  9. 9

    How to print a document using C# code?

  10. 10

    C# print html document from html string

  11. 11

    How to force an empty page in a paged HTML document?

  12. 12

    Android: How to print an HTML page directly on Samsung Mobile Print

  13. 13

    Print preview one page

  14. 14

    How to call a function in one html page in another html page

  15. 15

    VueJS Print HTML to Page

  16. 16

    Print html to multiple page

  17. 17

    How to print page title of parent and up to one child only in WordPress

  18. 18

    How to set 'Fit all columns on one page' in print tab

  19. 19

    How to print multiple pages per side with one(right) page blank?

  20. 20

    How can I print one page enlarged to multiple pages?

  21. 21

    How do I print multiple images to one page on Chrome OS?

  22. 22

    How to achieve print with "Fit sheet on one page" using javascript

  23. 23

    How does one make a html scrolling page

  24. 24

    Why won't my HTML page print according to my CSS document?

  25. 25

    how many `<main>` main tag can be used in a html document / Page

  26. 26

    How to use document.write() method to write into current html page?

  27. 27

    How do I convert a word document into a single .html web page?

  28. 28

    How to output a String into an HTML document page from a native Function API

  29. 29

    Chrome Print - Save as PDF - Print to One Page

HotTag

Archive