Create PDF from Template
11,263
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();
}
}
Author by
Weedalf
Updated on June 04, 2022Comments
-
Weedalf almost 2 years
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?
-
ProgrammingLlama over 5 yearsI've removed your request for libraries since that's off-topic.
-
anhtv13 over 5 yearstry itextsharp to generate pdf from html template
-
Jongware over 5 years@John: and so it's now a request for a full tutorial, which is similarly off-topic -- in the same sentence, no less: "4. Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic ..."
-
ProgrammingLlama over 5 years@usr2564301 That's true.
-
Weedalf over 5 yearsi dont want a tutorial. just an idea -.-
-
Ryan over 5 yearsWhy do you need to create a PDF? Why not just use HTML forms, or something else?
-
-
Steffen Bauer about 3 yearsHow can you deal with page related things like page breaks with an approach like this?
-
Tommix about 3 yearsSorry dont know, in my experience better to write pdf in code not from html. Like other answer - choosen that path. Static template but at least im in control of every aspect. This example which i provided have it's shortcomings, like page breaks. So i guess this answer is good until you have 1 page.