Closed supersume closed 6 days ago
Hi @supersume
Markdown does not have a native way of configuring text alignment (For example, see https://stackoverflow.com/questions/14051715/markdown-native-text-alignment).
The most common workaround for this is using HTML + CSS.
QuestPDF.Markdown aims to convert pure markdown to PDF and not to become a HTML to PDF converter with all the issues that will bring.
Therefore, currently no syntax besides markdown is supported. Under the hood markdig is used, which does have some HTML support, but I have not looked into using it to support alignment styles. So unless someone is willing to create a PR with a PoC this will likely not be added.
Hi, @christiaanderidder! Thank you for your work on QuestPDF.Markdown!
Could we leverage QuestPDF’s existing capabilities for this? text.Justify() could be called if a flag is set in MarkdownRendererOptions.
Here’s a sample of how these changes could be applied:
--- a/src/QuestPDF.Markdown/MarkdownRenderer.cs
+++ b/src/QuestPDF.Markdown/MarkdownRenderer.cs
@@ -191,6 +191,10 @@ internal sealed class MarkdownRenderer : IComponent
{
pdf.Text(text =>
{
+ if (_options.JustifyText)
+ {
+ text.Justify();
+ }
// Process the block's inline elements
foreach (var item in block.Inline)
--- a/src/QuestPDF.Markdown/MarkdownRendererOptions.cs
+++ b/src/QuestPDF.Markdown/MarkdownRendererOptions.cs
@@ -41,6 +41,8 @@ public class MarkdownRendererOptions
public float ImageScalingFactor { get; set; } = 0.5f;
+ public bool JustifyText { get; set; }
+
public float ParagraphSpacing { get; set; } = 10;
public float ListItemSpacing { get; set; } = 5;
public string UnorderedListGlyph { get; set; } = "•";
@nemec784 I've done some experimenting with this and this can indeed be done, but it would set the alignment for every single piece of text in the document. I would expect that in most cases more finely grained control is needed, which cannot really be done without having some sort of markdown syntax to indicate alignment (and without introducing HTML into the mix).
@supersume would setting the text align for the entire document, without any additional control, be workable for your use case?
Yes. Setting alignment for the entire document is an acceptable solution
Version 1.24.0 should become available shortly and will include a global paragraph alignment setting.
@christiaanderidder, wow! Thanks a lot!
How can one render markdown text that is justified?