Search code examples
c#.netwpfpdfflowdocument

What's the best way to convert a FlowDocument into PDF


How would ya'll recommend that I convert a FlowDocument to PDF to be attached to an EMail?

The FlowDocument is dynamic, not static.

I would prefer to be able to store the PDF in memory as a byte[], rather than on disk, but that is negotiable.

Thanks for your help!


Solution

  • You have two options that I know of.

    The first is to use a proprietary library called NiPDF, alternatively you can use Word Interop.

    1. Save the FlowDocument to a DOCX file using Open XML SDK
    2. Use Word Interop to load the saved document from some temporary store
    3. Set the WdSaveFormat to wdFormatPDF
    4. Save the document again (remember to rename the file to PDF)

    You can find further info here