Setting Structure Elements Properties
In order to set structure elements properties in a Tagged PDF Document, Aspose.PDF offers CreateSectElement and CreateHeaderElement methods of ITaggedContent interface.
Following code snippet shows how to set structure elements properties of a Tagged PDF Document:
Setting Text Structure Elements
In order to set text structure elements of a Tagged PDF Document, Aspose.PDF offers ParagraphElement class. Following code snippet shows how to set text structure elements of a Tagged PDF Document:
Setting Text Block Structure Elements
In order to set text block structure elements of a Tagged PDF Document, Aspose.PDF offers HeaderElement and ParagraphElement classes. You can append objects of these classes as a child of StructureElement object.
Following code snippet shows how to set text block structure elements of a Tagged PDF Document:
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SetTextBlockElements ()
{
// The path to the documents directory
string dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
// Create PDF Document
using ( var document = new Aspose . Pdf . Document ())
{
// Get Content for work with Tagged PDF
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document . TaggedContent ;
// Set Title and Language for Document
taggedContent . SetTitle ( "Tagged Pdf Document" );
taggedContent . SetLanguage ( "en-US" );
// Get Root Structure Element
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . HeaderElement h1 = taggedContent . CreateHeaderElement ( 1 );
Aspose . Pdf . LogicalStructure . HeaderElement h2 = taggedContent . CreateHeaderElement ( 2 );
Aspose . Pdf . LogicalStructure . HeaderElement h3 = taggedContent . CreateHeaderElement ( 3 );
Aspose . Pdf . LogicalStructure . HeaderElement h4 = taggedContent . CreateHeaderElement ( 4 );
Aspose . Pdf . LogicalStructure . HeaderElement h5 = taggedContent . CreateHeaderElement ( 5 );
Aspose . Pdf . LogicalStructure . HeaderElement h6 = taggedContent . CreateHeaderElement ( 6 );
h1 . SetText ( "H1. Header of Level 1" );
h2 . SetText ( "H2. Header of Level 2" );
h3 . SetText ( "H3. Header of Level 3" );
h4 . SetText ( "H4. Header of Level 4" );
h5 . SetText ( "H5. Header of Level 5" );
h6 . SetText ( "H6. Header of Level 6" );
rootElement . AppendChild ( h1 );
rootElement . AppendChild ( h2 );
rootElement . AppendChild ( h3 );
rootElement . AppendChild ( h4 );
rootElement . AppendChild ( h5 );
rootElement . AppendChild ( h6 );
Aspose . Pdf . LogicalStructure . ParagraphElement p = taggedContent . CreateParagraphElement ();
p . SetText ( "P. 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. Sed vulputate, quam sed lacinia luctus, ipsum nibh fringilla purus, vitae posuere risus odio id massa. Cras sed venenatis lacus." );
rootElement . AppendChild ( p );
// Save Tagged PDF Document
document . Save ( dataDir + "TextBlockStructureElements.pdf" );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SetTextBlockElements ()
{
// The path to the documents directory
string dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
// Create PDF Document
using var document = new Aspose . Pdf . Document ();
// Get Content for work with Tagged PDF
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document . TaggedContent ;
// Set Title and Language for Document
taggedContent . SetTitle ( "Tagged Pdf Document" );
taggedContent . SetLanguage ( "en-US" );
// Get Root Structure Element
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . HeaderElement h1 = taggedContent . CreateHeaderElement ( 1 );
Aspose . Pdf . LogicalStructure . HeaderElement h2 = taggedContent . CreateHeaderElement ( 2 );
Aspose . Pdf . LogicalStructure . HeaderElement h3 = taggedContent . CreateHeaderElement ( 3 );
Aspose . Pdf . LogicalStructure . HeaderElement h4 = taggedContent . CreateHeaderElement ( 4 );
Aspose . Pdf . LogicalStructure . HeaderElement h5 = taggedContent . CreateHeaderElement ( 5 );
Aspose . Pdf . LogicalStructure . HeaderElement h6 = taggedContent . CreateHeaderElement ( 6 );
h1 . SetText ( "H1. Header of Level 1" );
h2 . SetText ( "H2. Header of Level 2" );
h3 . SetText ( "H3. Header of Level 3" );
h4 . SetText ( "H4. Header of Level 4" );
h5 . SetText ( "H5. Header of Level 5" );
h6 . SetText ( "H6. Header of Level 6" );
rootElement . AppendChild ( h1 );
rootElement . AppendChild ( h2 );
rootElement . AppendChild ( h3 );
rootElement . AppendChild ( h4 );
rootElement . AppendChild ( h5 );
rootElement . AppendChild ( h6 );
Aspose . Pdf . LogicalStructure . ParagraphElement p = taggedContent . CreateParagraphElement ();
p . SetText ( "P. 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. Sed vulputate, quam sed lacinia luctus, ipsum nibh fringilla purus, vitae posuere risus odio id massa. Cras sed venenatis lacus." );
rootElement . AppendChild ( p );
// Save Tagged PDF Document
document . Save ( dataDir + "TextBlockStructureElements.pdf" );
}
Setting Inline Structure Elements
In order to set inline structure elements of a Tagged PDF Document, Aspose.PDF offers SpanElement and ParagraphElement classes. You can append objects of these classes as a child of StructureElement object. Following code snippet shows how to set inline structure elements of a Tagged PDF Document:
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SetInlineElements ()
{
// The path to the documents directory
string dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
// Create PDF Document
using ( var document = new Aspose . Pdf . Document ())
{
// Get Content for work with Tagged PDF
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document . TaggedContent ;
// Set Title and Language for Document
taggedContent . SetTitle ( "Tagged Pdf Document" );
taggedContent . SetLanguage ( "en-US" );
// Get Root Structure Element
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . HeaderElement h1 = taggedContent . CreateHeaderElement ( 1 );
Aspose . Pdf . LogicalStructure . HeaderElement h2 = taggedContent . CreateHeaderElement ( 2 );
Aspose . Pdf . LogicalStructure . HeaderElement h3 = taggedContent . CreateHeaderElement ( 3 );
Aspose . Pdf . LogicalStructure . HeaderElement h4 = taggedContent . CreateHeaderElement ( 4 );
Aspose . Pdf . LogicalStructure . HeaderElement h5 = taggedContent . CreateHeaderElement ( 5 );
Aspose . Pdf . LogicalStructure . HeaderElement h6 = taggedContent . CreateHeaderElement ( 6 );
rootElement . AppendChild ( h1 );
rootElement . AppendChild ( h2 );
rootElement . AppendChild ( h3 );
rootElement . AppendChild ( h4 );
rootElement . AppendChild ( h5 );
rootElement . AppendChild ( h6 );
Aspose . Pdf . LogicalStructure . SpanElement spanH11 = taggedContent . CreateSpanElement ();
spanH11 . SetText ( "H1. " );
h1 . AppendChild ( spanH11 );
Aspose . Pdf . LogicalStructure . SpanElement spanH12 = taggedContent . CreateSpanElement ();
spanH12 . SetText ( "Level 1 Header" );
h1 . AppendChild ( spanH12 );
Aspose . Pdf . LogicalStructure . SpanElement spanH21 = taggedContent . CreateSpanElement ();
spanH21 . SetText ( "H2. " );
h2 . AppendChild ( spanH21 );
Aspose . Pdf . LogicalStructure . SpanElement spanH22 = taggedContent . CreateSpanElement ();
spanH22 . SetText ( "Level 2 Header" );
h2 . AppendChild ( spanH22 );
Aspose . Pdf . LogicalStructure . SpanElement spanH31 = taggedContent . CreateSpanElement ();
spanH31 . SetText ( "H3. " );
h3 . AppendChild ( spanH31 );
Aspose . Pdf . LogicalStructure . SpanElement spanH32 = taggedContent . CreateSpanElement ();
spanH32 . SetText ( "Level 3 Header" );
h3 . AppendChild ( spanH32 );
Aspose . Pdf . LogicalStructure . SpanElement spanH41 = taggedContent . CreateSpanElement ();
spanH41 . SetText ( "H4. " );
h4 . AppendChild ( spanH41 );
Aspose . Pdf . LogicalStructure . SpanElement spanH42 = taggedContent . CreateSpanElement ();
spanH42 . SetText ( "Level 4 Header" );
h4 . AppendChild ( spanH42 );
Aspose . Pdf . LogicalStructure . SpanElement spanH51 = taggedContent . CreateSpanElement ();
spanH51 . SetText ( "H5. " );
h5 . AppendChild ( spanH51 );
Aspose . Pdf . LogicalStructure . SpanElement spanH52 = taggedContent . CreateSpanElement ();
spanH52 . SetText ( "Level 5 Header" );
h5 . AppendChild ( spanH52 );
Aspose . Pdf . LogicalStructure . SpanElement spanH61 = taggedContent . CreateSpanElement ();
spanH61 . SetText ( "H6. " );
h6 . AppendChild ( spanH61 );
Aspose . Pdf . LogicalStructure . SpanElement spanH62 = taggedContent . CreateSpanElement ();
spanH62 . SetText ( "Level 6 Header" );
h6 . AppendChild ( spanH62 );
Aspose . Pdf . LogicalStructure . ParagraphElement p = taggedContent . CreateParagraphElement ();
p . SetText ( "P. " );
rootElement . AppendChild ( p );
Aspose . Pdf . LogicalStructure . SpanElement span1 = taggedContent . CreateSpanElement ();
span1 . SetText ( "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " );
p . AppendChild ( span1 );
Aspose . Pdf . LogicalStructure . SpanElement span2 = taggedContent . CreateSpanElement ();
span2 . SetText ( "Aenean nec lectus ac sem faucibus imperdiet. " );
p . AppendChild ( span2 );
Aspose . Pdf . LogicalStructure . SpanElement span3 = taggedContent . CreateSpanElement ();
span3 . SetText ( "Sed ut erat ac magna ullamcorper hendrerit. " );
p . AppendChild ( span3 );
Aspose . Pdf . LogicalStructure . SpanElement span4 = taggedContent . CreateSpanElement ();
span4 . SetText ( "Cras pellentesque libero semper, gravida magna sed, luctus leo. " );
p . AppendChild ( span4 );
Aspose . Pdf . LogicalStructure . SpanElement span5 = taggedContent . CreateSpanElement ();
span5 . SetText ( "Fusce lectus odio, laoreet nec ullamcorper ut, molestie eu elit. " );
p . AppendChild ( span5 );
Aspose . Pdf . LogicalStructure . SpanElement span6 = taggedContent . CreateSpanElement ();
span6 . SetText ( "Interdum et malesuada fames ac ante ipsum primis in faucibus. " );
p . AppendChild ( span6 );
Aspose . Pdf . LogicalStructure . SpanElement span7 = taggedContent . CreateSpanElement ();
span7 . SetText ( "Aliquam lacinia sit amet elit ac consectetur. Donec cursus condimentum ligula, vitae volutpat sem tristique eget. " );
p . AppendChild ( span7 );
Aspose . Pdf . LogicalStructure . SpanElement span8 = taggedContent . CreateSpanElement ();
span8 . SetText ( "Nulla in consectetur massa. Vestibulum vitae lobortis ante. Nulla ullamcorper pellentesque justo rhoncus accumsan. " );
p . AppendChild ( span8 );
Aspose . Pdf . LogicalStructure . SpanElement span9 = taggedContent . CreateSpanElement ();
span9 . SetText ( "Mauris ornare eu odio non lacinia. Aliquam massa leo, rhoncus ac iaculis eget, tempus et magna. Sed non consectetur elit. " );
p . AppendChild ( span9 );
Aspose . Pdf . LogicalStructure . SpanElement span10 = taggedContent . CreateSpanElement ();
span10 . SetText ( "Sed vulputate, quam sed lacinia luctus, ipsum nibh fringilla purus, vitae posuere risus odio id massa. Cras sed venenatis lacus." );
p . AppendChild ( span10 );
// Save Tagged PDF Document
document . Save ( dataDir + "InlineStructureElements.pdf" );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SetInlineElements ()
{
// The path to the documents directory
string dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
// Create PDF Document
using var document = new Aspose . Pdf . Document ();
// Get Content for work with Tagged PDF
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document . TaggedContent ;
// Set Title and Language for Document
taggedContent . SetTitle ( "Tagged Pdf Document" );
taggedContent . SetLanguage ( "en-US" );
// Get Root Structure Element
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . HeaderElement h1 = taggedContent . CreateHeaderElement ( 1 );
Aspose . Pdf . LogicalStructure . HeaderElement h2 = taggedContent . CreateHeaderElement ( 2 );
Aspose . Pdf . LogicalStructure . HeaderElement h3 = taggedContent . CreateHeaderElement ( 3 );
Aspose . Pdf . LogicalStructure . HeaderElement h4 = taggedContent . CreateHeaderElement ( 4 );
Aspose . Pdf . LogicalStructure . HeaderElement h5 = taggedContent . CreateHeaderElement ( 5 );
Aspose . Pdf . LogicalStructure . HeaderElement h6 = taggedContent . CreateHeaderElement ( 6 );
rootElement . AppendChild ( h1 );
rootElement . AppendChild ( h2 );
rootElement . AppendChild ( h3 );
rootElement . AppendChild ( h4 );
rootElement . AppendChild ( h5 );
rootElement . AppendChild ( h6 );
Aspose . Pdf . LogicalStructure . SpanElement spanH11 = taggedContent . CreateSpanElement ();
spanH11 . SetText ( "H1. " );
h1 . AppendChild ( spanH11 );
Aspose . Pdf . LogicalStructure . SpanElement spanH12 = taggedContent . CreateSpanElement ();
spanH12 . SetText ( "Level 1 Header" );
h1 . AppendChild ( spanH12 );
Aspose . Pdf . LogicalStructure . SpanElement spanH21 = taggedContent . CreateSpanElement ();
spanH21 . SetText ( "H2. " );
h2 . AppendChild ( spanH21 );
Aspose . Pdf . LogicalStructure . SpanElement spanH22 = taggedContent . CreateSpanElement ();
spanH22 . SetText ( "Level 2 Header" );
h2 . AppendChild ( spanH22 );
Aspose . Pdf . LogicalStructure . SpanElement spanH31 = taggedContent . CreateSpanElement ();
spanH31 . SetText ( "H3. " );
h3 . AppendChild ( spanH31 );
Aspose . Pdf . LogicalStructure . SpanElement spanH32 = taggedContent . CreateSpanElement ();
spanH32 . SetText ( "Level 3 Header" );
h3 . AppendChild ( spanH32 );
Aspose . Pdf . LogicalStructure . SpanElement spanH41 = taggedContent . CreateSpanElement ();
spanH41 . SetText ( "H4. " );
h4 . AppendChild ( spanH41 );
Aspose . Pdf . LogicalStructure . SpanElement spanH42 = taggedContent . CreateSpanElement ();
spanH42 . SetText ( "Level 4 Header" );
h4 . AppendChild ( spanH42 );
Aspose . Pdf . LogicalStructure . SpanElement spanH51 = taggedContent . CreateSpanElement ();
spanH51 . SetText ( "H5. " );
h5 . AppendChild ( spanH51 );
Aspose . Pdf . LogicalStructure . SpanElement spanH52 = taggedContent . CreateSpanElement ();
spanH52 . SetText ( "Level 5 Header" );
h5 . AppendChild ( spanH52 );
Aspose . Pdf . LogicalStructure . SpanElement spanH61 = taggedContent . CreateSpanElement ();
spanH61 . SetText ( "H6. " );
h6 . AppendChild ( spanH61 );
Aspose . Pdf . LogicalStructure . SpanElement spanH62 = taggedContent . CreateSpanElement ();
spanH62 . SetText ( "Level 6 Header" );
h6 . AppendChild ( spanH62 );
Aspose . Pdf . LogicalStructure . ParagraphElement p = taggedContent . CreateParagraphElement ();
p . SetText ( "P. " );
rootElement . AppendChild ( p );
Aspose . Pdf . LogicalStructure . SpanElement span1 = taggedContent . CreateSpanElement ();
span1 . SetText ( "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " );
p . AppendChild ( span1 );
Aspose . Pdf . LogicalStructure . SpanElement span2 = taggedContent . CreateSpanElement ();
span2 . SetText ( "Aenean nec lectus ac sem faucibus imperdiet. " );
p . AppendChild ( span2 );
Aspose . Pdf . LogicalStructure . SpanElement span3 = taggedContent . CreateSpanElement ();
span3 . SetText ( "Sed ut erat ac magna ullamcorper hendrerit. " );
p . AppendChild ( span3 );
Aspose . Pdf . LogicalStructure . SpanElement span4 = taggedContent . CreateSpanElement ();
span4 . SetText ( "Cras pellentesque libero semper, gravida magna sed, luctus leo. " );
p . AppendChild ( span4 );
Aspose . Pdf . LogicalStructure . SpanElement span5 = taggedContent . CreateSpanElement ();
span5 . SetText ( "Fusce lectus odio, laoreet nec ullamcorper ut, molestie eu elit. " );
p . AppendChild ( span5 );
Aspose . Pdf . LogicalStructure . SpanElement span6 = taggedContent . CreateSpanElement ();
span6 . SetText ( "Interdum et malesuada fames ac ante ipsum primis in faucibus. " );
p . AppendChild ( span6 );
Aspose . Pdf . LogicalStructure . SpanElement span7 = taggedContent . CreateSpanElement ();
span7 . SetText ( "Aliquam lacinia sit amet elit ac consectetur. Donec cursus condimentum ligula, vitae volutpat sem tristique eget. " );
p . AppendChild ( span7 );
Aspose . Pdf . LogicalStructure . SpanElement span8 = taggedContent . CreateSpanElement ();
span8 . SetText ( "Nulla in consectetur massa. Vestibulum vitae lobortis ante. Nulla ullamcorper pellentesque justo rhoncus accumsan. " );
p . AppendChild ( span8 );
Aspose . Pdf . LogicalStructure . SpanElement span9 = taggedContent . CreateSpanElement ();
span9 . SetText ( "Mauris ornare eu odio non lacinia. Aliquam massa leo, rhoncus ac iaculis eget, tempus et magna. Sed non consectetur elit. " );
p . AppendChild ( span9 );
Aspose . Pdf . LogicalStructure . SpanElement span10 = taggedContent . CreateSpanElement ();
span10 . SetText ( "Sed vulputate, quam sed lacinia luctus, ipsum nibh fringilla purus, vitae posuere risus odio id massa. Cras sed venenatis lacus." );
p . AppendChild ( span10 );
// Save Tagged PDF Document
document . Save ( dataDir + "InlineStructureElements.pdf" );
}
Setting Custom Tag Name
In order to set a custom tag name of the elements of a Tagged PDF Document, Aspose.PDF offers SetTag method of StructureElement class for elements. Following code snippet shows how to set custom tag name:
Adding Structure Element into Elements
This feature is supported by version 19.4 or greater.
In order to set link structure elements in a Tagged PDF Document, Aspose.PDF offers CreateLinkElement method of ITaggedContent interface. Following code snippet shows how to set structure elements in paragraph with text of Tagged PDF Document:
Setting Link Structure Element
This feature is supported by version 19.4 or greater.
Aspose.PDF for .NET API also allows you to add link structure elements. Following code snippet shows how to add link structure element into Tagged PDF Document:
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddLinkElement ()
{
// The path to the documents directory
string dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
string outFile = dataDir + "AddStructureElementIntoElement_Output.pdf" ;
string logFile = dataDir + "46144_log.xml" ;
// Creation document and getting Tagged PDF Content
using ( var document = new Aspose . Pdf . Document ())
{
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document . TaggedContent ;
// Setting Title and Nature Language for document
taggedContent . SetTitle ( "Text Elements Example" );
taggedContent . SetLanguage ( "en-US" );
// Getting Root structure element (Document structure element)
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . ParagraphElement p1 = taggedContent . CreateParagraphElement ();
rootElement . AppendChild ( p1 );
Aspose . Pdf . LogicalStructure . SpanElement span11 = taggedContent . CreateSpanElement ();
span11 . SetText ( "Span_11" );
Aspose . Pdf . LogicalStructure . SpanElement span12 = taggedContent . CreateSpanElement ();
span12 . SetText ( " and Span_12." );
p1 . SetText ( "Paragraph with " );
p1 . AppendChild ( span11 );
p1 . AppendChild ( span12 );
Aspose . Pdf . LogicalStructure . ParagraphElement p2 = taggedContent . CreateParagraphElement ();
rootElement . AppendChild ( p2 );
Aspose . Pdf . LogicalStructure . SpanElement span21 = taggedContent . CreateSpanElement ();
span21 . SetText ( "Span_21" );
Aspose . Pdf . LogicalStructure . SpanElement span22 = taggedContent . CreateSpanElement ();
span22 . SetText ( "Span_22." );
p2 . AppendChild ( span21 );
p2 . SetText ( " and " );
p2 . AppendChild ( span22 );
Aspose . Pdf . LogicalStructure . ParagraphElement p3 = taggedContent . CreateParagraphElement ();
rootElement . AppendChild ( p3 );
Aspose . Pdf . LogicalStructure . SpanElement span31 = taggedContent . CreateSpanElement ();
span31 . SetText ( "Span_31" );
Aspose . Pdf . LogicalStructure . SpanElement span32 = taggedContent . CreateSpanElement ();
span32 . SetText ( " and Span_32" );
p3 . AppendChild ( span31 );
p3 . AppendChild ( span32 );
p3 . SetText ( "." );
Aspose . Pdf . LogicalStructure . ParagraphElement p4 = taggedContent . CreateParagraphElement ();
rootElement . AppendChild ( p4 );
Aspose . Pdf . LogicalStructure . SpanElement span41 = taggedContent . CreateSpanElement ();
Aspose . Pdf . LogicalStructure . SpanElement span411 = taggedContent . CreateSpanElement ();
span411 . SetText ( "Span_411, " );
span41 . SetText ( "Span_41, " );
span41 . AppendChild ( span411 );
Aspose . Pdf . LogicalStructure . SpanElement span42 = taggedContent . CreateSpanElement ();
Aspose . Pdf . LogicalStructure . SpanElement span421 = taggedContent . CreateSpanElement ();
span421 . SetText ( "Span 421 and " );
span42 . AppendChild ( span421 );
span42 . SetText ( "Span_42" );
p4 . AppendChild ( span41 );
p4 . AppendChild ( span42 );
p4 . SetText ( "." );
// Save Tagged PDF Document
document . Save ( outFile );
}
// Checking PDF/UA compliance
using ( var document = new Aspose . Pdf . Document ( outFile ))
{
bool isPdfUaCompliance = document . Validate ( logFile , Aspose . Pdf . PdfFormat . PDF_UA_1 );
Console . WriteLine ( String . Format ( "PDF/UA compliance: {0}" , isPdfUaCompliance ));
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddLinkElement ()
{
// The path to the documents directory
string dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
string outFile = dataDir + "AddStructureElementIntoElement_Output.pdf" ;
string logFile = dataDir + "46144_log.xml" ;
// Creation document and getting Tagged PDF Content
using var document1 = new Aspose . Pdf . Document ();
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document1 . TaggedContent ;
// Setting Title and Nature Language for document
taggedContent . SetTitle ( "Text Elements Example" );
taggedContent . SetLanguage ( "en-US" );
// Getting Root structure element (Document structure element)
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . ParagraphElement p1 = taggedContent . CreateParagraphElement ();
rootElement . AppendChild ( p1 );
Aspose . Pdf . LogicalStructure . SpanElement span11 = taggedContent . CreateSpanElement ();
span11 . SetText ( "Span_11" );
Aspose . Pdf . LogicalStructure . SpanElement span12 = taggedContent . CreateSpanElement ();
span12 . SetText ( " and Span_12." );
p1 . SetText ( "Paragraph with " );
p1 . AppendChild ( span11 );
p1 . AppendChild ( span12 );
Aspose . Pdf . LogicalStructure . ParagraphElement p2 = taggedContent . CreateParagraphElement ();
rootElement . AppendChild ( p2 );
Aspose . Pdf . LogicalStructure . SpanElement span21 = taggedContent . CreateSpanElement ();
span21 . SetText ( "Span_21" );
Aspose . Pdf . LogicalStructure . SpanElement span22 = taggedContent . CreateSpanElement ();
span22 . SetText ( "Span_22." );
p2 . AppendChild ( span21 );
p2 . SetText ( " and " );
p2 . AppendChild ( span22 );
Aspose . Pdf . LogicalStructure . ParagraphElement p3 = taggedContent . CreateParagraphElement ();
rootElement . AppendChild ( p3 );
Aspose . Pdf . LogicalStructure . SpanElement span31 = taggedContent . CreateSpanElement ();
span31 . SetText ( "Span_31" );
Aspose . Pdf . LogicalStructure . SpanElement span32 = taggedContent . CreateSpanElement ();
span32 . SetText ( " and Span_32" );
p3 . AppendChild ( span31 );
p3 . AppendChild ( span32 );
p3 . SetText ( "." );
Aspose . Pdf . LogicalStructure . ParagraphElement p4 = taggedContent . CreateParagraphElement ();
rootElement . AppendChild ( p4 );
Aspose . Pdf . LogicalStructure . SpanElement span41 = taggedContent . CreateSpanElement ();
Aspose . Pdf . LogicalStructure . SpanElement span411 = taggedContent . CreateSpanElement ();
span411 . SetText ( "Span_411, " );
span41 . SetText ( "Span_41, " );
span41 . AppendChild ( span411 );
Aspose . Pdf . LogicalStructure . SpanElement span42 = taggedContent . CreateSpanElement ();
Aspose . Pdf . LogicalStructure . SpanElement span421 = taggedContent . CreateSpanElement ();
span421 . SetText ( "Span 421 and " );
span42 . AppendChild ( span421 );
span42 . SetText ( "Span_42" );
p4 . AppendChild ( span41 );
p4 . AppendChild ( span42 );
p4 . SetText ( "." );
// Save Tagged PDF Document
document1 . Save ( outFile );
// Checking PDF/UA compliance
using var document2 = new Aspose . Pdf . Document ( outFile );
bool isPdfUaCompliance = document2 . Validate ( logFile , Aspose . Pdf . PdfFormat . PDF_UA_1 );
Console . WriteLine ( String . Format ( "PDF/UA compliance: {0}" , isPdfUaCompliance ));
}
Setting Note Structure Element
Aspose.PDF for .NET API also allows you to add NoteElement in a tagged PDF document. Following code snippet shows how to add note element in Tagged PDF Document:
Setting Language and Title
This feature is supported by version 19.6 or greater.
Aspose.PDF for .NET API also allows you to set language and title for a document according to specification PDF/UA. The language can be set up as for whole document as for its separate structural elements. Following code snippet shows how to et language and title in Tagged PDF Document: