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

935299 Added KB sample project in PDF Example. #130

Merged
merged 5 commits into from
Feb 17, 2025
Merged
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,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}") = "Get-number-of-digital-signatures", "Get-number-of-digital-signatures\Get-number-of-digital-signatures.csproj", "{3129BC31-7611-4A6D-9ED0-C4ECB7888852}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3129BC31-7611-4A6D-9ED0-C4ECB7888852}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3129BC31-7611-4A6D-9ED0-C4ECB7888852}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3129BC31-7611-4A6D-9ED0-C4ECB7888852}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3129BC31-7611-4A6D-9ED0-C4ECB7888852}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file not shown.
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>Get_number_of_digital_signatures</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Syncfusion.Pdf.Parsing;

// Initialize a counter to count the number of signature fields in the PDF document
int signedFieldsCount = 0;
int unSignedFieldsCount = 0;

// Open the PDF document as a file stream
using (FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read))
{
// Load the PDF document from the file stream
using (PdfLoadedDocument doc = new PdfLoadedDocument(docStream))
{
// Access the form inside the loaded PDF document
PdfLoadedForm form = doc.Form;

// Iterate through each field in the form field collection
foreach (PdfLoadedField field in form.Fields)
{
PdfLoadedSignatureField sigField = field as PdfLoadedSignatureField;
// Check whether the signature field is signed or not
if (sigField != null)
{
if (sigField.IsSigned)
{
signedFieldsCount++;
}
else
{
unSignedFieldsCount++;
}
}
}

// Display the total number of signature fields found in the PDF document
Console.WriteLine("The number of signed signature fields in the PDF document: " + signedFieldsCount);
Console.WriteLine("The number of unSigned signature fields in the PDF document: " + unSignedFieldsCount);
}
}
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}") = "Resize-font-to-fit-grid-cell-width", "Resize-font-to-fit-grid-cell-width\Resize-font-to-fit-grid-cell-width.csproj", "{13AC0FBB-D3CE-4370-BA00-2A639A4990BA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{13AC0FBB-D3CE-4370-BA00-2A639A4990BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13AC0FBB-D3CE-4370-BA00-2A639A4990BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13AC0FBB-D3CE-4370-BA00-2A639A4990BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13AC0FBB-D3CE-4370-BA00-2A639A4990BA}.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,107 @@
using Syncfusion.Pdf;
using Syncfusion.Pdf.Grid;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Drawing;

class Program
{
static void Main(string[] args)
{
// Create a new PDF document.
PdfDocument document = new PdfDocument();

// Add a page to the document.
PdfPage page = document.Pages.Add();

// Create a PdfGrid.
PdfGrid grid = new PdfGrid();

// Set the font for the grid.
grid.Style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);

// Add three columns to the grid.
grid.Columns.Add(3);

// Set the width of each column.
for (int i = 0; i < 3; i++)
{
grid.Columns[i].Width = page.GetClientSize().Width / 3;
}

// Set up the header cells.
PdfGridRow pdfGridHeader = grid.Headers.Add(1)[0];
pdfGridHeader.Cells[0].Value = "Employee ID";
pdfGridHeader.Cells[1].Value = "Employee Name";
pdfGridHeader.Cells[2].Value = "Details";

// Add rows to the grid.
for (int i = 1; i <= 5; i++)
{
PdfGridRow row = grid.Rows.Add();
row.Height = 20;
row.Cells[0].Value = "E0" + i;
row.Cells[1].Value = "Employee " + i;
row.Cells[2].Value = String.Format("Employee {0} is a software engineer with over ten years of experience in developing scalable applications. He specializes in full-stack development and enjoys working on innovative projects.", i);
}

// Adjust the font size to fit the cell content.
AdjustFontSize(grid);

// Draw the PdfGrid on the page.
grid.Draw(page, PointF.Empty);

// Save and close the document.
using (FileStream stream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
document.Save(stream);
}
document.Close(true);
}

// Method to adjust the font size to fit the cell content.
public static void AdjustFontSize(PdfGrid grid)
{
for (int i = 0; i < grid.Rows.Count; i++)
{
for (int j = 0; j < grid.Columns.Count; j++)
{
// Get the cell.
PdfGridCell cell = grid.Rows[i].Cells[j];

// Get the cell font.
PdfFont initialFont = cell.Style.Font ?? grid.Style.Font;

// Get the cell value.
string text = cell.Value?.ToString() ?? string.Empty;

// Get the cell size.
SizeF cellSize = new SizeF(grid.Columns[j].Width, grid.Rows[i].Height);

// Get the initial font size.
float fontSize = initialFont.Size;

PdfFont currentFont = initialFont;

while (fontSize > 0)
{
// Measure the text.
SizeF textSize = currentFont.MeasureString(text, cellSize.Width);
if (textSize.Height <= cellSize.Height)
{
cell.Style.Font = currentFont;
break;
}
fontSize--;
if (initialFont is PdfStandardFont)
{
currentFont = new PdfStandardFont(initialFont as PdfStandardFont, fontSize);
}
else
{
currentFont = new PdfTrueTypeFont(initialFont as PdfTrueTypeFont, fontSize);
}
}
}
}
}
}
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>Resize_font_to_fit_grid_cell_width</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
</ItemGroup>

</Project>
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}") = "Set-different-margins-for-multi-page-PDF-grid", "Set-different-margins-for-multi-page-PDF-grid\Set-different-margins-for-multi-page-PDF-grid.csproj", "{C8EB4001-9E7D-4340-8E5A-73B50908E0F0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C8EB4001-9E7D-4340-8E5A-73B50908E0F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8EB4001-9E7D-4340-8E5A-73B50908E0F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8EB4001-9E7D-4340-8E5A-73B50908E0F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8EB4001-9E7D-4340-8E5A-73B50908E0F0}.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,40 @@
using Syncfusion.Pdf.Grid;
using Syncfusion.Pdf;

//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Set page margins
document.PageSettings.Margins.Top = 50;
document.PageSettings.Margins.Bottom = 50;
//Add a new PDF page.
PdfPage page = document.Pages.Add();
//Create a PdfGrid.
PdfGrid pdfGrid = new PdfGrid();
//Add values to the list.
List<object> data = new List<object>();
for (int i = 0; i < 100; i++)
{
Object row1 = new { ID = "1", Name = "Clay", Price = "$10" };
Object row2 = new { ID = "2", Name = "Gray", Price = "$20" };
Object row3 = new { ID = "3", Name = "Ash", Price = "$30" };
data.Add(row1);
data.Add(row2);
data.Add(row3);
}
//Add list to IEnumerable.
IEnumerable<object> tableData = data;
//Assign data source.
pdfGrid.DataSource = tableData;
PdfGridLayoutFormat format = new PdfGridLayoutFormat();
//Set paginate bounds
format.PaginateBounds = new Syncfusion.Drawing.RectangleF(0, 15, page.GetClientSize().Width, page.GetClientSize().Height - 15);
//Draw the grid, letting Syncfusion handle pagination.
pdfGrid.Draw(page, new Syncfusion.Drawing.RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the PDF document to file stream.
document.Save(outputFileStream);
}
//Close the document.
document.Close(true);
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>Set_different_margins_for_multi_page_PDF_grid</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
</ItemGroup>

</Project>
Loading