2013-02-27 75 views
4

使用PrintDialog從WPF進行打印時,只能爲要打印的所有頁面設置默認頁面方向。我正在使用FixedDocument併爲我自己佈局的不同內容創建多個頁面,包括頁眉和頁腳行。其中一些頁面必須是橫向的,其他縱向。WPF固定文檔中的每個頁面方向

如何設置單頁的方向? FixedPage類不提供這樣的屬性。

+0

好問題。我想親自知道。 – 2013-04-06 16:20:57

回答

0

如何使用PrintTicket?

的PrintTicket對象是易於工作與 某些類型的XML文檔的表示被稱爲的PrintTicket的文件。後者 是一組指令,告訴打印機如何設置其各種功能(如雙面打印,整理和裝訂)。

我沒有它的一個明確的說法還沒有,但在這裏似乎是可以改變頁面的方向一個接一個:

// Use different PrintTickets for different FixedDocuments. 
PrintTicket ptFD = new PrintTicket(); 

if (_firstDocumentPrintTicket <= 1) 
{ // Print the first document in black/white and in portrait 
    // orientation. Since the PrintTicket at the 
    // FixedDocumentSequence level already specifies portrait 
    // orientation, this FixedDocument can just inherit that 
    // setting without having to set it again. 
    ptFD.PageOrientation = PageOrientation.Portrait; 
    ptFD.OutputColor = OutputColor.Monochrome; 
    _firstDocumentPrintTicket++; 
} 

else // if (_firstDocumentPrintTicket > 1) 
{ // Print the second document in color and in landscape 
    // orientation. Since the PrintTicket at the 
    // FixedDocumentSequence level already specifies portrait 
    // orientation, this FixedDocument needs to set its 
    // PrintTicket with landscape orientation in order to 
    // override the higher level setting. 
    ptFD.PageOrientation = PageOrientation.Landscape; 
    ptFD.OutputColor = OutputColor.Color; 
} 

http://msdn.microsoft.com/en-us/library/system.printing.pageorientation.aspx

+1

每個PrintTicket都會導致新的打印作業。打印到PDF等軟件打印機時,每個作業都將在自己的文件中寫入。因此創建一個新的PrintTicket將創建多個PDF文件,這在我的情況下是不可接受的。我需要在單個文檔中使用不同的方向,以便將其打印爲一個文檔。 – ygoe 2013-04-06 23:13:41

+0

我同意多個PDF文件而不是一個是不可接受的。感謝您清理它。我留下我的答案作爲一個教訓,如何不這樣做;) – 2013-04-10 07:34:13