diff --git a/HTML to PDF/Blink/Crop-page-from-HTML-to-PDF-document/.NET/Crop-page-from-HTML-to-PDF-document.sln b/HTML to PDF/Blink/Crop-page-from-HTML-to-PDF-document/.NET/Crop-page-from-HTML-to-PDF-document.sln new file mode 100644 index 00000000..2b69c85a --- /dev/null +++ b/HTML to PDF/Blink/Crop-page-from-HTML-to-PDF-document/.NET/Crop-page-from-HTML-to-PDF-document.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36616.10 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crop-page-from-HTML-to-PDF-document", "Crop-page-from-HTML-to-PDF-document\Crop-page-from-HTML-to-PDF-document.csproj", "{77219185-C36B-4F5F-823C-450F4B0C8D6E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {77219185-C36B-4F5F-823C-450F4B0C8D6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {77219185-C36B-4F5F-823C-450F4B0C8D6E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {77219185-C36B-4F5F-823C-450F4B0C8D6E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {77219185-C36B-4F5F-823C-450F4B0C8D6E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BC7C80E1-9850-4820-AAF7-CF9390605A84} + EndGlobalSection +EndGlobal diff --git a/HTML to PDF/Blink/Crop-page-from-HTML-to-PDF-document/.NET/Crop-page-from-HTML-to-PDF-document/Crop-page-from-HTML-to-PDF-document.csproj b/HTML to PDF/Blink/Crop-page-from-HTML-to-PDF-document/.NET/Crop-page-from-HTML-to-PDF-document/Crop-page-from-HTML-to-PDF-document.csproj new file mode 100644 index 00000000..1318eb6d --- /dev/null +++ b/HTML to PDF/Blink/Crop-page-from-HTML-to-PDF-document/.NET/Crop-page-from-HTML-to-PDF-document/Crop-page-from-HTML-to-PDF-document.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Crop_page_from_HTML_to_PDF_document + enable + enable + + + + + + + diff --git a/HTML to PDF/Blink/Crop-page-from-HTML-to-PDF-document/.NET/Crop-page-from-HTML-to-PDF-document/Output/gitkeep.txt b/HTML to PDF/Blink/Crop-page-from-HTML-to-PDF-document/.NET/Crop-page-from-HTML-to-PDF-document/Output/gitkeep.txt new file mode 100644 index 00000000..e69de29b diff --git a/HTML to PDF/Blink/Crop-page-from-HTML-to-PDF-document/.NET/Crop-page-from-HTML-to-PDF-document/Program.cs b/HTML to PDF/Blink/Crop-page-from-HTML-to-PDF-document/.NET/Crop-page-from-HTML-to-PDF-document/Program.cs new file mode 100644 index 00000000..990ab153 --- /dev/null +++ b/HTML to PDF/Blink/Crop-page-from-HTML-to-PDF-document/.NET/Crop-page-from-HTML-to-PDF-document/Program.cs @@ -0,0 +1,29 @@ +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + +// Create an HTML-to-PDF converter instance +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +// Convert the given URL to a PDF document +using (PdfDocument document = htmlConverter.Convert("https://www.google.com")) +using (PdfDocument croppedDocument = new PdfDocument()) +{ + // Get the first page from the converted PDF + PdfPage srcPage = document.Pages[0]; + // Create a template of the entire source page + PdfTemplate template = srcPage.CreateTemplate(); + // Define the crop height (3.6 inches converted to points) + float cropHeight = 3.6f * 72f; + float pageWidth = srcPage.GetClientSize().Width; // Get original page width + // Configure the new document's page settings for cropping + croppedDocument.PageSettings.Margins.All = 0; + croppedDocument.PageSettings.Width = pageWidth; + croppedDocument.PageSettings.Height = cropHeight; + // Add a new page to the cropped document + PdfPage destPage = croppedDocument.Pages.Add(); + // Draw the cropped template onto the new page + destPage.Graphics.DrawPdfTemplate(template, new PointF(0, 0)); + // Save the cropped PDF document + croppedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file