Skip to footer content

How to Use Base URLs in PDF Generation with C#

In this tutorial, we explore the process of using base URLs and asset coding with IronPDF in C#. The session begins with ensuring you have the IronPDF library installed via the NuGet Package Manager. Once setup, we import IronPDF in the Program.cs file and set the license key. A Chrome PDF renderer is instantiated to handle PDF rendering. We define a base URL for assets, crucial for resolving image paths in HTML. An HTML string containing an image is created and rendered to a PDF using the render-to-HTML-as-PDF method, with the base URL specified. The file is then saved. We also cover adding HTML headers with images, setting header options, and applying custom CSS for styling. The tutorial then delves into image encoding by importing an image file's binary data, converting it to a base64 string, and embedding it directly into HTML for PDF rendering. The final PDFs are pixel-perfect, maintaining the HTML structure and style. By the end of this tutorial, you will have mastered using base URLs and asset coding in IronPDF, enabling you to produce high-quality PDFs. Don't forget to like and subscribe for more tutorials.

Further Reading: How to Use Base URLs & Asset Encoding

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.