Accessibility Issues with PDF Content Order
zahin-zaman-agilebits opened this issue · 3 comments
There seems to be some ordering issues with PDFs generated using this library, the order in which screen readers read the PDF contents is not what we'd expect. Here's an example:
package main
import (
"fmt"
"github.com/signintech/gopdf"
)
func main() {
pdf := gopdf.GoPdf{}
pdf.SetMargins(5, 5, 5, 5)
pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4})
pdf.AddPage()
err := pdf.AddTTFFont("Arial", "fonts/Arial.ttf")
if err != nil {
fmt.Println(err)
return
}
err = pdf.SetFont("Arial", "", 14)
if err != nil {
fmt.Println(err)
return
}
x := pdf.GetX()
pdf.CellWithOption(&gopdf.Rect{W: 350}, "Foo", gopdf.CellOption{Align: gopdf.Left})
pdf.SetX(x)
pdf.SetY(pdf.GetY() + 100)
pdf.CellWithOption(&gopdf.Rect{W: 350}, "Bar", gopdf.CellOption{Align: gopdf.Right})
pdf.SetX(x)
pdf.SetY(pdf.GetY() + 100)
pdf.CellWithOption(&gopdf.Rect{W: 350}, "Spam", gopdf.CellOption{Align: gopdf.Left})
pdf.SetX(x)
pdf.SetY(pdf.GetY() + 100)
pdf.CellWithOption(&gopdf.Rect{W: 350}, "Eggs", gopdf.CellOption{Align: gopdf.Center})
pdf.WritePdf("my.pdf")
}
This code generates the following PDF:
A good way to check order is to select all the text and notice in what order the text gets selected. Doing so you'll notice that Spam
and Eggs
are selected before Bar
. If I select all text (using Ctrl/Cmd + A) and paste it somewhere, this is the order I see:
Foo
Spam
Eggs
Bar
Of course, visually, I would expect this order to be:
Foo
Bar
Spam
Eggs
I think fixing this involves the usage of ordering PDF tags properly, and I don't think this library currently supports that.
Here's the generated PDF file:
We need accessibility options as well, is goPDF considering adding accessible features for accessibility tags?
@zahin-zaman-agilebits I copied and pasted it from your generated PDF and got
Foo
Bar
Spam
Eggs
seems like this isn't an issue anymore
@vantaboard thanks, yepp I can confirm this isn't an issue anymore.