Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessibility Issues with PDF Content Order #271

Open
zahin-zaman-agilebits opened this issue Oct 18, 2023 · 1 comment
Open

Accessibility Issues with PDF Content Order #271

zahin-zaman-agilebits opened this issue Oct 18, 2023 · 1 comment

Comments

@zahin-zaman-agilebits
Copy link

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:

Screenshot 2023-10-18 at 10 36 40 AM

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:

my.pdf

@vikraman-alea-bah
Copy link

We need accessibility options as well, is goPDF considering adding accessible features for accessibility tags?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants