Get print page count without printing the document

huMpty duMpty

This is somewhat similar to question about Is there a better way to get the page count from a PrintDocument than this?

But in my case I have a web-browser control with formatted html. At the moment I have option which calls ShowPrintPreviewDialog() so user can see how many pages going to be printed.

Is there anyway to get the no of pages which going to be printed, without launching the PrintPreview?

I am trying to create a method which will call OnTextChange and display print-page count automatically?

I have use PrintPage event

private void PrintDocumentOnPrintPage(object sender, PrintPageEventArgs e)
 {
     e.Graphics.DrawString(this.webBrowser1.DocumentText, this.webBrowser1.Font, Brushes.Black, 10, 25);               
 }
Hans Passant

Bad news always travels slow at SO. You'll need to scratch the idea that this is practical.

Although unstated in the question, you should have already figured out by now that your PrintPage event handler doesn't work. It always produces a count of 1. That's because you never set the e.HasMorePages property to true, the property that causes more than one page to be generated.

To reliably set that property to true, you need to figure out exactly how the HTML gets rendered by the browser layout engine. And figure out exactly how to break it up into pages that don't cut, say, a line of text or an image in two. And figure out how to this is in the exact same way that the browser printing engine does this. A feat that's been attempted by many a programmer, accomplished by none. The browser's automation object model just doesn't have the needed api.

The only reasonable way is the one you already know. You have to call ShowPrintPreviewDialog(). Which readily displays the page count in the preview dialog, looks like this in IE11:

enter image description here

In case you'd consider snooping that number off the dialog: no, that cannot work either. The dialog doesn't use any controls, it is one monolithic window.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Print File(NotePad) Without the name of the file appearing in the printing document

From Dev

Apache Poi: get page count in DOC document

From Dev

how to get page count in dompdf without using page text

From Dev

PDF attached with Paperclip - get document properties (like page count)

From Dev

trying to print search "label" and "description" without printing anything else within the page

From Dev

Printing a HTML page without page information

From Dev

How can i get the Facebook page like count without login?

From Java

Print page numbers on pages when printing html

From Dev

how to print a document without having displayed the address at the bottom of the page in php or javascript

From Dev

Printing in client side without print Dialog Box

From Dev

Notepad++ Display Printing Page Count

From Dev

Print external page without open it

From Dev

Winforms print multi-page document

From Dev

Printing a Document

From Dev

Insert page headers/footers when printing HTML document

From Dev

Print range - print from page x until end of document

From Dev

Google Cloud Print API - white page when printing PDF

From Dev

Should I use @media print for a page that is solely used for printing?

From Dev

Get output of system ping without printing to the console

From Dev

Get Scilab to calculate without printing result

From Dev

Print the summary of an lm or fastLm() model without printing the coefficients

From Dev

Printing an html file using java without showing print dialog to the user

From Dev

Why is my program printing values without a corresponding print statement?

From Dev

Print caught Exception type without printing the error description

From Dev

Printing an html file using java without showing print dialog to the user

From Dev

IE11 crashes when printing without Print dialog

From Dev

Printing a Report from a Form in Access without a print preview or opening report?

From Dev

is this possible to print the web page in android without popup?

From Dev

How do I print the page without the datatable

Related Related

  1. 1

    Print File(NotePad) Without the name of the file appearing in the printing document

  2. 2

    Apache Poi: get page count in DOC document

  3. 3

    how to get page count in dompdf without using page text

  4. 4

    PDF attached with Paperclip - get document properties (like page count)

  5. 5

    trying to print search "label" and "description" without printing anything else within the page

  6. 6

    Printing a HTML page without page information

  7. 7

    How can i get the Facebook page like count without login?

  8. 8

    Print page numbers on pages when printing html

  9. 9

    how to print a document without having displayed the address at the bottom of the page in php or javascript

  10. 10

    Printing in client side without print Dialog Box

  11. 11

    Notepad++ Display Printing Page Count

  12. 12

    Print external page without open it

  13. 13

    Winforms print multi-page document

  14. 14

    Printing a Document

  15. 15

    Insert page headers/footers when printing HTML document

  16. 16

    Print range - print from page x until end of document

  17. 17

    Google Cloud Print API - white page when printing PDF

  18. 18

    Should I use @media print for a page that is solely used for printing?

  19. 19

    Get output of system ping without printing to the console

  20. 20

    Get Scilab to calculate without printing result

  21. 21

    Print the summary of an lm or fastLm() model without printing the coefficients

  22. 22

    Printing an html file using java without showing print dialog to the user

  23. 23

    Why is my program printing values without a corresponding print statement?

  24. 24

    Print caught Exception type without printing the error description

  25. 25

    Printing an html file using java without showing print dialog to the user

  26. 26

    IE11 crashes when printing without Print dialog

  27. 27

    Printing a Report from a Form in Access without a print preview or opening report?

  28. 28

    is this possible to print the web page in android without popup?

  29. 29

    How do I print the page without the datatable

HotTag

Archive