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

42167 Added sample code for created a multiline text area in PDF documents and avoid multiple font creation in PDF #146

Merged
merged 3 commits into from
Mar 24, 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.35707.178 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Creating-a-Multiline-Text-Area-in-PDF", "Creating-a-Multiline-Text-Area-in-PDF\Creating-a-Multiline-Text-Area-in-PDF.csproj", "{A5458CC1-56B4-4377-B1A6-DE8DC72E8D43}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A5458CC1-56B4-4377-B1A6-DE8DC72E8D43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5458CC1-56B4-4377-B1A6-DE8DC72E8D43}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5458CC1-56B4-4377-B1A6-DE8DC72E8D43}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5458CC1-56B4-4377-B1A6-DE8DC72E8D43}.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,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Creating_a_Multiline_Text_Area_in_PDF</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,32 @@
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf;
using Syncfusion.Drawing;

// Create a new PDF document
PdfDocument document = new PdfDocument();
// Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
// Create a standard font to be used in the text field
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
// Create a text box field and add it to the page with a name
PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName");
// Set the bounds (position and size) of the text box field
textBoxField.Bounds = new RectangleF(0, 0, 200, 50);

// Enable multiline functionality for the text box (allows multiple lines of text)
textBoxField.Multiline = true;

// Set the initial text inside the text box field
textBoxField.Text = "Essential PDF allows you to create and manage the form (AcroForm) in PDF document by using PdfForm class. The PdfFormFieldCollection class represents the entire field collection of the form.";
// Add the text box field to the form field collection in the document
document.Form.Fields.Add(textBoxField);

// Create a FileStream to save the document
using (FileStream stream = new FileStream(Path.GetFullPath(@"Output/Sample.pdf"), FileMode.Create, FileAccess.Write))
{
// Save the PDF document to the memory stream
document.Save(stream);
}
// Close the document
document.Close(true);
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.35707.178 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avoid-multiple-font-creation-in-PDF", "Avoid-multiple-font-creation-in-PDF\Avoid-multiple-font-creation-in-PDF.csproj", "{82E7DC13-52E6-4456-A3D8-3F7FDD5149D7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{82E7DC13-52E6-4456-A3D8-3F7FDD5149D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{82E7DC13-52E6-4456-A3D8-3F7FDD5149D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{82E7DC13-52E6-4456-A3D8-3F7FDD5149D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82E7DC13-52E6-4456-A3D8-3F7FDD5149D7}.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,15 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf;
using Syncfusion.Drawing;

// Create a new PDF document
PdfDocument document = new PdfDocument();

// Open the font stream once to use it for all pages instead of opening it repeatedly in each iteration
FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/Arial.ttf"), FileMode.Open, FileAccess.Read);

// Load the font from the font stream with a size of 14
PdfFont font = new PdfTrueTypeFont(fontStream, 14);

// Add 10 pages to the PDF document
for (int i = 0; i < 10; i++)
{
// Add a new page to the document
PdfPage page = document.Pages.Add();

// Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;

// Create a solid black brush to draw text on the page
PdfBrush brush = new PdfSolidBrush(Color.Black);

// Draw the text on the page at coordinates (20, 20), appending the iteration number (i) to each string
graphics.DrawString("Hello world!-" + i, font, brush, new PointF(20, 20));
}

// Create a file stream to save the PDF document to a file in the specified output path
using (FileStream stream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write))
{
// Save the PDF document to the file stream
document.Save(stream);
}

// Close the document and release resources
document.Close(true);

// Dispose of the font stream to free up resources
fontStream.Dispose();
Loading