How to Render HTML Zip File to PDF

Some projects use ZIP packages for more efficient storage and transfer. If a user wants to render an HTML file contained within a ZIP, there's no need to manually extract its contents. With IronPDF, you can render the entire project including all assets directly from the ZIP file. In this article, we’ll demonstrate how to convert an HTML ZIP package into a PDF with ease.

Get started with IronPDF

!!!--LIBRARY_DOWNLOAD_BLOCK--!!!



Convert HTML ZIP File to PDF Example

Below is an example of utilizing the RenderZipFileAsPdf method to convert the HTML ZIP file into a PDF. The RenderZipFileAsPdf method takes in two parameters: the path to the ZIP file and the HTML file name within the ZIP file.

After converting it, we then save the PDF as output.pdf.

Input File

This is the htmlSample.html HTML file that the code renders:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Sample HTML with External CSS and JS</title>
  <!-- Link to External CSS -->
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <div class="container">
    <h1>Welcome to the Sample Page!</h1>
    <p id="greeting">Click the button to change the background color and greeting text.</p>
    <button id="changeButton">Change Background</button>
  </div>

  <!-- Link to External JavaScript -->
  <script src="script.js"></script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Sample HTML with External CSS and JS</title>
  <!-- Link to External CSS -->
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <div class="container">
    <h1>Welcome to the Sample Page!</h1>
    <p id="greeting">Click the button to change the background color and greeting text.</p>
    <button id="changeButton">Change Background</button>
  </div>

  <!-- Link to External JavaScript -->
  <script src="script.js"></script>
</body>
</html>
HTML

Here's a quick preview on how it looks on a Chromium browser.

Code Example

:path=/static-assets/pdf/content-code-examples/how-to/html-zip-file-to-pdf.cs
ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderZipFileAsPdf("htmlSample.zip", @"htmlSample.html");

pdf.SaveAs("output.pdf");
Dim renderer As New ChromePdfRenderer()

Dim pdf As PdfDocument = renderer.RenderZipFileAsPdf("htmlSample.zip", "htmlSample.html")

pdf.SaveAs("output.pdf")
$vbLabelText   $csharpLabel

Result

This is the final output from the code above.

Regan related to Result
Software Engineer
Regan graduated from the University of Reading, with a BA in Electronic Engineering. Before joining Iron Software, his previous job roles had him laser-focused on single tasks; and what he most enjoys at Iron Software is the spectrum of work he gets to undertake, whether it’s adding value to sales, technical support, product development or marketing. He enjoys understanding the way developers are using the Iron Software library, and using that knowledge to continually improve documentation and develop the products.