Giter Site home page Giter Site logo

iron-software / iron-pdf-example-hello-world-csharp Goto Github PK

View Code? Open in Web Editor NEW
18.0 5.0 8.0 1.09 MB

Get started creating PDF documents in C# using IronPDF

Home Page: https://ironpdf.com/tutorials/html-to-pdf/

C# 100.00%
html-to-pdf html5 ironpdf pdf pdf-generation url-to-pdf

iron-pdf-example-hello-world-csharp's Introduction

IronPDF "Hello World" Example in C#

IronPDF Features and Compatiblity

IronPDF easily handles all these features:

  • Generating PDFs from: HTML, URL, JavaScript, CSS and many image formats
  • Adding headers/footers, signatures, attachments, compression, and passwords and security
  • Performance optimization: Full Multihreading and Async support
  • And many more! Visit our website to see all our code examples and a full list of our 50+ features

IronPDF also has cross platform support compatibility with:

  • .NET 7 and .NET 6, .NET Core, Standard, and Framework (4.6.2+)
  • Windows, macOS, Linux, Docker, Azure, and AWS

Code Example

using IronPdf;
using IronPdf.Engines.Chrome;
using IronPdf.Rendering;
 
// Example of HTML string to be rendered into a PDF
private const string SampleHtmlString = "<h1>Hello World!</h1><br><p>This is IronPdf.</p>";

static void Main(string[] args)
{
    // Get a free license key instantly: https://ironpdf.com/#trial-license
    IronPdf.License.LicenseKey = "ENTER-KEY-HERE";
    
    Console.WriteLine("Welcome to the IronPDF `Hello World' Tutorial!");
    
    // Example of an HTML String to PDF
    HtmlToPdfExample(SampleHtmlString);
    
    // Example of URL to PDF
    UrlToPdfExample("https://getbootstrap.com/");
    
    Console.WriteLine("IronPDF Tutorial Complete! Press any key to exit!");
    Console.ReadKey();
}

public static void HtmlToPdfExample(string htmlString)
{
    // Start by initializing the Chrome Renderer
    ChromePdfRenderer renderer = new ChromePdfRenderer();

    // Render a new PdfDocument using an HTML string
    PdfDocument newPdf = renderer.RenderHtmlAsPdf(SampleHtmlString);
    
    // Save new PDF File
    newPdf.SaveAs("pdf_from_html.pdf");
}

public static void UrlToPdfExample(string url)
{
    // Start by initializing the Chrome Renderer
    ChromePdfRenderer renderer = new ChromePdfRenderer();

    // Set Pdf CssMediaType to Screen to get all the background
    renderer.RenderingOptions = new ChromePdfRenderOptions()
    {
        // Screen vs Print: https://ironpdf.com/how-to/pixel-perfect-html-to-pdf/#1-decide-to-use-css-media-type-print-or-screen
        CssMediaType = PdfCssMediaType.Screen,
        PrintHtmlBackgrounds = true,
        
        // Set Margins
        MarginTop = 10,
        MarginBottom = 10,
        MarginLeft = 10,
        MarginRight = 10
    };
    
    // Render a new PdfDocument from a URL
    PdfDocument newPdf = renderer.RenderUrlAsPdf(url);
    
    // Save new PDF File
    newPdf.SaveAs("pdf_from_url.pdf");
}

Get Started creating PDF documents with IronPDF in C# now! https://github.com/iron-software

iron-pdf-example-hello-world-csharp's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

iron-pdf-example-hello-world-csharp's Issues

Page break issue

I am applying page break styles to table but these are not applying in creating pdf.

After upgrade to V 2020.8.1 and 9.0 the deployment (Azure web app) will taking more than 25 min

After upgrade IronPDF version 2020.8.1 or 2020.9.0, the Azure web app ( ASP.NET MVC 5) deployment takes more than 25 minutes and sometimes failed.

For confirming this, we downgraded the IronPDF version to 2020.6.0 and deployed the same to the Azure web app and it will only be taken 1 min and 45 sec.

After publishing the web app with IronPDF version 2020.8.1 or 2020.9.0, the Azure portal showing extremely high CPU usage (100%) within the Azure App Service.

After downgrade to 2020.6.0, The CPU usage has stabilized at around 10-30% in Azure App Service.

2020-09-15_20-26-26

2020-09-15_20-29-44

Please advice.

Unity-Version 2018.3.14f crashes when using the net40 version of iron pdf

Hello IronPDF-Crew,

I want to use the IronPDF Plugin in Unity, specifically in a UWP build, but using the following code Unity just crashes.

        HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
        PdfDocument PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");
        string OutputPath = "HtmlToPDF.pdf";
        PDF.SaveAs(Path.Combine(Application.persistentDataPath, OutputPath));

Is there a known solution on this?

Embedded Browser

This is not of an issue but a question: I read somewhere that IronPDF has an embedded browser in it. Can I show that browser in my WPF application?

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.