1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
using IronPdf; using System; using System.Diagnostics; class Program { static void Main() { // Activate IronPDF license key (replace with your trial key if needed) IronPdf.License.LicenseKey = "IRONSUITE.NEHAJOSHI1982DOB.GMAIL.COM.20253-59C6B44943-AIT2TQE-IUNYAU3KXZ4R-X3DNLRPGVC5E-GKMELJB3LS6N-KENSEXWSVQPA-RKKIX443RHDY-54G4R3AQCWWB-B2R4E6-T5DJSXYB5KSNUA-DEPLOYMENT.TRIAL-A246QJ.TRIAL.EXPIRES.15.OCT.2024"; // Define the HTML content with a table, image, and multiple pages string htmlContent = @" <html> <head> <style> body { font-family: Arial, sans-serif; } h1 { color: #4CAF50; text-align: center; } p { text-align: justify; margin-bottom: 20px; } table { width: 100%; border-collapse: collapse; margin-bottom: 30px; } table, th, td { border: 1px solid black; } th { background-color: #4CAF50; color: white; } td { text-align: center; padding: 8px; } .page-break { page-break-before: always; } </style> </head> <body> <!-- Page 1 - Title and Text --> <h1>Sample PDF with Table and Image</h1> <p> This is a sample PDF generated using IronPDF. This PDF contains multiple pages with a colorful table, an image, and some text. The table below displays some sample data, followed by an embedded image. </p> <!-- Page Break Before Table --> <div class='page-break'></div> <!-- Page 2 - Colorful Table --> <table> <tr> <th>Item</th> <th>Quantity</th> <th>Price</th> </tr> <tr> <td>Apples</td> <td>5</td> <td>$3.00</td> </tr> <tr> <td>Bananas</td> <td>3</td> <td>$1.50</td> </tr> <tr> <td>Cherries</td> <td>7</td> <td>$4.20</td> </tr> <tr> <td>Oranges</td> <td>6</td> <td>$3.60</td> </tr> </table> <!-- Page Break Before Image --> <div class='page-break'></div> <!-- Page 3 - Image from URL or Local Path --> <h2>Embedded Image</h2> <p> Below is an image that has been embedded into the PDF from an external URL or local path. </p> <!-- External URL for the image --> <img src='https://via.placeholder.com/350x150' alt='Sample Image' style='width:350px;height:150px;' /> <!-- Local path for the image (uncomment this if you want to use a local image) --> <!-- <img src='C:/path/to/your/image.jpg' alt='Sample Image' style='width:350px;height:150px;' /> --> <!-- Page Break Before Last Page --> <div class='page-break'></div> <!-- Page 4 - More Text --> <p> This is the last page of the PDF. IronPDF makes it easy to generate complex documents with text, tables, images, and more. </p> </body> </html> "; // Create a new PDF document var htmlToPdf = new HtmlToPdf(); var pdfDocument = htmlToPdf.RenderHtmlAsPdf(htmlContent); // Save the PDF file string outputPath = @"ironpdf_with_page_breaks.pdf"; pdfDocument.SaveAs(outputPath); // Open File Explorer and select the generated PDF file Process.Start("explorer.exe", $"/select,\"{outputPath}\""); Console.WriteLine($"PDF generated successfully at {outputPath}"); } } |