你们会如何建议我将FlowDocument转换为PDF并附加到电子邮件中?
FlowDocument是动态的,而不是静态的。
我希望能够将PDF存储在内存中作为byte[],而非存储在磁盘上,但这是可商量的。
感谢你们的帮助!
你们会如何建议我将FlowDocument转换为PDF并附加到电子邮件中?
FlowDocument是动态的,而不是静态的。
我希望能够将PDF存储在内存中作为byte[],而非存储在磁盘上,但这是可商量的。
感谢你们的帮助!
http://xamltopdf.codeplex.com/
创建PDF非常简单,它还支持表格和图片。
免责声明:我不为任何这些公司或它们的竞争对手工作。我已经使用过Adobe SDK、Amyuni打印机和各种XPS技巧,并取得了相当不错的成功。没有一种方法能够100%准确地转换。
当我需要做这件事情时,我将FlowDocument保存为XPS文件,最后使用PDFSharp转换为PDF并删除XPS文件。
var test = (IDocumentPaginatorSource)flowDoc;
XpsDocument xpsDocument = new XpsDocument(xpsFileLocation, FileAccess.ReadWrite);
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
writer.Write(test.DocumentPaginator);
xpsDocument.Close();
PdfSharp.Xps.XpsConverter.Convert(xpsFileLocation, pdfFileLocation, 0);
File.Delete(xpsFileLocation);
希望这能帮助到某些人
我成功地使用PDFCreator打印机驱动程序使其工作。您需要安装该驱动程序才能使其正常工作,因此对于某些人来说可能不是理想的解决方案。有一个可用的COM接口。代码大致如下:
PDFCreator.clsPDFCreator _PDFCreator;
PDFCreator.clsPDFCreatorError pErr;
if (_PDFCreator.cStart(parameters, false))
{
_PDFCreator.cClearCache();
_PDFCreator.set_cOption("UseAutosave", 1);
_PDFCreator.cPrinterStop = false;
}
_PDFCreator.set_cOption("AutosaveFilename", file);
_PDFCreator.set_cOption("AutosaveDirectory", folder);
PrintDialog printDialog = new PrintDialog();
printDialog.PrintDocument(((IDocumentPaginatorSource)flowDoc).DocumentPaginator, "Report");
new PdfCreatorComWrapper().CreatePdf(DocumentPaginator, filename);
包装器源代码可在 GitHub 上获取。 - Louis SomersSiberix.Report.Report report = CreateMyPdfReport(); //You write this
Stream stream = new MemoryStream();
report.Publish(stream, Siberix.Report.FileFormat.PDF);
byte[] bytes = stream.ToArray();
现在字节可以保存到数据库表或其他任何地方。