Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create PDF from Template

I need to create a PDF File with c#. It have to be that I need a template (eg. Editable PDF or HTML Template). In this template I have to insert text and Picutures.

I have no ideas how to do this. Could someone say me a technique I could use do this?

like image 801
Weedalf Avatar asked Feb 15 '26 04:02

Weedalf


1 Answers

You can use PdfSharp plugin via NuGet. Just create html template file, read it as string, replace what you need, and pass full html to function bellow.

using TheArtOfDev.HtmlRenderer.PdfSharp;

    public static bool PdfSharpConvert(String html, string SaveTo)
    {
        try
        {
            using (var pdf = PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4))
            {
                pdf.Save(SaveTo);
            }

            return true;
        }
        catch (Exception er)
        {
            return false;
        }
        finally
        {
            GC.Collect();
        }
    }
like image 120
Tommix Avatar answered Feb 17 '26 18:02

Tommix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!