Relorer / HTMLToQPDF

HTMLToQPDF is an extension for QuestPDF that allows to generate PDF from HTML
MIT License
80 stars 26 forks source link

Block alignment [Feature] #10

Closed eagleusa closed 1 year ago

eagleusa commented 1 year ago

Would it be possible to add a feature of alignment of blocks such as

<p align="center">

or similar for other blocks and alignment? (Left, Right, Top, Middle, etc.) / (h1, h2, etc.)?

Also font attributes such as color, size, etc. ?

Thank you for all your work.

eagleusa commented 1 year ago

I was able to achieve this by modifying the ParagraphComponent within the Components folder. The modification was a quick and dirty one which will probably be refactored and cleaned up some later. However wanted to provide it here just in case anyone else is looking for this type of solution. In this component, the following code was added.

          else if (listItemNode.IsBlockNode())
            {
                var attributes = listItemNode.GetAttributes();
                foreach (var attribute in attributes)
                {
                    if (attribute.Name == "align")
                    {
                        if(attribute.Value.ToLower() == "left")
                        {
                            container = container.AlignLeft();
                        }
                        if (attribute.Value.ToLower() == "center")
                        {
                            container = container.AlignCenter();
                        }
                        if (attribute.Value.ToLower() == "right")
                        {
                            container = container.AlignRight();
                        }
                    }
                }

This is after the if statement checking whether it is a numbered list within the Compose method. Around line 45.