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

Using an added unicode font results in broken PDF #3245

Closed
popobol opened this issue Aug 30, 2021 · 1 comment
Closed

Using an added unicode font results in broken PDF #3245

popobol opened this issue Aug 30, 2021 · 1 comment

Comments

@popobol
Copy link

popobol commented Aug 30, 2021

Description

(Moved from svg2pdf.js issue 190 tracker, as it is happens to be unrelated to the SVG layer.)

Using an added unicode font in SVG results in broken PDF. There are no warnings or errors logged in the console.

On Windows, Adobe Reader says "There as an error processing a page. There as a problem reading this document (135)". Sumatra displays a blank page or unrelated characters in an unrelated font (pdf default serif?).
On macOS Big Sur 11.5.2, "Preview" displays a blank page.

Various PDF tools report problems with the file. E.g.
pdfunite : "Syntax Error: Dictionary key must be a name object"
mutool : "error: invalid key in dict"
gs -sDEVICE=pdfwrite : "Error: obj definition followed by multiple tokens"
etc.

However, the PDF renders correctly with anything Poppler-based on Linux or with PDF readers built into Firefox or Chrome browsers.

Using version jspdf.umd.js : 2.3.1

To reproduce

HTML

<!DOCTYPE html>

<head>
    <meta charset="UTF-8">
</head>

<body>
    <script src="../../../current/lib.js/nih/jspdf/jspdf.umd.js"></script>
    <script src="../../../current/lib.js/nih/fonts/LiberationSans-Bold-bold.js"></script>
    <script src="asypdf-bare.js" defer></script>
</body>

asypdf-bare.js

const { jsPDF } = window.jspdf;

var pageWidth = 85.6,
    pageHeight = 53.98;
var pdf = new jsPDF('l', 'mm', [pageWidth, pageHeight], true);

pdf.setFont('Liberation Sans', 'bold');
pdf.text(5, 5, 'wazzat?');
pdf.save('result.pdf');

The UMD "LiberationSans-Bold-bold.js" (LiberationSans-Bold-bold.js.zip attached) was generated with jsPDF fontconverter tool from a TTF coming with default Xubuntu installation. The behaviour is the same with Free Sans, or Noto Sans fonts.

The behaviour is the same with other PDF page sizes.

If an additional font is not loaded, or when using default fonts, the PDF renders just fine.

Platform

  • OS: Xubuntu 20.04
  • Browser: Firefox 91.0.2, Chromium Ungoogled 91.0.4472.77
@HackbrettXXX
Copy link
Collaborator

I've just figured out why it fails: there is a space in the font name. This issue has been fixed already in #3149 and there will be a new release within the next days.

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