Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

929841 Added disable local file access #126

Merged
merged 4 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enable-local-file-access-HTML-to-PDF", "Enable-local-file-access-HTML-to-PDF\Enable-local-file-access-HTML-to-PDF.csproj", "{FD6E2CEF-5ED9-4218-BB4F-CC04CB50C676}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FD6E2CEF-5ED9-4218-BB4F-CC04CB50C676}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD6E2CEF-5ED9-4218-BB4F-CC04CB50C676}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD6E2CEF-5ED9-4218-BB4F-CC04CB50C676}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD6E2CEF-5ED9-4218-BB4F-CC04CB50C676}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { background-color: #fff; font-family: Arial, Helvetica, sans-serif; }
#guideHeader { background-color: #5d5d5d; color: white; }
#guideHeader { width: 630px; margin-left: auto; margin-right: auto; }

</style>
</head>
<body>
<div id="guideHeader">
<div style="float: left; height: 70px; width: 30%;">LOGO.png</div>
<div style="float: left; height: 70px; width: 40%; text-align: center; font-size: 22px; font-weight: bold;">Guidelines</div>
<div style="float: left; height: 70px; width: 30%; text-align: right; font-size: 13px;">@datetime</div>
<br style="clear: both;">
</div>
</body>
</html>
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>Enable_local_file_access_HTML_to_PDF</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,30 @@

using Syncfusion.Drawing;
using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;

// Initialize HTML to PDF converter with a using statement to ensure disposal
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();

// Initialize Blink converter settings
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
// Set Blink viewport size
blinkConverterSettings.ViewPortSize = new Size(1280, 0);

// EnableLocalFileAccess=false restricts external CSS and images in local HTML content
blinkConverterSettings.EnableLocalFileAccess = false;

// Assign Blink converter settings to HTML converter
htmlConverter.ConverterSettings = blinkConverterSettings;
// Read HTML content from file
string html = File.ReadAllText(Path.GetFullPath(@"Data/Sample.html"));
// Convert HTML to PDF document
using (PdfDocument document = htmlConverter.Convert(html, ""))
{
// Create a file stream with a using statement to ensure disposal
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
// Save the PDF document to the file stream
document.Save(fileStream);
}
}
Loading