Skip to content

Commit 45ab1c4

Browse files
Merge pull request #145 from SyncfusionExamples/921247
921247 Updated on Font-Related Issue in Tagged PDF UG Documentation
2 parents 0d54dc6 + b833071 commit 45ab1c4

File tree

12 files changed

+35
-14
lines changed
  • Tagged PDF
    • Add-tag-for-image-element-in-PDF-document/.NET/Add-tag-for-image-element-in-PDF-document
    • Add-tags-to-table-in-the-PDF-document/.NET/Add-tags-to-table-in-the-PDF-document
    • Add-tags-to-template-in-PDF-document/.NET/Add-tags-to-template-in-PDF-document
    • Add-the-tag-to-list-element-in-PDF-document/.NET/Add-the-tag-to-list-element-in-PDF-document
    • Adding-tag-to-shape-element-in-the-PDF-document/.NET/Adding-tag-to-shape-element-in-the-PDF-document

12 files changed

+35
-14
lines changed

Tagged PDF/Add-tag-for-hyperlink-in-the-PDF-document/.NET/Add-tag-for-hyperlink-in-the-PDF-document/Program.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
//Creates new PDF structure element with tag type link.
1818
PdfStructureElement linkStructureElement = new PdfStructureElement(PdfTagType.Link);
1919

20-
//Create the font.
21-
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f);
22-
2320
//Create the text web link.
2421
PdfTextWebLink textLink = new PdfTextWebLink();
2522

@@ -32,6 +29,9 @@
3229
//Set the link text.
3330
textLink.Text = "Syncfusion .NET components and controls";
3431

32+
//Load the TrueType font from the local *.ttf file.
33+
FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/Arial.ttf"), FileMode.Open, FileAccess.Read);
34+
PdfFont font = new PdfTrueTypeFont(fontStream, 14);
3535
//Set the font.
3636
textLink.Font = font;
3737

@@ -50,3 +50,4 @@
5050

5151
//Close the document.
5252
document.Close(true);
53+
fontStream.Dispose();

Tagged PDF/Add-tag-for-image-element-in-PDF-document/.NET/Add-tag-for-image-element-in-PDF-document/Program.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
//Creates new page.
1414
PdfPage page = document.Pages.Add();
1515

16+
//Load the TrueType font from the local *.ttf file.
17+
FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/Arial.ttf"), FileMode.Open, FileAccess.Read);
18+
PdfFont font = new PdfTrueTypeFont(fontStream, 14);
19+
1620
//Draw string.
17-
page.Graphics.DrawString("JPEG Image:", new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold), PdfBrushes.Blue, new PointF(0, 0));
21+
page.Graphics.DrawString("JPEG Image:", font, PdfBrushes.Blue, new PointF(0, 0));
1822

1923
//Load the image as stream.
2024
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/pdf.jpg"), FileMode.Open, FileAccess.Read);
@@ -43,3 +47,4 @@
4347

4448
//Close the document.
4549
document.Close(true);
50+
fontStream.Dispose();

Tagged PDF/Add-tags-to-table-in-the-PDF-document/.NET/Add-tags-to-table-in-the-PDF-document/Program.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@
3232
//Set table header.
3333
PdfGridRow pdfGridHeader = pdfGrid.Headers[0];
3434

35+
//Load the TrueType font from the local *.ttf file.
36+
FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/Arial.ttf"), FileMode.Open, FileAccess.Read);
37+
PdfFont font = new PdfTrueTypeFont(fontStream, 14);
38+
3539
//Set font and brush.
36-
pdfGridHeader.Style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);
40+
pdfGridHeader.Style.Font = font;
3741
pdfGridHeader.Style.TextBrush = PdfBrushes.Brown;
3842

3943
//Adding tag for each row with tag type TR.
@@ -85,3 +89,4 @@
8589

8690
//Close the document.
8791
pdfDocument.Close(true);
92+
fontStream.Dispose();

Tagged PDF/Add-tags-to-template-in-PDF-document/.NET/Add-tags-to-template-in-PDF-document/Program.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
//Add a page to the PDF document.
1414
PdfPage pdfPage = pdfDocument.Pages.Add();
1515

16+
//Load the TrueType font from the local *.ttf file.
17+
FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/Arial.ttf"), FileMode.Open, FileAccess.Read);
18+
PdfFont font = new PdfTrueTypeFont(fontStream, 14);
19+
1620
//Draw text in page.
17-
pdfPage.Graphics.DrawString("Rectangle:", new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold), PdfBrushes.Blue, new PointF(0, 0));
21+
pdfPage.Graphics.DrawString("Rectangle:", font, PdfBrushes.Blue, new PointF(0, 0));
1822

1923
//Create a PDF template.
2024
PdfTemplate template = new PdfTemplate(100, 50);
@@ -28,9 +32,6 @@
2832
//Adding tag to the template element
2933
template.PdfTag = structureElement;
3034

31-
//Set the font.
32-
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14);
33-
3435
//Set the brush.
3536
PdfBrush brush = new PdfSolidBrush(Color.Pink);
3637

@@ -49,3 +50,4 @@
4950

5051
//Close the document.
5152
pdfDocument.Close(true);
53+
fontStream.Dispose();

Tagged PDF/Add-the-tag-to-list-element-in-PDF-document/.NET/Add-the-tag-to-list-element-in-PDF-document/Program.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
//Get the page graphics size.
2121
SizeF size = page.Graphics.ClientSize;
2222

23-
//Create font.
24-
PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Italic);
23+
//Load the TrueType font from the local *.ttf file.
24+
FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/Arial.ttf"), FileMode.Open, FileAccess.Read);
25+
PdfFont font = new PdfTrueTypeFont(fontStream, 14);
2526

2627
//Draw text in PDF page.
27-
graphics.DrawString("List:", new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold), PdfBrushes.Blue, new PointF(10, 0));
28+
graphics.DrawString("List:", font, PdfBrushes.Blue, new PointF(10, 0));
2829

2930
string[] products = { "Tools", "Grid", "Chart", "Edit", "Diagram", "XlsIO", "Grouping", "Calculate", "PDF", "HTMLUI", "DocIO" };
3031

@@ -71,4 +72,5 @@
7172
}
7273

7374
//Close the document.
74-
document.Close(true);
75+
fontStream.Dispose();
76+
document.Close(true);

Tagged PDF/Adding-tag-to-shape-element-in-the-PDF-document/.NET/Adding-tag-to-shape-element-in-the-PDF-document/Program.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
//Add new page.
1414
PdfPage page = document.Pages.Add();
1515

16+
//Load the TrueType font from the local *.ttf file.
17+
FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/Arial.ttf"), FileMode.Open, FileAccess.Read);
18+
PdfFont font = new PdfTrueTypeFont(fontStream, 14);
19+
1620
//Draw text.
17-
page.Graphics.DrawString("Line Shape:", new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold), PdfBrushes.Blue, new PointF(30, 80));
21+
page.Graphics.DrawString("Line Shape:", font, PdfBrushes.Blue, new PointF(30, 80));
1822

1923
//Initialize structure element with tag type as figure.
2024
PdfStructureElement element = new PdfStructureElement(PdfTagType.Figure);
@@ -42,4 +46,6 @@
4246

4347
//Close the document.
4448
document.Close(true);
49+
fontStream.Dispose();
50+
4551

0 commit comments

Comments
 (0)