Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Crop_page_from_HTML_to_PDF_document</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Windows" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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"));
}
Loading