PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Cannot make åäö print in PDF
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3553
Page 1 of 1

Author:  haf [ Sat Mar 11, 2017 1:00 pm ]
Post subject:  Cannot make åäö print in PDF

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 3898 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 3896 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.

Author:  haf [ Sat Mar 11, 2017 1:31 pm ]
Post subject:  Re: Cannot make åäö print in PDF

May be related to https://github.com/fsharp/fsharp/issues ... -277175716

Author:  TH-Soft [ Sat Mar 11, 2017 2:46 pm ]
Post subject:  Re: Cannot make åäö print in PDF

Those characters work under Windows, so I assume this problem is related to the OSX implementation of .NET or whatever.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/