From 121d2875ea9fdead3d3658509f8c334b2fc4b3b4 Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Wed, 30 Jul 2025 12:20:54 +0530 Subject: [PATCH 1/5] 966259: Added proper code sample for two phase PDF margin customization. --- ...e-PDF-merging-for-margin-customization.sln | 25 +++ .../Data/sample.html | 171 ++++++++++++++++++ .../Program.cs | 102 +++++++++++ ...DF-merging-for-margin-customization.csproj | 15 ++ 4 files changed, 313 insertions(+) create mode 100644 HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization.sln create mode 100644 HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Data/sample.html create mode 100644 HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Program.cs create mode 100644 HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Two-phase-PDF-merging-for-margin-customization.csproj diff --git a/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization.sln b/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization.sln new file mode 100644 index 00000000..86500d6c --- /dev/null +++ b/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36221.1 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Two-phase-PDF-merging-for-margin-customization", "Two-phase-PDF-merging-for-margin-customization\Two-phase-PDF-merging-for-margin-customization.csproj", "{546D19CF-BDDF-423D-A165-007E02911EF9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {546D19CF-BDDF-423D-A165-007E02911EF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {546D19CF-BDDF-423D-A165-007E02911EF9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {546D19CF-BDDF-423D-A165-007E02911EF9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {546D19CF-BDDF-423D-A165-007E02911EF9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E1A1C446-BB6A-4714-BE88-CC30C480A0A5} + EndGlobalSection +EndGlobal diff --git a/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Data/sample.html b/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Data/sample.html new file mode 100644 index 00000000..909b56e0 --- /dev/null +++ b/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Data/sample.html @@ -0,0 +1,171 @@ + + + + + + + +
+

Chapter 1: Introduction to PDF Generation

+

This document demonstrates how to create multi-page PDF content using HTML. The content is structured to span exactly 5-6 pages when converted to PDF.

+ +

1.1 Document Structure

+

Proper document structure is essential for consistent PDF conversion. We use:

+ + +

1.2 Page Layout Considerations

+

When designing for PDF output, consider:

+ + + + + + + + + + + + + + + + + +
ElementConsideration
ImagesUse high resolution (300dpi) for print quality
TablesAvoid row breaks across pages when possible
TextMaintain readable font sizes (10-12pt)
+
+ +
+ +
+

Chapter 2: Advanced PDF Features

+ +

2.1 Headers and Footers

+

Headers and footers should be consistent across pages but may need to be suppressed on title pages.

+ +

2.2 Page Numbering

+

Page numbers are typically added during PDF generation rather than in the HTML.

+ +

2.3 Multi-column Layout

+

CSS columns can be used for newspaper-style layouts:

+
+

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui mauris. Vivamus hendrerit arcu sed erat molestie vehicula. Sed auctor neque eu tellus rhoncus ut eleifend nibh porttitor.

+

Ut in nulla enim. Phasellus molestie magna non est bibendum non venenatis nisl tempor. Suspendisse dictum feugiat nisl ut dapibus. Mauris iaculis porttitor posuere.

+

Praesent id metus massa, ut blandit odio. Proin quis tortor orci. Etiam at risus et justo dignissim congue. Donec congue lacinia dui, a porttitor lectus condimentum laoreet.

+
+
+ +
+ +
+

Chapter 3: Visual Elements in PDF

+ +

3.1 Images

+

Properly sized images help maintain document flow:

+ Sample Image + +

3.2 Charts and Graphs

+

For data visualization, consider using SVG or high-resolution PNG images:

+ Sample Chart + +

3.3 Borders and Backgrounds

+
+

Styled divs can highlight important content while maintaining print readability.

+
+
+ +
+ +
+

Chapter 4: Long-form Content

+ +

4.1 Multi-page Tables

+

Tables that span multiple pages should have headers repeated:

+ + + + + + + + + + + + + + + + +
IDNameDescriptionValue
1Item ADescription of item A$100
2Item BDescription of item B$200
3Item CDescription of item C$300
+
+ +
+

Chapter 5: Conclusion

+

This template demonstrates how to structure HTML content that will reliably convert to a 5-6 page PDF document. Key takeaways:

+ + + +

5.1 Final Notes

+

Always test your HTML-to-PDF conversion with actual content to ensure proper pagination. The exact page count may vary slightly based on:

+ +
+ + + \ No newline at end of file diff --git a/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Program.cs b/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Program.cs new file mode 100644 index 00000000..f05c7954 --- /dev/null +++ b/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Program.cs @@ -0,0 +1,102 @@ +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + +// Initialize HTML to PDF converter +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + +// ======= HTML to PDF with No Margin ======= +// Set converter settings +BlinkConverterSettings settings = new BlinkConverterSettings(); +settings.Margin.All = 0; +htmlConverter.ConverterSettings = settings; + +// Load HTML content from a file +string html = File.ReadAllText(Path.GetFullPath(@"Data/Sample.html")); + +// Convert HTML to PDF +using (PdfDocument document = htmlConverter.Convert(html, "")) +{ + using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) + { + // Save the converted PDF document + document.Save(fileStream); + } +} +// ======= HTML to PDF with Top and Bottom Margins ======= +// Set different converter settings +BlinkConverterSettings settings1 = new BlinkConverterSettings(); +settings1.Margin.Top = 50; +settings1.Margin.Bottom = 50; +settings1.Margin.Left = 0; +settings1.Margin.Right = 0; +htmlConverter.ConverterSettings = settings1; + +// Convert HTML to PDF with updated settings +using (PdfDocument document1 = htmlConverter.Convert(html, "")) +{ + using (FileStream fileStream1 = new FileStream(Path.GetFullPath(@"Output/Output1.pdf"), FileMode.Create, FileAccess.ReadWrite)) + { + // Save the converted PDF document + document1.Save(fileStream1); + } +} + +// Load the source +using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Output/Output1.pdf"), FileMode.Open, FileAccess.Read)) +using (FileStream inputStream1 = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Open, FileAccess.Read)) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream)) +using (PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(inputStream1)) +using (PdfDocument finalDocument = new PdfDocument()) +{ + // Define pages requiring headers + HashSet pagesWithHeaders = new HashSet { 0, 2 }; // 0-based: pages 1 and 3 + + // Create margin and header settings + float headerHeight = 50; + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); + PdfBrush brush = PdfBrushes.Black; + string headerText = "Page Header"; + + // Iterate over each page in the original document + for (int i = 0; i < loadedDocument.Pages.Count; i++) + { + PdfTemplate contentTemplate; + PdfPage destPage = finalDocument.Pages.Add(); + destPage.Section.PageSettings.Margins.All = 0; + + if (pagesWithHeaders.Contains(i)) + { + // Page requires a header, copy from loadedDocument1 + PdfLoadedPage loadedPage = loadedDocument1.Pages[i] as PdfLoadedPage; + + // Create and apply the header + PdfGraphics graphics = destPage.Graphics; + graphics.DrawString(headerText, font, brush, new PointF(0, 0)); + + // Adjust for non-overlapping content + contentTemplate = loadedPage.CreateTemplate(); + graphics.DrawPdfTemplate(contentTemplate, new PointF(0, headerHeight)); + + // Set top margin + destPage.Section.PageSettings.Margins.Top = headerHeight; + } + else + { + // No header needed, copy from loadedDocument + PdfLoadedPage loadedPage = loadedDocument.Pages[i] as PdfLoadedPage; + + // Directly draw content + contentTemplate = loadedPage.CreateTemplate(); + destPage.Graphics.DrawPdfTemplate(contentTemplate, new PointF(0, 0)); + } + } + + using (FileStream fileStream2 = new FileStream(Path.GetFullPath(@"Output/FinalOutput.pdf"), FileMode.Create, FileAccess.ReadWrite)) + { + // Save the converted PDF document + finalDocument.Save(fileStream2); + } +} \ No newline at end of file diff --git a/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Two-phase-PDF-merging-for-margin-customization.csproj b/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Two-phase-PDF-merging-for-margin-customization.csproj new file mode 100644 index 00000000..319c1a88 --- /dev/null +++ b/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Two-phase-PDF-merging-for-margin-customization.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Two_phase_PDF_merging_for_margin_customization + enable + enable + + + + + + + From 5061f80ef39eb829e9ceb05f6d69dd9ce82ddbe5 Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Thu, 31 Jul 2025 12:03:21 +0530 Subject: [PATCH 2/5] 966259: Added proper project name. --- .../.NET/Page-specific-margins-and-conditional-headers.sln} | 2 +- .../Data/sample.html | 0 .../Page-specific-margins-and-conditional-headers.csproj} | 2 +- .../Page-specific-margins-and-conditional-headers}/Program.cs | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename HTML to PDF/Blink/{Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization.sln => Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers.sln} (79%) rename HTML to PDF/Blink/{Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization => Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers}/Data/sample.html (100%) rename HTML to PDF/Blink/{Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Two-phase-PDF-merging-for-margin-customization.csproj => Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Page-specific-margins-and-conditional-headers.csproj} (81%) rename HTML to PDF/Blink/{Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization => Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers}/Program.cs (100%) diff --git a/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization.sln b/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers.sln similarity index 79% rename from HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization.sln rename to HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers.sln index 86500d6c..1bd64c1b 100644 --- a/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization.sln +++ b/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.14.36221.1 d17.14 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Two-phase-PDF-merging-for-margin-customization", "Two-phase-PDF-merging-for-margin-customization\Two-phase-PDF-merging-for-margin-customization.csproj", "{546D19CF-BDDF-423D-A165-007E02911EF9}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Page-specific-margins-and-conditional-headers", "Page-specific-margins-and-conditional-headers\Page-specific-margins-and-conditional-headers.csproj", "{546D19CF-BDDF-423D-A165-007E02911EF9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Data/sample.html b/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Data/sample.html similarity index 100% rename from HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Data/sample.html rename to HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Data/sample.html diff --git a/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Two-phase-PDF-merging-for-margin-customization.csproj b/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Page-specific-margins-and-conditional-headers.csproj similarity index 81% rename from HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Two-phase-PDF-merging-for-margin-customization.csproj rename to HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Page-specific-margins-and-conditional-headers.csproj index 319c1a88..7369e2b8 100644 --- a/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Two-phase-PDF-merging-for-margin-customization.csproj +++ b/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Page-specific-margins-and-conditional-headers.csproj @@ -3,7 +3,7 @@ Exe net8.0 - Two_phase_PDF_merging_for_margin_customization + Page-specific-margins-and-conditional-headers enable enable diff --git a/HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Program.cs b/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Program.cs similarity index 100% rename from HTML to PDF/Blink/Two-phase-PDF-merging-for-margin-customization/.NET/Two-phase-PDF-merging-for-margin-customization/Program.cs rename to HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Program.cs From 001eabc68cda83c65757a6445daf2b6b0c411fd8 Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Thu, 31 Jul 2025 12:05:59 +0530 Subject: [PATCH 3/5] 966259: Added output path. --- .../Output/gitkeep.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Output/gitkeep.txt diff --git a/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Output/gitkeep.txt b/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Output/gitkeep.txt new file mode 100644 index 00000000..e69de29b From bba51a895c3b3e8cd9c8c5544fb2b020a2ca8dc1 Mon Sep 17 00:00:00 2001 From: Chinnu M Date: Thu, 7 Aug 2025 15:56:35 +0530 Subject: [PATCH 4/5] Modified the sample --- .../.NET/HeaderAndFooterForSpecificPage.sln | 25 +++ .../Data/sample.html | 171 ++++++++++++++++++ .../HeaderAndFooterForSpecificPage.csproj | 21 +++ .../HeaderAndFooterForSpecificPage/Program.cs | 107 +++++++++++ .../Program.cs | 102 ----------- 5 files changed, 324 insertions(+), 102 deletions(-) create mode 100644 HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage.sln create mode 100644 HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/Data/sample.html create mode 100644 HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/HeaderAndFooterForSpecificPage.csproj create mode 100644 HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/Program.cs delete mode 100644 HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Program.cs diff --git a/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage.sln b/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage.sln new file mode 100644 index 00000000..d8c4b6dd --- /dev/null +++ b/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36221.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeaderAndFooterForSpecificPage", "HeaderAndFooterForSpecificPage\HeaderAndFooterForSpecificPage.csproj", "{546D19CF-BDDF-423D-A165-007E02911EF9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {546D19CF-BDDF-423D-A165-007E02911EF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {546D19CF-BDDF-423D-A165-007E02911EF9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {546D19CF-BDDF-423D-A165-007E02911EF9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {546D19CF-BDDF-423D-A165-007E02911EF9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E1A1C446-BB6A-4714-BE88-CC30C480A0A5} + EndGlobalSection +EndGlobal diff --git a/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/Data/sample.html b/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/Data/sample.html new file mode 100644 index 00000000..909b56e0 --- /dev/null +++ b/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/Data/sample.html @@ -0,0 +1,171 @@ + + + + + + + +
+

Chapter 1: Introduction to PDF Generation

+

This document demonstrates how to create multi-page PDF content using HTML. The content is structured to span exactly 5-6 pages when converted to PDF.

+ +

1.1 Document Structure

+

Proper document structure is essential for consistent PDF conversion. We use:

+
    +
  • Semantic HTML5 elements
  • +
  • CSS for styling and layout
  • +
  • Page break controls where needed
  • +
+ +

1.2 Page Layout Considerations

+

When designing for PDF output, consider:

+ + + + + + + + + + + + + + + + + +
ElementConsideration
ImagesUse high resolution (300dpi) for print quality
TablesAvoid row breaks across pages when possible
TextMaintain readable font sizes (10-12pt)
+
+ +
+ +
+

Chapter 2: Advanced PDF Features

+ +

2.1 Headers and Footers

+

Headers and footers should be consistent across pages but may need to be suppressed on title pages.

+ +

2.2 Page Numbering

+

Page numbers are typically added during PDF generation rather than in the HTML.

+ +

2.3 Multi-column Layout

+

CSS columns can be used for newspaper-style layouts:

+
+

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui mauris. Vivamus hendrerit arcu sed erat molestie vehicula. Sed auctor neque eu tellus rhoncus ut eleifend nibh porttitor.

+

Ut in nulla enim. Phasellus molestie magna non est bibendum non venenatis nisl tempor. Suspendisse dictum feugiat nisl ut dapibus. Mauris iaculis porttitor posuere.

+

Praesent id metus massa, ut blandit odio. Proin quis tortor orci. Etiam at risus et justo dignissim congue. Donec congue lacinia dui, a porttitor lectus condimentum laoreet.

+
+
+ +
+ +
+

Chapter 3: Visual Elements in PDF

+ +

3.1 Images

+

Properly sized images help maintain document flow:

+ Sample Image + +

3.2 Charts and Graphs

+

For data visualization, consider using SVG or high-resolution PNG images:

+ Sample Chart + +

3.3 Borders and Backgrounds

+
+

Styled divs can highlight important content while maintaining print readability.

+
+
+ +
+ +
+

Chapter 4: Long-form Content

+ +

4.1 Multi-page Tables

+

Tables that span multiple pages should have headers repeated:

+ + + + + + + + + + + + + + + + +
IDNameDescriptionValue
1Item ADescription of item A$100
2Item BDescription of item B$200
3Item CDescription of item C$300
+
+ +
+

Chapter 5: Conclusion

+

This template demonstrates how to structure HTML content that will reliably convert to a 5-6 page PDF document. Key takeaways:

+ +
    +
  • Use proper semantic structure
  • +
  • Control page breaks with CSS
  • +
  • Optimize images for print
  • +
  • Test with your PDF converter
  • +
+ +

5.1 Final Notes

+

Always test your HTML-to-PDF conversion with actual content to ensure proper pagination. The exact page count may vary slightly based on:

+
    +
  • PDF converter settings
  • +
  • Font rendering differences
  • +
  • Margin requirements
  • +
+
+ + + \ No newline at end of file diff --git a/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/HeaderAndFooterForSpecificPage.csproj b/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/HeaderAndFooterForSpecificPage.csproj new file mode 100644 index 00000000..d20cac9b --- /dev/null +++ b/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/HeaderAndFooterForSpecificPage.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + HeaderAndFooterForSpecificPage + enable + enable + + + + + + + + + PreserveNewest + + + + diff --git a/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/Program.cs b/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/Program.cs new file mode 100644 index 00000000..6567afc3 --- /dev/null +++ b/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/Program.cs @@ -0,0 +1,107 @@ +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; + + + // Initialize HTML to PDF converter + HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + //Convert the HTML to PDF without margins. + BlinkConverterSettings settings = new BlinkConverterSettings(); + settings.Margin.All = 0; + settings.ViewPortSize = new Size(1024, 768); // Set the viewport size for rendering + htmlConverter.ConverterSettings = settings; + + // Load HTML content from a file + string html = File.ReadAllText(Path.GetFullPath(@"Data/Sample.html")); + + // Convert HTML to PDF + using (PdfDocument document = htmlConverter.Convert(html, "")) + { + if (Directory.Exists("Output") == false) + { + Directory.CreateDirectory("Output"); + } + using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Output/Output-HTML-To-PDF.pdf"), FileMode.OpenOrCreate, FileAccess.ReadWrite)) + { + // Save the converted PDF document + document.Save(fileStream); + } + } + htmlConverter.Close(); + +// Load the source +using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Output/Output-HTML-To-PDF.pdf"), FileMode.Open, FileAccess.Read)) +{ + //Load the converted document + using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream)) + { + + // Define pages requiring headers + HashSet pagesWithHeaders = new HashSet { 0, 2 }; // 0-based: pages 1 and 3 + + // Create a new PDF document + using (PdfDocument finalDocument = new PdfDocument()) + { + // Create a section for the new document + PdfSection section = finalDocument.Sections.Add(); + // Set margins for the section + section.PageSettings.Margins.All = 0; + // Iterate over each page in the original document + for (int i = 0; i < loadedDocument.Pages.Count; i++) + { + bool hasHeaderAndFooter = pagesWithHeaders.Contains(i); + if (hasHeaderAndFooter) + { + // Set the page size to match the original document by allocating space for headers and footer. + section.PageSettings.Size = loadedDocument.Pages[i].Size; + } + else + { + // Set the page size to match the original document + section.PageSettings.Size = loadedDocument.Pages[i].Size; + } + // Create a new page in the final document + PdfPage destPage = section.Pages.Add(); + + // Copy content from the loaded document + PdfTemplate contentTemplate = loadedDocument.Pages[i].CreateTemplate(); + + if (hasHeaderAndFooter) + { + //Define the font for header + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); + //Draw header and footer + AddHeaderAndFooter(destPage, "PDF Page Header Content", "PDF Page Footer Content", font); + //Draw the template + destPage.Graphics.DrawPdfTemplate(contentTemplate, new PointF(0, 50)); //50 Header height + } + else + { + // Draw the content on the destination page + destPage.Graphics.DrawPdfTemplate(contentTemplate, new PointF(0, 0)); + } + } + using (FileStream fileStream1 = new FileStream(Path.GetFullPath(@"Output/Output-With-HeaderAndFooter.pdf"), FileMode.Create, FileAccess.ReadWrite)) + { + // Save the converted PDF document + finalDocument.Save(fileStream1); + } + } + } +} + +static void AddHeaderAndFooter(PdfPage page, string headerText, string footerText, PdfFont font) +{ + // Draw header + page.Graphics.DrawLine(PdfPens.Gray, new PointF(0, 50), new PointF(page.GetClientSize().Width, 50)); + + //Measure the header text + SizeF textSize = font.MeasureString(headerText); + page.Graphics.DrawString(headerText, font, PdfBrushes.Red, new PointF((page.GetClientSize().Width - textSize.Width) / 2, (50 - textSize.Height) / 2)); + + // Draw footer + page.Graphics.DrawLine(PdfPens.Gray, new PointF(0, page.GetClientSize().Height - 50), new PointF(page.GetClientSize().Width, page.GetClientSize().Height - 50)); + page.Graphics.DrawString(footerText, font, PdfBrushes.Green, new PointF(10, page.GetClientSize().Height - 50)); //50 Footer height +} diff --git a/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Program.cs b/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Program.cs deleted file mode 100644 index f05c7954..00000000 --- a/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Program.cs +++ /dev/null @@ -1,102 +0,0 @@ -using Syncfusion.Drawing; -using Syncfusion.HtmlConverter; -using Syncfusion.Pdf; -using Syncfusion.Pdf.Graphics; -using Syncfusion.Pdf.Parsing; - -// Initialize HTML to PDF converter -HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); - -// ======= HTML to PDF with No Margin ======= -// Set converter settings -BlinkConverterSettings settings = new BlinkConverterSettings(); -settings.Margin.All = 0; -htmlConverter.ConverterSettings = settings; - -// Load HTML content from a file -string html = File.ReadAllText(Path.GetFullPath(@"Data/Sample.html")); - -// Convert HTML to PDF -using (PdfDocument document = htmlConverter.Convert(html, "")) -{ - using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - // Save the converted PDF document - document.Save(fileStream); - } -} -// ======= HTML to PDF with Top and Bottom Margins ======= -// Set different converter settings -BlinkConverterSettings settings1 = new BlinkConverterSettings(); -settings1.Margin.Top = 50; -settings1.Margin.Bottom = 50; -settings1.Margin.Left = 0; -settings1.Margin.Right = 0; -htmlConverter.ConverterSettings = settings1; - -// Convert HTML to PDF with updated settings -using (PdfDocument document1 = htmlConverter.Convert(html, "")) -{ - using (FileStream fileStream1 = new FileStream(Path.GetFullPath(@"Output/Output1.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - // Save the converted PDF document - document1.Save(fileStream1); - } -} - -// Load the source -using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Output/Output1.pdf"), FileMode.Open, FileAccess.Read)) -using (FileStream inputStream1 = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Open, FileAccess.Read)) -using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream)) -using (PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(inputStream1)) -using (PdfDocument finalDocument = new PdfDocument()) -{ - // Define pages requiring headers - HashSet pagesWithHeaders = new HashSet { 0, 2 }; // 0-based: pages 1 and 3 - - // Create margin and header settings - float headerHeight = 50; - PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); - PdfBrush brush = PdfBrushes.Black; - string headerText = "Page Header"; - - // Iterate over each page in the original document - for (int i = 0; i < loadedDocument.Pages.Count; i++) - { - PdfTemplate contentTemplate; - PdfPage destPage = finalDocument.Pages.Add(); - destPage.Section.PageSettings.Margins.All = 0; - - if (pagesWithHeaders.Contains(i)) - { - // Page requires a header, copy from loadedDocument1 - PdfLoadedPage loadedPage = loadedDocument1.Pages[i] as PdfLoadedPage; - - // Create and apply the header - PdfGraphics graphics = destPage.Graphics; - graphics.DrawString(headerText, font, brush, new PointF(0, 0)); - - // Adjust for non-overlapping content - contentTemplate = loadedPage.CreateTemplate(); - graphics.DrawPdfTemplate(contentTemplate, new PointF(0, headerHeight)); - - // Set top margin - destPage.Section.PageSettings.Margins.Top = headerHeight; - } - else - { - // No header needed, copy from loadedDocument - PdfLoadedPage loadedPage = loadedDocument.Pages[i] as PdfLoadedPage; - - // Directly draw content - contentTemplate = loadedPage.CreateTemplate(); - destPage.Graphics.DrawPdfTemplate(contentTemplate, new PointF(0, 0)); - } - } - - using (FileStream fileStream2 = new FileStream(Path.GetFullPath(@"Output/FinalOutput.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - // Save the converted PDF document - finalDocument.Save(fileStream2); - } -} \ No newline at end of file From c8d510cec6b62b87b7b351d9fa9d9759796bcc30 Mon Sep 17 00:00:00 2001 From: sameerkhan001 Date: Thu, 7 Aug 2025 16:15:06 +0530 Subject: [PATCH 5/5] 966259: Resolved given feedback. --- .../Output/gitkeep.txt | 0 ...ecific-margins-and-conditional-headers.sln | 25 --- .../Data/sample.html | 171 ------------------ ...fic-margins-and-conditional-headers.csproj | 15 -- 4 files changed, 211 deletions(-) rename HTML to PDF/Blink/{Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers => Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage}/Output/gitkeep.txt (100%) delete mode 100644 HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers.sln delete mode 100644 HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Data/sample.html delete mode 100644 HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Page-specific-margins-and-conditional-headers.csproj diff --git a/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Output/gitkeep.txt b/HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/Output/gitkeep.txt similarity index 100% rename from HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Output/gitkeep.txt rename to HTML to PDF/Blink/Header-And-Footer-For-Specific-Page/.NET/HeaderAndFooterForSpecificPage/Output/gitkeep.txt diff --git a/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers.sln b/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers.sln deleted file mode 100644 index 1bd64c1b..00000000 --- a/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.14.36221.1 d17.14 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Page-specific-margins-and-conditional-headers", "Page-specific-margins-and-conditional-headers\Page-specific-margins-and-conditional-headers.csproj", "{546D19CF-BDDF-423D-A165-007E02911EF9}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {546D19CF-BDDF-423D-A165-007E02911EF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {546D19CF-BDDF-423D-A165-007E02911EF9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {546D19CF-BDDF-423D-A165-007E02911EF9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {546D19CF-BDDF-423D-A165-007E02911EF9}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {E1A1C446-BB6A-4714-BE88-CC30C480A0A5} - EndGlobalSection -EndGlobal diff --git a/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Data/sample.html b/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Data/sample.html deleted file mode 100644 index 909b56e0..00000000 --- a/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Data/sample.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - -
-

Chapter 1: Introduction to PDF Generation

-

This document demonstrates how to create multi-page PDF content using HTML. The content is structured to span exactly 5-6 pages when converted to PDF.

- -

1.1 Document Structure

-

Proper document structure is essential for consistent PDF conversion. We use:

-
    -
  • Semantic HTML5 elements
  • -
  • CSS for styling and layout
  • -
  • Page break controls where needed
  • -
- -

1.2 Page Layout Considerations

-

When designing for PDF output, consider:

- - - - - - - - - - - - - - - - - -
ElementConsideration
ImagesUse high resolution (300dpi) for print quality
TablesAvoid row breaks across pages when possible
TextMaintain readable font sizes (10-12pt)
-
- -
- -
-

Chapter 2: Advanced PDF Features

- -

2.1 Headers and Footers

-

Headers and footers should be consistent across pages but may need to be suppressed on title pages.

- -

2.2 Page Numbering

-

Page numbers are typically added during PDF generation rather than in the HTML.

- -

2.3 Multi-column Layout

-

CSS columns can be used for newspaper-style layouts:

-
-

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui mauris. Vivamus hendrerit arcu sed erat molestie vehicula. Sed auctor neque eu tellus rhoncus ut eleifend nibh porttitor.

-

Ut in nulla enim. Phasellus molestie magna non est bibendum non venenatis nisl tempor. Suspendisse dictum feugiat nisl ut dapibus. Mauris iaculis porttitor posuere.

-

Praesent id metus massa, ut blandit odio. Proin quis tortor orci. Etiam at risus et justo dignissim congue. Donec congue lacinia dui, a porttitor lectus condimentum laoreet.

-
-
- -
- -
-

Chapter 3: Visual Elements in PDF

- -

3.1 Images

-

Properly sized images help maintain document flow:

- Sample Image - -

3.2 Charts and Graphs

-

For data visualization, consider using SVG or high-resolution PNG images:

- Sample Chart - -

3.3 Borders and Backgrounds

-
-

Styled divs can highlight important content while maintaining print readability.

-
-
- -
- -
-

Chapter 4: Long-form Content

- -

4.1 Multi-page Tables

-

Tables that span multiple pages should have headers repeated:

- - - - - - - - - - - - - - - - -
IDNameDescriptionValue
1Item ADescription of item A$100
2Item BDescription of item B$200
3Item CDescription of item C$300
-
- -
-

Chapter 5: Conclusion

-

This template demonstrates how to structure HTML content that will reliably convert to a 5-6 page PDF document. Key takeaways:

- -
    -
  • Use proper semantic structure
  • -
  • Control page breaks with CSS
  • -
  • Optimize images for print
  • -
  • Test with your PDF converter
  • -
- -

5.1 Final Notes

-

Always test your HTML-to-PDF conversion with actual content to ensure proper pagination. The exact page count may vary slightly based on:

-
    -
  • PDF converter settings
  • -
  • Font rendering differences
  • -
  • Margin requirements
  • -
-
- - - \ No newline at end of file diff --git a/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Page-specific-margins-and-conditional-headers.csproj b/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Page-specific-margins-and-conditional-headers.csproj deleted file mode 100644 index 7369e2b8..00000000 --- a/HTML to PDF/Blink/Page-specific-margins-and-conditional-headers/.NET/Page-specific-margins-and-conditional-headers/Page-specific-margins-and-conditional-headers.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - Exe - net8.0 - Page-specific-margins-and-conditional-headers - enable - enable - - - - - - -