Print XMAL FlowDocument as PDF using novaPDF

Have questions about novaPDF (desktop or server), or having problems using it? Ask here for help.
Post Reply
cebert
Posts: 2
Joined: Tue Jan 17, 2017 3:58 pm

Print XMAL FlowDocument as PDF using novaPDF

Post by cebert »

All,

I was wondering if it is possible to print a XAML FlowDocument as a PDF using Nova. I can print a FlowDocument to a printer selected by an end user, using the following code method included below. However, what I am trying to do is print the FlowDocument to the Nova printer, without using the PrintDialog. From my understanding the novaPDF API only supports printing via PrintDocument and setting the printer name to the name of the installed Nova printer??

public static void PrintDocument(FlowDocument doc, string description)
{
if (doc == null)
throw new ArgumentNullException("doc");

// Create a copy of the FlowDocument before printing or original may be modified and crashes may occur (MO:23017)
string xaml = System.Windows.Markup.XamlWriter.Save(doc);
var flowDocumentCopy = System.Windows.Markup.XamlReader.Parse(xaml) as FlowDocument;
if (flowDocumentCopy == null)
throw new ArgumentException("Failed to create copy of FlowDocument.", "doc");

IDocumentPaginatorSource dps = flowDocumentCopy;

if (!dps.DocumentPaginator.IsPageCountValid)
dps.DocumentPaginator.ComputePageCount();
int pageCount = dps.DocumentPaginator.PageCount;

var pd = new PrintDialog
{
MaxPage = (uint) pageCount,
UserPageRangeEnabled = true,
PageRange = new PageRange(1, pageCount)
};

if (!pd.ShowDialog().GetValueOrDefault())
return;
// PrintDialog does not have logic to process selected PageRange, we have to do it ourselves.
DocumentPaginator paginator = pd.PageRangeSelection == PageRangeSelection.UserPages
? new PageRangeDocumentPaginator(dps.DocumentPaginator, pd.PageRange)
: dps.DocumentPaginator;


pd.PrintDocument(paginator, description);
}

Post Reply