From 86b24dae6399e99d146ba226fe324fc25000822b Mon Sep 17 00:00:00 2001 From: jeyalakshmit Date: Wed, 28 Jun 2023 18:40:47 +0530 Subject: [PATCH] Added sample for Creating Tagged PDF with nested elements --- ...eating-Tagged-PDF-with-nested-elements.sln | 25 +++++++ ...ing-Tagged-PDF-with-nested-elements.csproj | 15 +++++ .../Program.cs | 66 +++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 Tagged PDF/Creating-Tagged-PDF-with-nested-elements/.NET/Creating-Tagged-PDF-with-nested-elements.sln create mode 100644 Tagged PDF/Creating-Tagged-PDF-with-nested-elements/.NET/Creating-Tagged-PDF-with-nested-elements/Creating-Tagged-PDF-with-nested-elements.csproj create mode 100644 Tagged PDF/Creating-Tagged-PDF-with-nested-elements/.NET/Creating-Tagged-PDF-with-nested-elements/Program.cs diff --git a/Tagged PDF/Creating-Tagged-PDF-with-nested-elements/.NET/Creating-Tagged-PDF-with-nested-elements.sln b/Tagged PDF/Creating-Tagged-PDF-with-nested-elements/.NET/Creating-Tagged-PDF-with-nested-elements.sln new file mode 100644 index 00000000..51922d28 --- /dev/null +++ b/Tagged PDF/Creating-Tagged-PDF-with-nested-elements/.NET/Creating-Tagged-PDF-with-nested-elements.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33417.168 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Creating-Tagged-PDF-with-nested-elements", "Creating-Tagged-PDF-with-nested-elements\Creating-Tagged-PDF-with-nested-elements.csproj", "{BEE61CA6-12C6-49F9-945F-8F40A67F7869}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BEE61CA6-12C6-49F9-945F-8F40A67F7869}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BEE61CA6-12C6-49F9-945F-8F40A67F7869}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BEE61CA6-12C6-49F9-945F-8F40A67F7869}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BEE61CA6-12C6-49F9-945F-8F40A67F7869}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8BFC8C72-D452-40E7-82D8-0473A35E1B4C} + EndGlobalSection +EndGlobal diff --git a/Tagged PDF/Creating-Tagged-PDF-with-nested-elements/.NET/Creating-Tagged-PDF-with-nested-elements/Creating-Tagged-PDF-with-nested-elements.csproj b/Tagged PDF/Creating-Tagged-PDF-with-nested-elements/.NET/Creating-Tagged-PDF-with-nested-elements/Creating-Tagged-PDF-with-nested-elements.csproj new file mode 100644 index 00000000..2f07de1e --- /dev/null +++ b/Tagged PDF/Creating-Tagged-PDF-with-nested-elements/.NET/Creating-Tagged-PDF-with-nested-elements/Creating-Tagged-PDF-with-nested-elements.csproj @@ -0,0 +1,15 @@ + + + + Exe + net7.0 + Creating_Tagged_PDF_with_nested_elements + enable + enable + + + + + + + diff --git a/Tagged PDF/Creating-Tagged-PDF-with-nested-elements/.NET/Creating-Tagged-PDF-with-nested-elements/Program.cs b/Tagged PDF/Creating-Tagged-PDF-with-nested-elements/.NET/Creating-Tagged-PDF-with-nested-elements/Program.cs new file mode 100644 index 00000000..9eb1b570 --- /dev/null +++ b/Tagged PDF/Creating-Tagged-PDF-with-nested-elements/.NET/Creating-Tagged-PDF-with-nested-elements/Program.cs @@ -0,0 +1,66 @@ +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using Syncfusion.Drawing; + +namespace Creating_Tagged_PDF_with_nested_elements { + internal class Program { + static void Main(string[] args) { + Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Mgo+DSMBMAY9C3t2V1hhQlJAfV5AQmBIYVp/TGpJfl96cVxMZVVBJAtUQF1hSn5Vd0BiXX9ccXRQRGBa"); + + //Creates new PDF document. + using (PdfDocument document = new PdfDocument()) { + //Set the document title. + document.DocumentInformation.Title = "Tagged Pdf Document"; + //Creates new page. + PdfPage page = document.Pages.Add(); + //Initialize the structure element with tag type paragraph. + PdfStructureElement structureElement = new PdfStructureElement(PdfTagType.Paragraph); + //Represents the text that is exact replacement for PdfTextElement. + structureElement.ActualText = "Simple paragraph element"; + string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean nec lectus ac sem faucibus imperdiet. Sed ut erat ac magna ullamcorper hendrerit. Cras pellentesque libero semper, gravida magna sed, luctus leo. Fusce lectus odio, laoreet nec ullamcorper ut, molestie eu elit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam lacinia sit amet elit ac consectetur. Donec cursus condimentum ligula, vitae volutpat sem tristique eget. Nulla in consectetur massa. Vestibulum vitae lobortis ante. Nulla ullamcorper pellentesque justo rhoncus accumsan. Mauris ornare eu odio non lacinia. Aliquam massa leo, rhoncus ac iaculis eget, tempus et magna. Sed non consectetur elit."; + //Initialize the PDF text element. + PdfTextElement element = new PdfTextElement(text); + //Adding tag to the text element. + element.PdfTag = structureElement; + //Creates font for the text element. + element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12); + //Create brush for the text element. + element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93)); + PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width, 200)); + + //Initialize the structure element with tag type quotation. + PdfStructureElement quoteChildElement = new PdfStructureElement(PdfTagType.Quotation); + quoteChildElement.Parent = structureElement; + string text1 = "This is the nested text."; + //Initialize the PDF text element. + PdfTextElement element1 = new PdfTextElement(text1); + element1.PdfTag = quoteChildElement; + //Creates font for the text element. + element1.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12); + //Create brush for the text element. + element1.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93)); + element1.Draw(page, new RectangleF(0, 100, result.Bounds.Width, result.Bounds.Height)); + + //Initialize the structure element with tag type span. + PdfStructureElement spanChildElement = new PdfStructureElement(PdfTagType.Span); + spanChildElement.Parent = structureElement; + string text2 = " Appended Text."; + //Initialize the PDF text element. + PdfTextElement element2 = new PdfTextElement(text2); + element2.PdfTag = spanChildElement; + //Creates font for the text element. + element2.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12); + //Create brush for the text element. + element2.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93)); + //Draws text element. + element2.Draw(page, new RectangleF(0, 140, result.Bounds.Width, result.Bounds.Height)); + + //Create file stream. + using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite)) { + //Save the PDF document to file stream. + document.Save(outputFileStream); + } + } + } + } +} \ No newline at end of file