2012-04-23 141 views
0

我已經問了過去的類似問題,但自那時起就沒有快樂解決我的問題。我不是Xps文檔的專家,但設法確定了我的問題...XPS - 使用圖像打印文檔

下面的示例需要DocumentPaginator參數,只是打印文檔。 第一個示例工作正常,第二個示例不打印嵌入在文檔中的圖像。

// this works 

XpsDocumentWriter xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(printQueue); 
xpsDocumentWriter.Write(document); // where document is a DocumentPaginator 

// this doesn't work (it prints but no images) 

// create new doc 
XpsDocument doc = new XpsDocument(package, CompressionOption.NotCompressed, "pack://TempTemporaryPackageUri.xps"); 

// create writer for new doc 
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc); 

// write document 
writer.Write(document, printQueue.DefaultPrintTicket); 

// create writer for print job 
XpsDocumentWriter xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(printQueue); 

// i think it's here where the resources are being lost 

// write document 
xpsDocumentWriter.Write(doc.GetFixedDocumentSequence()); 

我需要創建一個新文檔的原因是因爲我需要在分頁後操作XpsDocument。

任何人都可以指出我正確的方向,關於能夠將資源從一個文檔複製到另一個文檔?

任何意見讚賞。

由於提前,

山姆

+1

我認爲你還在追逐錯誤的道路。創建分頁的XPS文檔後,請直接修改該文檔,而不是嘗試複製它。 – Jon 2012-04-23 16:51:50

+0

然後,您如何將xpsdocument打印到打印隊列中。看起來,當我從getfixeddocument序列創建一個新文檔時,它會丟失資源 - 或者將它們留在原始文檔中。我必須缺少一些簡單的 – sambomartin 2012-04-23 21:22:58

+0

[PrintQueue.AddJob](http://msdn.microsoft.com/en-us/library/ms553644.aspx)將是一個很好的開始。 – Jon 2012-04-23 21:33:06

回答

0

你可以試試下面的代碼的鏈接給出。它正在轉換爲XPS和PDF格式。

http://msdn.microsoft.com/en-us/library/bb412305(v=office.12).aspx

+0

感謝您的回覆anshul,但我試圖從現有的文檔創建一個XpsDoc,但添加一個額外的視覺到每個頁面。我沒有使用Word或PDF。謝謝。 – sambomartin 2012-04-23 12:13:54

+0

好的。但在該代碼中,您的要求和示例之間的差異僅在於將格式更改爲wdExportFormatXPS,並且如果您想添加一些數據,則只需按FileStreamer編寫文檔字段並將其轉換即可。 – 2012-04-25 10:45:34