111,092
社区成员




PrintDialog pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;
if (pDialog.ShowDialog()==true)
{
using (XpsDocument xpsDocument = new XpsDocument(printDocFile, FileAccess.ReadWrite))
{
FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "证书打印");
}
}
var printDialog = new PrintDialog();
printDialog.UserPageRangeEnabled = true;
try
{
if (printDialog.ShowDialog() == true)
{
printDialog.PrintTicket.PageBorderless = System.Printing.PageBorderless.None;
DocumentPaginator MyDocumentPaginator = ((IDocumentPaginatorSource)fixedDoc).DocumentPaginator;
MyDocumentPaginator.PageSize = new Size(96 * 18.8, MyPageHList.Max());
if (printDialog.PageRangeSelection == PageRangeSelection.UserPages)
{
var xdw = System.Printing.PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue);
var vtxd = (System.Windows.Xps.VisualsToXpsDocument)xdw.CreateVisualsCollator();
for (int i = printDialog.PageRange.PageFrom - 1; i < printDialog.PageRange.PageTo; i++)
{
var v = MyDocumentPaginator.GetPage(i).Visual;
var cv = new ContainerVisual();
cv.Children.Add(v);
vtxd.Write(cv, printDialog.PrintTicket);
cv.Children.Remove(v);
}
vtxd.EndBatchWrite();
}
else
{
printDialog.PrintDocument(MyDocumentPaginator, "打印");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}