TPPDF
TPPDF copied to clipboard
Attributed text from markdown is rendered as regular text
What did you do?
I created a PDF and added an attributed text generated from a markdown string. However, the text is rendered to the PDF document as plain text, without any attribution. Here is the code for reference:
init() {
let document = TPPDF.PDFDocument(format: .usLetter)
let markdownString = try? NSAttributedString(markdown: "This is a *simple* **test**")
let textElementObject = PDFAttributedText(text: markdownString!)
document.add(attributedTextObject: textElementObject)
let generator = PDFGenerator(document: document)
let url = try? generator.generateURL(filename: "Example.pdf")
}
Just for completeness, I also tried the following:
let markdownString = try? NSAttributedString(markdown: "This is a *simple* **test**")
document.add(attributedText: markdownString)
What did you expect to happen?
I expected the text to be rendered like this:
This is a sample test
I.e., I was expecting that the string would be rendered considering the markdown syntax (italic and bold).
What happened instead?
The text was rendered like this:
This is a sample test
So the text was rendered without any attributes. Please check the attached PDF for the result.
It is worth noting, however, that the * are not rendered. So it seems that the markdown syntax is parsed correctly, but the attributes are simply ignored.
TPPDF Environment
TPPDF version: 2.6.0 Xcode version: 15.4 Swift version: 5
Demo Code / Project
You can download an XCode project (macOS App) from my repo The relevant code is here
And here is the generated PDF: Example.pdf