PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Dec 07, 2021 6:07 pm

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Nov 23, 2017 1:43 am 

Joined: Wed Nov 22, 2017 8:09 pm
Posts: 2
I am new to MigraDoc so I started by experimenting with the WPF samples.
MigraDoc libraries are 1.50b4 and WPF samples are from 1.32.

I began with HelloWorld and successfully added a table and footer. Both PDF and RTF look fine.

Then I changed the font and added some document info data:

/// <summary>
/// Creates an absolutely minimalistic document.
/// </summary>
static Document CreateDocument()
// Create a new MigraDoc document
Document document = new Document();

Style style = document.Styles["Normal"];
style.Font.Name = "Segoe UI Semibold";

document.Info.Author = "Author";
document.Info.Title = "New Report";

The font change works, and info fields show up correctly in PDF, but as odd characters when viewing document properties of the RTF with Word 2016.

Inspection of the RTF file itself shows:
- a font table with first 2 entries "Symbol" and "Wingdings" (plus Courier New and Segoe UI Semibold)
- no font specifier for info group:

{\info{\title New Report}{\author Author}}

If I edit the RTF source directly to add a font specifier, then view in Word, the fields appear as expected:

{\f2\info{\title New Report}{\author Author}}

What should I have added to my C# source to force the font of the document info fields?

Reply with quote  
PostPosted: Thu Nov 23, 2017 2:02 pm 
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3049
Location: Cologne, Germany

That's a mighty old bug you found. Thanks for the feedback.

Get the source code for PDFsharp/MigraDoc, open the file RtfDocumentRenderer.cs and locate method "RenderInfo()".

Insert one new line of code:
_rtfWriter.WriteControl("f", 2); // This line is new.

Change will be included with the next NuGet packages (and no, there is no ETA for that).

I don't know if there is a way to work around that issue without changing MigraDoc - besides the hacky method of saving to a stream and inserting "\f2" before writing to a file.

Thomas Hoevel
PDFsharp Team

Reply with quote  
PostPosted: Thu Nov 23, 2017 8:22 pm 

Joined: Wed Nov 22, 2017 8:09 pm
Posts: 2
Hello & thank you for the very quick reply.

I appreciate the explicit instructions for fixing the source. That will be no problem here.

It is our Thanksgiving holiday here, and very appropriate to say thanks especially since this was the only thing holding up my work. You probably know how it is when you receive a high priority requirements change, 1 week before the due date of a 5 month project, and just before a national holiday. That's when I learned that my app would need to produce PDF & RTF output also. Due to the 1.32 samples & reviewing discussions in this forum, I was able to add those new capabilities in just 2 days, even though I'd never even heard of Migradoc/PDFsharp before.

Thanks & Best Regards!

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

All times are UTC

Who is online

Users browsing this forum: No registered users and 3 guests

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