【发布时间】:2016-04-03 07:04:51
【问题描述】:
我有一个 WPF 应用程序,我在其中创建了一个 XPS 文档(从 Excel),然后我能够将 XPS 文档转换为 PDF 文件:
PdfSharp.Xps.XpsConverter.Convert(sourceXpsFile, destPdfFile, 0);
但是当我的 XPS 文档包含多个页面时,只有第一页会转换为 PDF。
看来我的 XPS 文件有误,我创建了多个单个 XPS 文件,然后将它们合并:
public void MergeXpsDocument(string newFile, List<XpsDocument> sourceDocuments)
{
Thread th = new Thread(() =>
{
if (File.Exists(newFile))
{
File.Delete(newFile);
}
XpsDocument xpsDocument = new XpsDocument(newFile, System.IO.FileAccess.ReadWrite);
XpsDocumentWriter xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
FixedDocumentSequence fixedDocumentSequence = new FixedDocumentSequence();
foreach (XpsDocument doc in sourceDocuments)
{
FixedDocumentSequence sourceSequence = doc.GetFixedDocumentSequence();
foreach (DocumentReference dr in sourceSequence.References)
{
DocumentReference newDocumentReference = new DocumentReference();
newDocumentReference.Source = dr.Source;
(newDocumentReference as IUriContext).BaseUri = (dr as IUriContext).BaseUri;
FixedDocument fd = newDocumentReference.GetDocument(true);
newDocumentReference.SetDocument(fd);
fixedDocumentSequence.References.Add(newDocumentReference);
}
doc.Close();
}
xpsDocumentWriter.Write(fixedDocumentSequence);
xpsDocument.Close();
});
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
也许我应该使用其他方式来合并我的 XPS 文件?
【问题讨论】:
-
还有...?错误?警告?
-
没有错误或警告,PDF 被创建,但只有第一页。