c# - Efficient way to count number of pages to print? -


tldr how can 1 efficiently determine amount of pages have printed?

** note: marked klugerama's answer answer question. i'm still open other suggestions though!

currently, have application in production prints invoices. printing isn't problem: customer information, invoice details etc printed should be. however, users complaining time takes software send print job printer.

at moment, have implemented rather inefficient way print. in order know how many pages have print, 'dry run' of print job , cancel before gets sent printer. count number of pages print job contains , add information print job sent printer. this, 'abuse' printdocument.printpage method. after doing so, can print "page 1/2 - page 2/2" etc.

i'm thinking handling in different way. know margins have in page, header , footer. ergo, space between header , footer available space print article information (name, price etc). if calculate height of string (using graphics.measurestring), can tell when articles take more space on page that's available printing.

previously, printing take minute before getting sent printer (taken account clients run software aren't fastest around). have implemented method, , printing takes 5-10 seconds. however, i'm wondering if way go. can't imagine i'm 1 dealing issue; how deal this?

i'm open different approaches.

what doing sounds way go. but...

you instead output xml , use xslt style output, handle pagination you. note require pretty substantial refactoring effort, depending on situation it's not feasible, it's option.

it provide potential flexibility down road, provides more modular approach. allow more provide other output options, html & pdf. may make "print preview" easier.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -