PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 5:48 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: Sat Mar 11, 2017 1:00 pm 
Offline

Joined: Tue Aug 09, 2016 7:34 am
Posts: 6
Greetings,

I've managed to use PDF Sharp on OS X with a custom font resolver – https://gist.github.com/haf/ef50a926eb7 ... 7a7c10c3c6 (MIT license), (you're welcome!).

Now, with this dep, I'm trying to make my PDF display all UTF-8 characters:

Code:
    PDFsharp-MigraDoc (1.50.4000-beta3b)


I can directly tell you that http://www.pdfsharp.net/wiki/Unicode-sample.ashx isn't applicable, because I'm both 1) using a template PDF, 2) using MigraDoc.

This is the code with which I load the template:

Code:
let createFromTemplate (template : PdfDocument) =
  let d = new PdfDocument()
  let page = d.AddPage(template.Pages.[0])
  let graphics = XGraphics.FromPdfPage page
  d, page, graphics


Here's the code that generates the PDF;

Code:
let createInvoice (template : PdfDocument) (invoice : Invoice) : PdfDocument =
  let doc, page, graphics = createFromTemplate template
  let mdoc = new Document()
  let sec = mdoc.AddSection()
  addLinesTable sec invoice
  // snip - more content generation into MigraDoc.Document

  let drenderer = new DocumentRenderer(mdoc)
  drenderer.PrepareDocument()
  for i in 0 .. drenderer.FormattedDocument.PageCount - 1 do
    drenderer.RenderPage(graphics, i + 1)

  doc


It gives output...

Code:
let qvitooCust : BuyerParty =
  { name = "Utmärkta Övningar AB"
    address =
      { lines =
        [ "Åsögatan 10B"
          "411 19 Göteborg"
          "SWEDEN"
        ]
      }
    refPerson = "Åsa Höglund"
  }


Attachment:
File comment: Output sample
Screen Shot 2017-03-11 at 13.56.46.png
Screen Shot 2017-03-11 at 13.56.46.png [ 156.45 KiB | Viewed 3855 times ]


I've also tried to follow http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx (and hours worth of googling PDFSharp + Unicode) which ends up looking like this:

Code:
let createFromTemplate (template : PdfDocument) =
  let d = new PdfDocument()
  let page = d.AddPage(template.Pages.[0])
  let graphics = XGraphics.FromPdfPage page
  graphics.MUH <- PdfFontEncoding.Unicode
  d, page, graphics

let createInvoice (template : PdfDocument) (invoice : Invoice) : PdfDocument =
  let doc, page, graphics = createFromTemplate template
  let mdoc = new Document()
  let sec = mdoc.AddSection()
  // snip
  let pdfrenderer = new PdfDocumentRenderer((* utf8 *) true)
  pdfrenderer.Document <- mdoc
  pdfrenderer.RenderDocument()
  let drenderer = new DocumentRenderer(mdoc)
  drenderer.PrepareDocument()
  for i in 0 .. drenderer.FormattedDocument.PageCount - 1 do
    drenderer.RenderPage(graphics, i + 1)
  doc


Which gives this output:

Attachment:
File comment: Output with Unicode flag in PdfDocumentRenderer c'tor
Screen Shot 2017-03-11 at 14.15.24.png
Screen Shot 2017-03-11 at 14.15.24.png [ 46.66 KiB | Viewed 3853 times ]


Btw, that sample is outdated; the c'tor with character embedding is gone (deprecated https://github.com/empira/MigraDoc/blob ... rer.cs#L68)

I have verified that the font I'm importing supports other-than-ASCII chars.

Help would be much appreciated.


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 11, 2017 1:31 pm 
Offline

Joined: Tue Aug 09, 2016 7:34 am
Posts: 6
May be related to https://github.com/fsharp/fsharp/issues ... -277175716


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 11, 2017 2:46 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
Those characters work under Windows, so I assume this problem is related to the OSX implementation of .NET or whatever.

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


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: Bing [Bot], Google [Bot] and 127 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