I have a System.Window.Controls.PrintDialog and I want to print pages with landscape mode and portrait mode in with single PrintTicket but it seems I only can set the orientation once.
我有一个System.Window.Controls.PrintDialog,我想用单个PrintTicket打印横向模式和纵向模式的页面,但似乎我只能设置一次方向。
As long as I want to print on paper this may not be a big deal but I want to print/create a PDF document from my Printjob. There I need pages with Landscape and Portrait mode in onc document.
只要我想在纸上打印,这可能不是什么大问题,但我想从我的Printjob打印/创建PDF文档。我需要在onc文档中使用横向和纵向模式的页面。
So far I managed to rotate the landscape pages 90 degree and this works fine but in the PrintPreview it looks very strange because of the rotated content.
到目前为止,我设法将景观页面旋转90度,这很好,但在PrintPreview中,由于旋转的内容,它看起来很奇怪。
2 个解决方案
#1
1
Not as clean as you would like and more of a workaround but I think it might accomplish your goal. You can use the iTextSharp library to concatenate PDFs into one following multiple print jobs. Here is some sample code.
不像你想要的那么干净,而是更多的解决方法,但我认为它可能会实现你的目标。您可以使用iTextSharp库将PDF连接到多个打印作业之后。这是一些示例代码。
Hopefully someone comes up with a more straight forward solution.
希望有人提出更直接的解决方案。
#2
1
A long time later ...
很久以后......
You can do this by providing an EventHandler that gets called, asking for a custom PrintTicket, before each page is printed. The PageViewModel here effectively comprises
您可以通过在每个页面打印之前提供一个被调用的EventHandler,要求自定义PrintTicket来完成此操作。这里的PageViewModel有效地包含
PageViewModel{
Page Page {get;set;}
PageOrientation? PageOrientation {get;set}
}
if (PrintDialog.ShowDialog() == true)
{
XpsDocumentWriter xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(PrintDialog.PrintQueue);
xpsDocumentWriter.WritingPrintTicketRequired += (s, e) =>
{
PageViewModel pVM = publicationVM.Pages[e.Sequence - 1];
if (pVM.Orientation != null && pVM.Orientation != publicationVM.Orientation)
{
e.CurrentPrintTicket = new PrintTicket();
e.CurrentPrintTicket.PageOrientation = PageOrientation.Portrait;
}
};
VisualsToXpsDocument visualsToXpsDocument = (VisualsToXpsDocument) xpsDocumentWriter.CreateVisualsCollator(PrintDialog.PrintTicket, PrintDialog.PrintTicket);
visualsToXpsDocument.BeginBatchWrite();
Page page;
foreach (PageViewModel pVM in publicationVM.Pages)
{
page = pVM.Page;
visualsToXpsDocument.Write(page);
}
visualsToXpsDocument.EndBatchWrite();
}
and bingo! mixed Portrait and Landscape. Duplexing this is fine too.
和宾果游戏!混合肖像和风景。双工这也很好。
#1
1
Not as clean as you would like and more of a workaround but I think it might accomplish your goal. You can use the iTextSharp library to concatenate PDFs into one following multiple print jobs. Here is some sample code.
不像你想要的那么干净,而是更多的解决方法,但我认为它可能会实现你的目标。您可以使用iTextSharp库将PDF连接到多个打印作业之后。这是一些示例代码。
Hopefully someone comes up with a more straight forward solution.
希望有人提出更直接的解决方案。
#2
1
A long time later ...
很久以后......
You can do this by providing an EventHandler that gets called, asking for a custom PrintTicket, before each page is printed. The PageViewModel here effectively comprises
您可以通过在每个页面打印之前提供一个被调用的EventHandler,要求自定义PrintTicket来完成此操作。这里的PageViewModel有效地包含
PageViewModel{
Page Page {get;set;}
PageOrientation? PageOrientation {get;set}
}
if (PrintDialog.ShowDialog() == true)
{
XpsDocumentWriter xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(PrintDialog.PrintQueue);
xpsDocumentWriter.WritingPrintTicketRequired += (s, e) =>
{
PageViewModel pVM = publicationVM.Pages[e.Sequence - 1];
if (pVM.Orientation != null && pVM.Orientation != publicationVM.Orientation)
{
e.CurrentPrintTicket = new PrintTicket();
e.CurrentPrintTicket.PageOrientation = PageOrientation.Portrait;
}
};
VisualsToXpsDocument visualsToXpsDocument = (VisualsToXpsDocument) xpsDocumentWriter.CreateVisualsCollator(PrintDialog.PrintTicket, PrintDialog.PrintTicket);
visualsToXpsDocument.BeginBatchWrite();
Page page;
foreach (PageViewModel pVM in publicationVM.Pages)
{
page = pVM.Page;
visualsToXpsDocument.Write(page);
}
visualsToXpsDocument.EndBatchWrite();
}
and bingo! mixed Portrait and Landscape. Duplexing this is fine too.
和宾果游戏!混合肖像和风景。双工这也很好。