Giter Site home page Giter Site logo

lucas-gaitzsch / pdf-turtle-client-dotnet Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 110 KB

Dotnet / C# Client for PdfTurtle

License: MIT License

C# 95.97% HTML 4.03%
client-library dotnet dotnet-core dotnet-standard2 html-to-pdf pdf pdf-generation pdf-lib pdf-library pdf-turtle

pdf-turtle-client-dotnet's Introduction

PdfTurtle Client .NET

.NET Standard 2.0 library to use the PdfTurtle service

Nuget

HINT: This lib is in the beta.

How to use - Recommended way for ASP.NET Core and bundles

See a working example in PdfTurtleClientDotnet.WebApiExample/Program.cs.

1. Prepare project

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) => { ... });

2. Design your PDF in the playground

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.

3. Call the service with the client and your data

Call RenderBundleAsync to render the pdf to a Stream.

var pdfStream = await pdfTurtleClient.RenderBundleAsync(BUNDLE_AS_STREAM_OR_BYTES, MODEL_AS_OBJECT);

Done.

Hint: You can split your bundle

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
    );

How to use - Alternative ways

Without template (plain HTML)

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() {
    ...
});

With template but no bundle

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() {
    ...
});

Open TODOs

  • Working examples for all methods
  • Add documentation as comments
  • Tests

pdf-turtle-client-dotnet's People

Contributors

lucas-gaitzsch avatar

Stargazers

 avatar  avatar

Watchers

 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.