PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Mar 19, 2024 7:49 am

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 
Offline

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?


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

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3092
Location: Cologne, Germany
Hi!

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:
Code:
_rtfWriter.StartContent();
_rtfWriter.WriteControl("f", 2); // This line is new.
_rtfWriter.WriteControl("info");


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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

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!


Top
 Profile  
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 4 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