PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon May 06, 2024 7:52 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Fri May 15, 2009 3:36 pm 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi,

I am creating a table and adding a paragraph object to each cell, then adding text to the paragraph objects, but I noticed that there is a property:
Code:
paragraph.Format.Font.Name = "Arial Unicode MS";

I can embed any ttf font in PDFSharp as i have already experimented with this as the project i am working on will require unicode language support. I have it working for PDFSharp, but i cant seem to find out how to do it for tables in MigraDoc?

If there is no way of embedding ttf fonts for use in MigraDoc objects, is there a workaround to create the table in MigraDoc, then add the text with PDFSharp BUT keep the word wrapping functionality of the MigraDoc paragraph object?

Thanks!

Mike


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 18, 2009 8:19 am 
Offline
PDFsharp Guru
User avatar

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

MigraDoc uses PDFsharp.

Font embedding works with MigraDoc, too.
No workaround needed.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 18, 2009 8:23 am 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
so can i just create the embedded fotn object in PDFSHarp like this:
Code:
// Load in font
string fontFileName = @"C:\Users\sowemi\Desktop\ARIALUNI.TTF";
XPrivateFontCollection privateFonts = new XPrivateFontCollection();
byte[] fontData = File.ReadAllBytes(fontFileName);
privateFonts.AddMemoryFont(fontData, fontData.Length, "Arial Unicode MS", false, false);
XPrivateFont pfont = privateFonts.FindFont("Arial Unicode MS", false, false);
 XPdfFontOptions fontOptions = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
XFont xFont = new XFont(family, 18, XFontStyle.Regular, fontOptions, privateFonts);

And then use it in a MigraDoc table's cell like this:
Code:
paragraph.Format.Font.Name = "Arial Unicode MS";


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 18, 2009 8:35 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
Yes, but don't forget to pass the private font collection to the Renderer:
Code:
DocumentRenderer renderer = new DocumentRenderer(document);
renderer.PrivateFonts = this.PrivateFontCollection;

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 18, 2009 9:03 am 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
I am now passing my privateFonts variable to renderer.PrivateFonts like this:
Code:
DocumentRenderer renderer = new DocumentRenderer(document);
renderer.PrivateFonts = privateFonts;
renderer.PrepareDocument();
renderer.RenderPage(gfx,1);


and I am creating the privateFonts object further up in my code like this:
Code:
XPrivateFontCollection privateFonts = new XPrivateFontCollection();
byte[] fontData = File.ReadAllBytes(fontFileName);
privateFonts.AddMemoryFont(fontData, fontData.Length, "Arial Unicode MS", false, false);


But when i put a unicode character into my table, it wont embed!

I looked at the fonts tab in the pdf's properties and its saying im using Arial Unicode MS, but its not embedded and its using Ansi encoding. Dont I have to create a MigraDoc.DocumentObjectModel.Font object and tell it to "always embed fonts" and "use unicode encoding" like I do with the PDFSharp XFont object?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 18, 2009 9:21 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
You specify this when creating the PdfDocumentRenderer.

Rendering to PDF goes like this:
Code:
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
renderer.Document = document;

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 18, 2009 9:45 am 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
OK I am now using PdfDocumentRenderer rather than DocumentRender as before, but it just isnt creating my table in the PDF now?

i am using this:
Code:
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always);
renderer.Document = document;
renderer.RenderDocument();


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 72 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