Giter Club home page Giter Club logo

pdflibrary's Introduction

How to easily create a PDF document in ASP NET MVC

PdfLibrary is an extremely simple way to convert an HTML response directly into a PDF document and print the PDF document into an ASP.NET MVC.

N|Solid

We will show how to use the PdfLibrary library to easily generate PDF documents while working on the .NET MVC Web project.

PdfLibrary is based on the wkhtmltopdf tool to create a PDF file from HTML content displayed in a browser. It uses the web kit engine used by Chrome to display the HTML code. And support most tags and HTML styles.

N|Solid

Configure this library on your project

Let's now create an example for how to easily create a PDF document in ASP.NET.NET MVC

Step 1 : Let's start from the beginning by creating a new ASP.NET MVC project called MVC_PDFGenerator Step 2 : Let's start by installing the PdfLibrary library:

Install-Package PdfLibrary

Or search for PdfLibrary in the Nuget package window

how it works?

for View a PDF document in a browser Step 1 : After adding the controller, we will now add an action to this controller and prepared you view page step 2: The solution is implemented with four classes of PdfLibrary in RapportPDFController.cs to generate a PDF / Image file.

ViewAsPdf - This class will generate the PDF based on the views.

          public ActionResult DownloadViewPDF ()
         {
             return new PdfLibrary.ViewAsPdf ("DemoAsPDF");
         }

ActionAsPdf - will use another method of action to generate a PDF file using the view

    public ActionResult DownloadActionAsPDF ()
         {
             return new PdfLibrary.ActionAsPdf ("DemoAsPDF") {FileName = "TestViewAsPdf.pdf"};
         }

ViewAsImage - This class will generate the Image based on the views.

       public ActionResult DownloadViewImage ()
         {
             return new PdfLibrary.ViewAsImage ("DemoAsPDF");
         }

ActionAsImage : will use another action method to generate an image file using the view

         public ActionResult DownloadActionAsImage ()
         {
             return new PdfLibrary.ActionAsImage ("DemoAsPDF") {FileName = "TestViewAsImage.png"};
             }

demo

you can download the source code in Github https://github.com/ahmedOumezzine/PdfLibrary/tree/master/html%20to%20pdf

pdflibrary's People

Contributors

ahmedoumezzine avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

James Cloos avatar  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.