PDFsharp & MigraDoc Foundation

Issue with document information fonts
Page 1 of 1

Author:  CSharpAppsForYou [ Thu Nov 23, 2017 1:43 am ]
Post subject:  Issue with document information fonts

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?

Author:  Thomas Hoevel [ Thu Nov 23, 2017 2:02 pm ]
Post subject:  Re: Issue with document information fonts


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.

Author:  CSharpAppsForYou [ Thu Nov 23, 2017 8:22 pm ]
Post subject:  Re: Issue with document information fonts

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!

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group