PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jul 21, 2024 4:28 pm

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue Sep 29, 2015 6:57 pm 
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 951
Location: CCAA
Earlier versions of MigraDoc up to version 1.32 included the class MigraDocPrintDocument that allows MigraDoc to print directly.
This class can also be used with MigraDoc 1.50 beta 2 and later (some names have changed, so it needs a bit renaming).

The current implementation of class MigraDocPrintDocument works with the GDI build of MigraDoc only and can only be used on platforms where GDI+ is available.
If you are using Windows Desktop and the GDI build, just copy the class file MigraDocPrintDocument.cs into your project and use it. At the end of this post is a link to a ZIP file that includes a MigraDocPrintDocument.cs that was adapted for version 1.50 and a sample that shows how to use it.

If you are using the WPF build of MigraDoc on a platform that supports GDI+, then you can also use MigraDocPrintDocument for printing. But you have to use a trick to make it work.
You have to create one assembly that contains the class MigraDocPrintDocument and that references the GDI build of MigraDoc. Your application can still use the WPF build of MigraDoc.
And now for the trick: you can invoke printing through a new class MigraDocPrintDocumentEx which internally calls class MigraDocPrintDocument. You have to pass your MigraDoc document to class MigraDocPrintDocumentEx as a string in the MDDDL format that MigraDoc uses to persist files. It takes only one line of code to convert from Document to MDDDL and the sample shows how to do it.

Further limitations of printing with MigraDocPrintDocument: Fonts from a FontResolver won't be used for printing.
If you want to use private fonts also for printing, then you currently have to use the GDI build of MigraDoc and register your fonts in the XPrivateFontCollection.

Here is a sample solution that shows MigraDocPrintDocument at work and also shows printing from an application that uses the WPF build of MigraDoc.
Download MigraDocPrintingDemo.zip.

Best regards
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group