.NET Standard 2.0 library to use the PdfTurtle service
HINT: This lib is in the beta.
See a working example in PdfTurtleClientDotnet.WebApiExample/Program.cs.
Get the package from nuget.
dotnet add package PdfTurtleClientDotnet
// register service
services.AddPdfTurtle("https://pdfturtle.gaitzsch.dev");
// resolve service over dependency injection
app.MapGet("/", (IPdfTurtleClient pdfTurtleClient) => { ... });
Go to 🐢PdfTurtle-Playground, put an example model as JSON and design your PDF. Download the bundle as ZIP file and put it in your resources/assets.
Call RenderBundleAsync
to render the pdf to a Stream
.
var pdfStream = await pdfTurtleClient.RenderBundleAsync(BUNDLE_AS_STREAM_OR_BYTES, MODEL_AS_OBJECT);
Done.
If you want to have the same header for all documents, you can create a ZIP file with with only the header.html
file.
Now you can call the Service with multiple bundle files. The service will assemble the files together.
var pdfStream = await pdfTurtleClient.RenderBundleAsync(
new [] { BUNDLE_WITHOUT_HEADER_AS_STREAM_OR_BYTES, HEADER_BUNDLE_AS_STREAM_OR_BYTES },
MODEL_AS_OBJECT
);
If the described way does not match your expectations, you can use a template engine of your choice (for example RazorLight) and render HTML directly with PdfTurtle.
var pdfStream = await pdfTurtleClient.RenderAsync(new RenderData() {
...
});
If you want to render a HTML template without any images or assets, you can use the RenderTemplateAsync
function.
var pdfStream = await pdfTurtleClient.RenderTemplateAsync(new RenderTemplateData() {
...
});
- Working examples for all methods
- Add documentation as comments
- Tests