.net - Print XpsDocument scaled to fit page -
we using telerik's wpf charting controls in our application. charting controls have built-in support exporting graphics xps file. want utilize wpf's support printing xps documents print chart. part, works great, i'm having trouble scaling chart fit 1 page. chart graphic cut off on right , bottom. chart coming out large page. ideas?
here code i'm using:
const string packageuristring = "pack://inmemorychart.xps"; using (var memorystream = new memorystream()) { //utilize telerik chartview method export xps... _chart.exporttoxps(memorystream); using (var package = package.open(memorystream)) { var packageuri = new uri(packageuristring); packagestore.addpackage(packageuri, package); var xpsdocument = new xpsdocument(package, compressionoption.maximum, packageuristring); var printdialog = new printdialog(); var result = printdialog.showdialog(); if (!result.getvalueordefault()) return; var fixeddocumentsequence = xpsdocument.getfixeddocumentsequence(); if (fixeddocumentsequence == null) return; var documentpaginator = fixeddocumentsequence.documentpaginator; if (documentpaginator == null) return; //attempt adjust fit page? adjustflowdocumenttopage(documentpaginator, printdialog.printqueue); printdialog.printdocument(documentpaginator , "chart"); packagestore.removepackage(packageuri); } }
i found adjustflowdocumenttopage on site:
public static void adjustflowdocumenttopage(documentpaginator documentpaginator, printqueue printqueue) { const double inch = 96; var printticket = printqueue.userprintticket; // media size. double width = printticket.pagemediasize.width.value; double height = printticket.pagemediasize.height.value; // set margins. const double leftmargin = 1.25 * inch; const double rightmargin = 1.25 * inch; const double topmargin = 1 * inch; const double bottommargin = 1 * inch; // calculate content size. var contentwidth = width - leftmargin - rightmargin; var contentheight = height - topmargin - bottommargin; documentpaginator.pagesize = new size(contentwidth, contentheight); }
upon further research, found following implementation , seems work great! http://www.telerik.com/community/forums/wpf/chart/behaviour-based-chart-print-solution.aspx
Comments
Post a Comment