c# - Printing in WPF similar to Winforms -


below process worked in windows forms printing. used printdocument class. contains printpage event , used draw graphics of need print , obtained result expected.

below code:

public printdocument printing {    m_printdocument = new printdocument();    m_printdocument.printpage += new printpageeventhandler(onprintpage); } 

the code onprintpage follows:

protected virtual void onprintpage(object sender, printpageeventargs e)  {       //image img = have things printing in form of image.       e.graphics.drawimage(img, new point(0,0));  } 

in wpf:

i working fixed document , using below code can print

printdialog print = new printdialog(); print.printdocument(fixeddocument.documentpaginator, "print") //where fixed document contains data printed. 

this results insufficient memory continue execution of program. got fixed document without problem. solutions ...? hope similar thing windows form there in wpf too...

i used when pages contained lots of visual elements (drawings/images/ complex diagrams). instead of printing complete document @ once (which can lead out of memory)

print.printdocument(fixeddocument.documentpaginator, "print") 

i printed 1 of page.

 printqueue selectedprntqueue = printdialog.printqueue;       xpsdocumentwriter writer = printqueue.createxpsdocumentwriter(selectedprntqueue);  serializerwritercollator collator = writer.createvisualscollator();  collator.beginbatchwrite();  var paginator = fixeddocument.documentpaginator;  fixedpage fixedpage = paginator.getfixedpage(printedpagecount)  containervisual newpage = new containervisual();  size sz = new size(pagesize.height.value, pagesize.width.value);  fixedpage.measure(sz);  fixedpage.arrange(new rect(new point(), sz));  fixedpage.updatelayout();  newpage.children.add(fixedpage);  collator.write(newpage); 

i had gc after printing few pages (my magic number 10). may need tweak requirement.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -