PDF tags are used to define the physical structure or layout of the content within a PDF document. PDF tags can help with the specific reading order of different elements on the page. This is especially useful when the PDF is being read by a screen-reader device (which may be used by blind or disabled users).
Within the DynamicPDF API, a Document can be specified as tagged by creating a TagOptions object and setting that equal to the Document's Tag property. PDF Tagging can either be done manually (where a specific type of tag is created and added to the Tag property of each PageElement) or tags can be automatically generated by DynamicPDF (tags will be generated automatically if nothing has been specified for a Page Elements Tag property). Additionally, all Images must provide text in the AlternateText property.
The below example demonstrates how to create a tagged PDF with a few simple page elements (an image and a page number label). For an example that demonstrates even more tagged elements on a PDF document, take a look at the "TaggerPdfWithStructureElements" example included with the download of our product.
[Java]
// Create a PDF document
Document document = new Document();
// Specify document as a tagged PDF
document.setTag = new TagOptions(true);
// Create a Page and add it to the document
Page page = new Page();
document.getPages().add( page );
// Create an image
Image image = new Image(Server.MapPath("../Images/DPDFLogo.png"), 180f, 150f, 0.24f);
image.setHeight(200);
image.setWidth(200);
// Create a structure element
StructureElement imageStructureElement = new StructureElement(TagType.Figure);
imageStructureElement.setIncludeDefaultAttributes(true);
imageStructureElement.setAlternateText("DynamicPDF Logo");
// Set structure element to the image
image.setTag(imageStructureElement);
// Add image to the page
page.getElements().add(image);
// Create a Page numbering label
PageNumberingLabel pageNumberingLabel = new PageNumberingLabel("Page %%cp%% of %%tp%%", 0, 680, 512, 12, Font.Helvetica, 12, TextAlign.Center);
// Create a artifact and add type
Artifact artifact = new Artifact();
artifact.setType(ArtifactType.Pagination);
// Set artifact to the page numbering label
pageNumberingLabel.setTag(artifact);
// Add page numbering label to the page
page.getElements().add(pageNumberingLabel);
document.draw("[PhysicalPath]/MyDocument.pdf");