I test this by using the PAC accessibility checker (you can search for "PAC 2021", it should be the first result).
The following code results in a PDF with a link, but I can't seem to do the right thing to resolve the error the PAC checker shows. It says ""Link" annotation is not nested inside a "Link" structure element".
- Code: Select all
FileStream to_stream = new FileStream(@"Output\Testfile.pdf", FileMode.OpenOrCreate);
var pdf = new PdfDocument();
pdf.PageSettings.Size = PdfPageSize.A4;
pdf.PageSettings.Margins.All = 0;
string fontFileName = @"Resources\Font\Linotype - Helvetica LT Pro.ttf";
var helveticaRegular = new PdfTrueTypeFont(fontFileName, 11f);
PdfSection section = pdf.Sections.Add();
PdfPageBase page = section.Pages.Add();
var taggedContent = new PdfTaggedContent(pdf);
var documentStructure = taggedContent.StructureTreeRoot.AppendChildElement(PdfStandardStructTypes.Document);
var divStructure = documentStructure.AppendChildElement(PdfStandardStructTypes.Division);
var linkStructure = divStructure.AppendChildElement(PdfStandardStructTypes.Link);
var annotationStructure = linkStructure.AppendChildElement(PdfStandardStructTypes.Annotation);
annotationStructure.Title = "Annotation";
linkStructure.BeginMarkedContent(page);
var text = "Text";
var destination = new PdfDestination(page, new PointF(10, 200));
var bookmark = pdf.Bookmarks.Add("bookmark");
bookmark.Action = new PdfGoToAction(destination);
var linkAnnotation = new PdfActionAnnotation(new RectangleF(10, 10, 23, 10), bookmark.Action);
linkAnnotation.Text = "Link to bookmark";
page.Annotations.Add(linkAnnotation);
PdfBrush brush = new PdfSolidBrush(new PdfRGBColor(Color.Black));
PdfUnitConvertor convertor = new PdfUnitConvertor();
page.Canvas.DrawString(text, helveticaRegular, brush, 10, 10);
linkStructure.EndMarkedContent(page);
pdf.SaveToStream(to_stream);
pdf.Close();
Can you tell me how I can nest the link annotation inside the Link structure element?