You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Document-Processing/PDF/PDF-Library/NET/Working-with-Text.md
+160Lines changed: 160 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -798,6 +798,166 @@ document.Close(True)
798
798
799
799
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Text/Measure-tilting-space-in-PDF/.NET).
800
800
801
+
## Unit conversion in text layout
802
+
803
+
The [PdfUnitConverter](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfUnitConvertor.html) class is used to accurately position and layout paragraph text within a PDF document. By converting measurements from inches to points, it ensures consistent margins and precise placement of content.
804
+
805
+
This example demonstrates how to use converted units to accurately position and format paragraph text within a PDF document.
806
+
807
+
{% tabs %}
808
+
809
+
{% highlight c# tabtitle="C# [Cross-platform]" %}
810
+
811
+
using Syncfusion.Pdf;
812
+
using Syncfusion.Pdf.Graphics;
813
+
using Syncfusion.Drawing;
814
+
815
+
// Create a new PDF document
816
+
using (PdfDocument document = new PdfDocument())
817
+
{
818
+
// Add a page
819
+
PdfPage page = document.Pages.Add();
820
+
821
+
// Initialize unit converter
822
+
PdfUnitConverter converter = new PdfUnitConverter();
// Define text bounds to fill the page with margins
828
+
RectangleF textBounds = new RectangleF(
829
+
margin,
830
+
margin,
831
+
page.Graphics.ClientSize.Width - 2 * margin,
832
+
page.Graphics.ClientSize.Height - 2 * margin
833
+
);
834
+
835
+
// Define font and paragraph text
836
+
PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
837
+
838
+
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.";
839
+
840
+
// Create text element and layout format
841
+
PdfTextElement textElement = new PdfTextElement(paragraphText, font, PdfBrushes.Black);
842
+
843
+
PdfLayoutFormat layoutFormat = new PdfLayoutFormat
// Define text bounds to fill the page with margins
877
+
RectangleF textBounds = new RectangleF(
878
+
margin,
879
+
margin,
880
+
page.Graphics.ClientSize.Width - 2 * margin,
881
+
page.Graphics.ClientSize.Height - 2 * margin
882
+
);
883
+
884
+
// Define font and paragraph text
885
+
PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
886
+
887
+
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.";
888
+
889
+
// Create text element and layout format
890
+
PdfTextElement textElement = new PdfTextElement(paragraphText, font, PdfBrushes.Black);
891
+
892
+
PdfLayoutFormat layoutFormat = new PdfLayoutFormat
Dim margin As Single = converter.ConvertUnits(1.0F, PdfGraphicsUnit.Inch, PdfGraphicsUnit.Point)
926
+
927
+
' Define text bounds to fill the page with margins
928
+
Dim textBounds As New RectangleF(
929
+
margin,
930
+
margin,
931
+
page.Graphics.ClientSize.Width - 2 * margin,
932
+
page.Graphics.ClientSize.Height - 2 * margin
933
+
)
934
+
935
+
' Define font and paragraph text
936
+
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.TimesRoman, 14)
937
+
Dim paragraphText As String = "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."
938
+
939
+
' Create text element and layout format
940
+
Dim textElement As New PdfTextElement(paragraphText, font, PdfBrushes.Black)
941
+
Dim layoutFormat As New PdfLayoutFormat With {
942
+
.Break = PdfLayoutBreakType.FitPage,
943
+
.Layout = PdfLayoutType.Paginate
944
+
}
945
+
946
+
text within the bounds
947
+
textElement.Draw(page, textBounds, layoutFormat)
948
+
949
+
' Save the document
950
+
document.Save("Output.pdf")
951
+
End Using
952
+
End Sub
953
+
End Module
954
+
955
+
{% endhighlight %}
956
+
957
+
{% endtabs %}
958
+
959
+
You can download a complete working sample from GitHub.
960
+
801
961
## Embedding fonts and working with Unicode text
802
962
803
963
To embed a font or display Unicode text in the document, the ‘Unicode’ Boolean parameter of the [PdfTrueTypeFont](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfTrueTypeFont.html#Syncfusion_Pdf_Base__ctor) constructor has to be set to true. The following code illustrates the same.
0 commit comments