Giter Club home page Giter Club logo

htmltoqpdf's Introduction

HTMLToQPDF is an extension for QuestPDF that allows to generate PDF from HTML

QuestPDF currently does not support inserting html into a pdf document. So I wrote a small library for this. It doesn't support the full functionality of html and css, but I think it should be enough for most cases.

Dependencies

Usage

The simplest example of use:

Document.Create(container =>
{
    container.Page(page =>
    {
        page.HTML(handler =>
        {
            handler.SetHtml(html);
        });
    });
}).GeneratePdf(path);

I strongly recommend overloading the image upload method, because the outdated WebClient is used by default without using asynchronous. To do this, you can use the OverloadImgReceivingFunc:

page.HTML(handler =>
{
    handler.OverloadImgReceivingFunc(GetImgBySrc);
    handler.SetHtml(html);
});

You can customize the styles of text and containers for tags:

handler.SetTextStyleForHtmlElement("div", TextStyle.Default.FontColor(Colors.Grey.Medium));
handler.SetTextStyleForHtmlElement("h1", TextStyle.Default.FontColor(Colors.DeepOrange.Accent4).FontSize(32).Bold());
handler.SetContainerStyleForHtmlElement("table", c => c.Background(Colors.Pink.Lighten5));
handler.SetContainerStyleForHtmlElement("ul", c => c.PaddingVertical(10));

You can set the vertical padding size for lists. This padding will not apply to sub-lists:

handler.SetListVerticalPadding(40);

You can use HTMLToQPDF.Example to try out the capabilities of this extension.

Default Styles Options for changing styles

htmltoqpdf's People

Contributors

lqwitel avatar relorer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.