Skip to content
 
 

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fpdf-asp

ASP (classic) version of fpdf for PHP with accessibility tags.

Here's how to add certain accessibility tags to your existing PDF generation logic when pursuing WCAG compliance (an understanding of relevant portions of the PDF specification is recommended; the inline documentation uses PDF Reference, sixth edition, Adobe Portable Document Format version 1.7, November 2006):

  1. Change the include file from fpdf.asp to fpdf_tagged.asp.
  2. Change the created object from FPDF to FPDFTagged:
    Dim PDFWriter
    Set PDFWriter = CreateJsObject("FPDFTagged")
  3. Before your first usage of marked content, initialize the Document top-level tag:
    Dim StructureDocument
    Set StructureDocument = PDFWriter.InitializeMarkedContent()
  4. Add tags according to the following:
    • Surround your flat Cell or Write calls with the corresponding tag:
      Const CellHeight = 5
      Dim StructureHeadingOne
      Set StructureHeadingOne = PDFWriter.StartMarkedContent("H1")
      Call PDFWriter.Cell(0, CellHeight, "Document Title", 0, 0, "R", False, "")
      Call PDFWriter.FinishMarkedContent()
      Call StructureDocument.AppendNode(StructureHeadingOne)
    • Wrap line breaks with nested marked content:
      Dim StructureParagraph
      Set StructureParagraph = PDFWriter.StartMarkedContent("P")
      Call PDFWriter.Write(TextHeight, "Sam Pull", "")
      Call PDFWriter.StartLineBreakMarkedContent()
      Call PDFWriter.Ln("")
      Call PDFWriter.FinishMarkedContent()
      Call PDFWriter.Write(TextHeight, "123 Any St", "")
      Call PDFWriter.StartLineBreakMarkedContent()
      Call PDFWriter.Ln("")
      Call PDFWriter.FinishMarkedContent()
      Call PDFWriter.Write(TextHeight, "Anywhere, MA  01234", "")
      Call PDFWriter.FinishMarkedContent()
      Call StructureDocument.AppendNode(StructureParagraph)
    • Mark decorative lines as an artifact:
      Dim LeftMarginX
      LeftMarginX = PDFWriter.GetX()
      Call PDFWriter.SetX(-1)
      Dim PageBodyWidth
      PageBodyWidth = PDFWriter.GetX() + 1 - LeftMarginX - LeftMarginX
      Dim RightMarginX
      RightMarginX = PageBodyWidth + LeftMarginX ' Approximation for right margin.
      Call PDFWriter.StartArtifactLayoutMarkedContent()
      Call PDFWriter.Line(LeftMarginX, PDFWriter.GetY(), RightMarginX, PDFWriter.GetY())
      Call PDFWriter.FinishMarkedContent()
    • Tag images as figures by changing Image calls to ImageTagged and providing the marked content object:
      Dim StructureLogo
      Set StructureLogo = PDFWriter.StartMarkedContent("Figure")
      Call PDFWriter.ImageTagged("/logo.jpg", PDFWriter.GetX(), PDFWriter.GetY(), 30, 30, "JPEG", "", StructureLogo)
      Call PDFWriter.FinishMarkedContent()
      Call StructureLogo.SetAlternativeText("Organization logo.")
      Call StructureDocument.AppendNode(StructureLogo)
    • Create tables using structure elements:
      Const CellHeight = 30
      Const CellHeight = 5
      
      Dim StructureTable
      Set StructureTable = PDFWriter.CreateStructureElement("Table")
      Call StructureDocument.AppendNode(StructureTable)
      Dim StructureRow
      Set StructureRow = PDFWriter.CreateStructureElement("TR")
      Call StructureTable.AppendNode(StructureRow)
      Dim StructureCell
      
      Set StructureCell = PDFWriter.StartMarkedContent("TH")
      Call PDFWriter.ApplyStructureElementAttributesForTableHeaderScopeColumn(StructureCell)
      Call PDFWriter.Cell(CellWidth, CellHeight, "Cell Header", "B", 0, "L", True, "")
      Call PDFWriter.FinishMarkedContent()
      Call StructureRow.AppendNode(StructureCell)
      
      Set StructureRow = PDFWriter.CreateStructureElement("TR")
      Call StructureTable.AppendNode(StructureRow)
      
      Set StructureCell = PDFWriter.StartMarkedContent("TD")
      Call PDFWriter.Cell(CellWidth, CellHeight, "Cell Value", 0, 0, "L", True, "")
      Call PDFWriter.FinishMarkedContent()
      Call StructureRow.AppendNode(StructureCell)
    • Create lists using structure elements:
      Dim LeftMarginX
      LeftMarginX = PDFWriter.GetX()
      Call PDFWriter.SetX(-1)
      Dim PageBodyWidth
      PageBodyWidth = PDFWriter.GetX() + 1 - LeftMarginX - LeftMarginX
      Dim ListItemX
      ListItemX = PageBodyWidth * 0.1
      
      Const TextHeight = 5
      
      Dim StructureList
      Set StructureList = PDFWriter.CreateStructureElement("L")
      Call PDFWriter.ApplyStructureElementAttributesForList(StructureList, "Decimal")
      
      Dim StructureListItem
      Set StructureListItem = PDFWriter.CreateStructureElement("LI")
      Dim StructureListItemLabel
      Set StructureListItemLabel = PDFWriter.StartMarkedContent("Lbl")
      Call PDFWriter.Write(TextHeight, "1.", "")
      Call PDFWriter.FinishMarkedContent()
      Call StructureListItem.AppendNode(StructureListItemLabel)
      Call PDFWriter.SetX(ListItemX)
      Call PDFWriter.SetLeftMargin(ListItemX)
      Dim StructureListItemBody
      Set StructureListItemBody = PDFWriter.StartMarkedContent("LBody")
      Call PDFWriter.Write(TextHeight, "This is the first list item.", "")
      Call PDFWriter.FinishMarkedContent()
      Call StructureListItem.AppendNode(StructureListItemBody)
      Call StructureList.AppendNode(StructureListItem)
      Call PDFWriter.SetLeftMargin(LeftMarginX)
      Call PDFWriter.Ln("")
      
      Call StructureDocument.AppendNode(StructureList)

Hyperlinks aren't covered because the core engine renders the Annot dictionaries inline, so they aren't allocated an object ID for referencing from structure elements.

Acknowledgements

About

ASP (classic) version of fpdf for PHP with accessibility tags

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages