// Prepare HTML code var code = @"<style> div { page-break-after: always; } </style> <div style='border: 1px solid red; width: 300px'>First Page</div> <div style='border: 1px solid red; width: 500px'>Second Page</div>"; // Initialize an HTML document from the HTML code using var document = new HTMLDocument(code, "."); // Create the instance of Rendering Options and set a custom page-size var options = new PdfRenderingOptions(); options.PageSetup.AnyPage = new Page(new Size(400, 200)); // Enable auto-adjusting for the page size options.PageSetup.AdjustToWidestPage = true; // Prepare a path to save the converted file string savePath = Path.Combine(OutputDir, "output-widest-page-size.pdf"); // Create the PdfDevice and specify options and output file using var device = new PdfDevice(options, savePath); // Render HTML to PDF document.RenderTo(device);