Skip to content

Commit 3d8838e

Browse files
committed
948077 Added signature field in the PDF converted from HTML
1 parent da0b3df commit 3d8838e

6 files changed

Lines changed: 163 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35707.178 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Adding-signature-field-to-PDF-converted-from-HTML", "Adding-signature-field-to-PDF-converted-from-HTML\Adding-signature-field-to-PDF-converted-from-HTML.csproj", "{5A85F0E8-3D3C-4F45-8184-FB3B76BBC9BD}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{5A85F0E8-3D3C-4F45-8184-FB3B76BBC9BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5A85F0E8-3D3C-4F45-8184-FB3B76BBC9BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5A85F0E8-3D3C-4F45-8184-FB3B76BBC9BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{5A85F0E8-3D3C-4F45-8184-FB3B76BBC9BD}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Adding_signature_field_to_PDF_converted_from_HTML</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Windows" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
3+
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>Test Document</title>
7+
</head>
8+
<body>
9+
<form method="POST">
10+
Sample Report Data: <br />
11+
<table style="border: solid 1px red; margin: 5px" cellpadding="5px">
12+
<tr>
13+
<td>Field 1:</td>
14+
<td><input type="text" id="field1" name="field1" value="FIELD1VALUE" /></td>
15+
</tr>
16+
<tr>
17+
<td>Field 2:</td>
18+
<td><input type="text" id="Text2" value="FIELD2VALUE" /></td>
19+
</tr>
20+
<tr>
21+
<td>Field 3:</td>
22+
<td><input type="text" id="Text3" value="FIELD3VALUE" /></td>
23+
</tr>
24+
<tr>
25+
<td>Field 4:</td>
26+
<td><input type="text" id="Text4" value="FIELD4VALUE" /></td>
27+
</tr>
28+
<tr>
29+
<td>Signature:</td>
30+
<td><textarea id="ClientSignature" style="background-color:LightCyan;border-color:Gray;border-width:1px;border-style:Solid;height:50px;width:200px;abcpdf-tag-visible: true"
31+
rows="2" cols="20"></textarea></td>
32+
</tr>
33+
</table>
34+
</form>
35+
</body>
36+
</html>

HTML to PDF/Blink/Adding-signature-field-to-PDF-converted-from-HTML/.NET/Adding-signature-field-to-PDF-converted-from-HTML/Output/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using Syncfusion.Pdf.Graphics;
2+
using Syncfusion.Pdf;
3+
using Syncfusion.Drawing;
4+
using Syncfusion.HtmlConverter;
5+
using Syncfusion.Pdf.Interactive;
6+
using Syncfusion.Pdf.Parsing;
7+
8+
namespace Create_PDF
9+
{
10+
internal class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
//Initialize the HTML to PDF converter.
15+
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
16+
17+
BlinkConverterSettings settings = new BlinkConverterSettings();
18+
//Set enable form
19+
settings.EnableForm = true;
20+
//Assign Blink converter settings to HTML converter
21+
htmlConverter.ConverterSettings = settings;
22+
23+
//Convert HTML to PDF
24+
PdfDocument document = htmlConverter.Convert(Path.GetFullPath("Data/Test.html"));
25+
document.Form.SetDefaultAppearance(false);
26+
using (MemoryStream stream = new MemoryStream())
27+
{
28+
document.Save(stream);
29+
stream.Position = 0;
30+
document.Close(true);
31+
//Add signature field in PDF.
32+
AddSignature(stream);
33+
}
34+
35+
}
36+
/// <summary>
37+
/// Adds signature field in PDF
38+
/// </summary>
39+
/// <param name="stream"></param>
40+
static void AddSignature(MemoryStream stream)
41+
{
42+
//Load the PDF document.
43+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);
44+
//Get the loaded form.
45+
PdfLoadedForm loadedForm = loadedDocument.Form;
46+
47+
List<PdfSignatureField> signatureFields = new List<PdfSignatureField>();
48+
49+
for (int i = loadedForm.Fields.Count - 1; i >= 0; i--)
50+
{
51+
52+
if (loadedForm.Fields[i] is PdfLoadedTextBoxField)
53+
{
54+
//Get the loaded text box field and fill it.
55+
PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[i] as PdfLoadedTextBoxField;
56+
57+
if (loadedTextBoxField.Name.Contains("textarea"))
58+
{
59+
//Get bounds from an existing textbox field.
60+
RectangleF bounds = loadedTextBoxField.Bounds;
61+
62+
//Get page.
63+
PdfPageBase loadedPage = loadedTextBoxField.Page;
64+
65+
//Create PDF Signature field.
66+
PdfSignatureField signatureField = new PdfSignatureField(loadedPage, loadedTextBoxField.Name.Trim());
67+
68+
//Set properties to the signature field.
69+
signatureField.Bounds = bounds;
70+
71+
//Add the form field to the document.
72+
signatureFields.Add(signatureField);
73+
74+
loadedForm.Fields.Remove(loadedTextBoxField);
75+
}
76+
}
77+
}
78+
foreach (PdfSignatureField signature in signatureFields)
79+
{
80+
loadedForm.Fields.Add(signature);
81+
}
82+
//Save the document.
83+
using (FileStream outputStream1 = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
84+
{
85+
loadedDocument.Save(outputStream1);
86+
}
87+
loadedDocument.Close(true);
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)