{"id":26534826,"url":"https://github.com/iron-software/c-sharp-html-to-pdf-tutorial","last_synced_at":"2025-07-04T17:33:41.936Z","repository":{"id":76754675,"uuid":"149709022","full_name":"iron-software/c-sharp-html-to-pdf-tutorial","owner":"iron-software","description":"Source code tutorial showing basic and advanced HTML to PDF creation in C# using IronPDF.    https://ironpdf.com/tutorials/html-to-pdf/","archived":false,"fork":false,"pushed_at":"2025-02-28T08:38:05.000Z","size":17,"stargazers_count":10,"open_issues_count":1,"forks_count":8,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-28T15:26:17.204Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iron-software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-21T04:16:57.000Z","updated_at":"2025-02-28T08:38:09.000Z","dependencies_parsed_at":"2023-03-15T06:45:24.097Z","dependency_job_id":null,"html_url":"https://github.com/iron-software/c-sharp-html-to-pdf-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iron-software%2Fc-sharp-html-to-pdf-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iron-software%2Fc-sharp-html-to-pdf-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iron-software%2Fc-sharp-html-to-pdf-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iron-software%2Fc-sharp-html-to-pdf-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iron-software","download_url":"https://codeload.github.com/iron-software/c-sharp-html-to-pdf-tutorial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244864016,"owners_count":20523079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-21T20:28:43.427Z","updated_at":"2025-03-21T20:28:43.991Z","avatar_url":"https://github.com/iron-software.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Why Choose IronPDF for HTML to PDF Conversion in C\u0026num;?\n\nWhen it comes to HTML to PDF conversion in C# .NET, developers need a solution that is fast, reliable, and easy to plug into their applications. Towards this end, [IronPDF](https://ironpdf.com/) stands out as one of the best libraries that .NET developers can use.\n\nHere are ten reasons why you should consider using IronPDF as your go-to for your next project.\n\n## 1. Pixel-Perfect Rendering\n\nIronPDF uses a **headless Chromium engine** to ensure that PDFs **look exactly like the original web page**. This means:\n\n- **No missing document formatting**: IronPDF preserves all layout changes applied by CSS styles, fonts, and JavaScript.  \n- **Create PDFs with complex layouts with confidence**: IronPDF supports all HTML5 elements, CSS3 styles, and ES6 syntax reliably.  \n- **High Fidelity Rendering** : If you can build it in a web page, then you can show it as a PDF!\n\nNeed a PDF to match a webpage's appearance **exactly**? IronPDF does it with ease.\n\n## 2. Simple, Developer-Friendly API\n\nIronPDF's user-friendly API makes HTML to PDF conversion child's play.\n\nHere's how you can Convert HTML to PDF in two lines of code:\n\n```csharp\nusing IronPdf;\nvar pdf = new ChromePdfRenderer().RenderHtmlAsPdf(\"\u003ch1\u003eHello, IronPDF!\u003c/h1\u003e\");\npdf.SaveAs(\"output.pdf\");\n```\n\n### Advanced Example: Conversion with HTML assets\n\n```csharp\nusing IronPdf;\n\nvar Renderer = new IronPdf.ChromePdfRenderer();\n\n// Load external html assets: Images, CSS and JavaScript.\n// An optional BasePath 'C:\\site\\assets\\' is set as the file location to load assets from \nvar myAdvancedPdf = Renderer.RenderHtmlAsPdf(\"\u003cimg src='icons/iron.png'\u003e\", @\"C:\\site\\assets\\\");\n\nmyAdvancedPdf.SaveAs(\"html-with-assets.pdf\");\n```\n\n## 3. Supports Multiple HTML Input Sources\n\nIronPDF gives you flexibility in how you can approach HTML-to-PDF conversion. Choose between converting from any of these **HTML sources** into PDFs:\n\n- Raw HTML strings\n- Local HTML files  \n- Live web pages (URLs)  \n\n### Example: Convert a Live Web Page to PDF\n\n```csharp\nvar pdf = new ChromePdfRenderer().RenderUrlAsPdf(\"https://example.com\");\npdf.SaveAs(\"webpage.pdf\");\n```\n\n### Example: Convert a Local HTML file to PDF\n\n```csharp\nvar pdf = new ChromePdfRenderer().RenderHtmlFileAsPdf(\"example.html\");\npdf.SaveAs(\"webpage.pdf\");\n```\n\n## 4. Even More File Conversion Options\n\nNeed to convert other file types into PDFs? IronPDF can that as well!\n\n### Example: Convert Images to PDFs\n\n```csharp\nvar imageFiles = Directory.EnumerateFiles(\"assets\").Where(f =\u003e f.EndsWith(\".jpg\") || f.EndsWith(\".jpeg\"));\nImageToPdfConverter.ImageToPdf(imageFiles).SaveAs(\"composite.pdf\");\n```\n\n### Example: Convert DOCX to PDF\n\n```csharp\nPdfDocument pdf = new DocxToPdfRenderer().RenderDocxAsPdf(\"example.docx\");\npdf.SaveAs(\"output.pdf\");\n```\n\n### Example: RTF to PDF\n\n```csharp\nPdfDocument pdfFromRtfFile = new ChromePdfRenderer().RenderRtfFileAsPdf(\"example.rtf\");\npdfFromRtfFile.SaveAs(\"output.pdf\");\n```\n\n### Example: Convert Markdown to PDF\n\n```csharp\nPdfDocument pdfFromFile = new ChromePdfRenderer().RenderMarkdownFileAsPdf(\"report.md\");\npdfFromFile.SaveAs(\"output.pdf\");\n```\n\n### Example: Convert TIFF to PDF\n\n```csharp\nvar pdf = ImageToPdfConverter.ImageToPdf(\"example.tif\");\npdf.SaveAs(\"output.pdf\");\n```\n\nTake your document management to the next level with IronPDF by converting from multiple document types to PDF!\n\n## 5. Advanced Customization \u0026 Styling Options\n\nIronPDF allows you to **control every aspect of the rendered PDF**, including:\n\n- **Custom margins, page sizes, headers, and footers**  \n- **Watermarks, page numbers, and digital signatures**  \n- **JavaScript execution before rendering for dynamic content**  \n\n### Example: Add a Custom Header \u0026 Footer\n\n```csharp\nvar Renderer = new ChromePdfRenderer();\nvar pdf = Renderer.RenderHtmlAsPdf(\"\u003ch1\u003eIronPDF Customization\u003c/h1\u003e\");\n\npdf.AddTextFooter(\"Generated using IronPDF\", 10);\npdf.SaveAs(\"custom-footer.pdf\");\n```\n\n## 6. High Performance \u0026 Scalability\n\nIronPDF is **optimized for speed** and works seamlessly in **multi-threaded environments**.\n\nWhether you’re generating a **single PDF** or processing **thousands per hour**, IronPDF ensures:\n\n- Fast rendering speeds  \n- Low memory consumption\n- Asynchronous PDF generation for better performance\n\n### Example: Async PDF Generation for Performance\n\n```csharp\nvar pdfTask = new ChromePdfRenderer().RenderHtmlAsPdfAsync(\"\u003ch1\u003eAsync IronPDF\u003c/h1\u003e\");\nawait pdfTask;\npdfTask.Result.SaveAs(\"async-output.pdf\");\n```\n\n## 7. Secure \u0026 Compliant\n\nFor enterprise applications that require **security and compliance**, IronPDF offers:\n\n- Password protection \u0026 encryption  \n- Digital signatures for authentication\n- Compliance with PDF/A \u0026 PDF/UA standards\n\n### Example: Generate a Password-Protected PDF\n\n```csharp\nvar pdf = new ChromePdfRenderer().RenderHtmlAsPdf(\"\u003ch1\u003eSecure PDF\u003c/h1\u003e\");\npdf.Security.Encrypt(\"userpass\", \"ownerpass\", IronPdf.Security.Permissions.CanPrint);\npdf.SaveAs(\"secure.pdf\");\n```\n\n## 8. Works Across All .NET Versions \u0026 Platforms\n\nIronPDF is compatible with:\n\n- .NET 9, 8, 7, 6, 5, Core, and Framework\n- Web, Desktop, Console, and Cloud applications\n- Windows, Linux, macOS, and Docker\n\n## 9. Active Support \u0026 Regular Updates\n\nIronPDF offers:\n\n- 24/5 developer supports\n- Frequent updates and new features\n- Reliable documentation and a large community of developers\n\nNeed help? IronPDF’s support team is available via [email](mailto:support@ironsoftware.com) and [documentation](https://ironpdf.com/documentation/).\n\n## 10. More Affordable Than Competitors\n\nIronPDF provides **better value for money**, then most well-known, premium library alternatives.\n\nCompared to **Aspose, Syncfusion, and PdfTron**, IronPDF has:\n\n- No complex licensing or hidden fees  \n- Lifetime license options  \n- Flexible pricing for individual developers and enterprises\n\n## Conclusion\n\nIf you're looking for a powerful, flexible, and easy-to-use HTML to PDF solution for your .NET application, IronPDF is an attractive library to consider.\n\nUse IronPDF to enjoy:\n\n- High-fidelity rendering\n- Rich customization options\n- Enterprise-grade security\n\n**Start using IronPDF today!** Install via NuGet:  \n\n```shell\nInstall-Package IronPdf\n```\n\n**Get a free trial at [IronPDF.com](https://ironpdf.com/#trial-license)**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firon-software%2Fc-sharp-html-to-pdf-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Firon-software%2Fc-sharp-html-to-pdf-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firon-software%2Fc-sharp-html-to-pdf-tutorial/lists"}