Skip to content

Commit a1c7236

Browse files
committed
989050: Added PdfUnitConvertor for Unit Conversion in PDF Text Layout
1 parent 40a0613 commit a1c7236

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36616.10 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unit-conversion-in-text-layout", "Unit-conversion-in-text-layout\Unit-conversion-in-text-layout.csproj", "{B3390CE2-AAF4-48F8-B9B2-A3A6FD97CF66}"
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+
{B3390CE2-AAF4-48F8-B9B2-A3A6FD97CF66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B3390CE2-AAF4-48F8-B9B2-A3A6FD97CF66}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B3390CE2-AAF4-48F8-B9B2-A3A6FD97CF66}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B3390CE2-AAF4-48F8-B9B2-A3A6FD97CF66}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {44C257F7-3356-4AC0-93B6-5FE4C0803FD0}
24+
EndGlobalSection
25+
EndGlobal

Text/Unit-conversion-in-text-layout/.NET/Unit-conversion-in-text-layout/Output/gitkeep.txt

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Syncfusion.Pdf;
2+
using Syncfusion.Pdf.Graphics;
3+
using Syncfusion.Drawing;
4+
5+
// Create a new PDF document
6+
using (PdfDocument document = new PdfDocument())
7+
{
8+
// Add a page
9+
PdfPage page = document.Pages.Add();
10+
11+
// Initialize unit converter
12+
PdfUnitConvertor converter = new PdfUnitConvertor();
13+
14+
// Convert margins from inches to points
15+
float margin = converter.ConvertUnits(1f, PdfGraphicsUnit.Inch, PdfGraphicsUnit.Point);
16+
17+
// Define text bounds to fill the page with margins
18+
RectangleF textBounds = new RectangleF(
19+
margin,
20+
margin,
21+
page.Graphics.ClientSize.Width - 2 * margin,
22+
page.Graphics.ClientSize.Height - 2 * margin
23+
);
24+
25+
// Define font and paragraph text
26+
PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
27+
28+
string paragraphText = "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.";
29+
30+
// Create text element and layout format
31+
PdfTextElement textElement = new PdfTextElement(paragraphText, font, PdfBrushes.Black);
32+
33+
PdfLayoutFormat layoutFormat = new PdfLayoutFormat
34+
{
35+
Break = PdfLayoutBreakType.FitPage,
36+
Layout = PdfLayoutType.Paginate
37+
};
38+
39+
// Draw the paragraph text within the bounds
40+
textElement.Draw(page, textBounds, layoutFormat);
41+
42+
//Save the document
43+
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
44+
}
Lines changed: 15 additions & 0 deletions
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>Unit_conversion_in_text_layout</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>

0 commit comments

Comments
 (0)