How to Print Preview when using a DocumentPaginator to print?

So I got it working after reading Pro WPF in C# 2008 (Page 726). Basically the DocumentViewer class needs an XPS file to present a print preview of it. So I do the following: PrintDialog dialog = new PrintDialog(); var paginator = new RowPaginator(rowsToPrint) { PageSize = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight) }; string tempFileName = System.IO.Path.GetTempFileName(); … Read more

Print styles: How to ensure image doesn’t span a page break

The only means I can think of is to use one (or potentially more) of the following css rules: img { page-break-before: auto; /* ‘always,’ ‘avoid,’ ‘left,’ ‘inherit,’ or ‘right’ */ page-break-after: auto; /* ‘always,’ ‘avoid,’ ‘left,’ ‘inherit,’ or ‘right’ */ page-break-inside: avoid; /* or ‘auto’ */ } I half-recall that these declarations only apply … Read more

how to print selected rows JTable

Seems to work okay for me… import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.print.PrinterException; import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.table.DefaultTableModel; import javax.swing.table.JTableHeader; public class TestPrint { public static void main(String[] args) { new TestPrint(); } public TestPrint() { EventQueue.invokeLater(new … Read more

Javascript Event Handler for Print

Different Style Sheets You can specify a different stylesheet for printing. <link rel=”stylesheet” type=”text/css” media=”print” href=”https://stackoverflow.com/questions/534977/print.css” /> <link rel=”stylesheet” type=”text/css” media=”screen” href=”main.css” /> One Style Sheet As kodecraft mentioned, you can also put the styles into the same file by using the @media block. @media print { div.box { width:100px; } } @media screen { … Read more

Print iframe content in Opera and Chrome

This is a known bug in Opera. In addition to the above ideas for workarounds, you may want to play with something like this: var clone=document.documentElement.cloneNode(true) var win=window.open(‘about:blank’); win.document.replaceChild(clone, win.document.documentElement); win.print(); I have not tested this but it should create a copy of the page in a popup window and print it, without having to … Read more

Print html document from Windows Service in C# without print dialog

Here’s the Holy Grail. Taking advantage of StaTaskScheduler (taken from Parallel Extension Extras (release on Code Gallery)). Features: waits for the printing completion, doesn’t show print settings, hopefully reliable. Limitations: requires C# 4.0, uses default printer, doesn’t allow to change print template TaskScheduler Sta = new StaTaskScheduler(1); public void PrintHtml(string htmlPath) { Task.Factory.StartNew(() => PrintOnStaThread(htmlPath), … Read more

Automatically open the printer dialog after providing PDF download

With JasperReports When using JasperReports, simply add this parameter to JasperReports exporter: exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, “this.print();”); This basically instructs Adobe Acrobat to execute the script this.print() when opening the PDF. See also page 79-80 of Adobe Acrobat Scripting Guide. Below is an extract of relevance: Printing PDF Documents It is possible to use Acrobat JavaScript to specify … Read more