[Bug]: FreeText annotations with Czech characters lose accented letters when exported with `saveAsCopy()`

Aperta
#901 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, typescript

Direzione di ricerca

Start by running the reproduction testbed linked in the issue with @embedpdf/snippet@2, then trace how exportPlugin.saveAsCopy() serializes FreeText annotation text and its font into the exported PDF. Compare the exported text stream with the original Czech pangram to locate where characters are dropped. Done when the exported PDF preserves all listed Czech characters in standard PDF viewers; the issue names no source files or tests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

When I export a document containing FreeText annotations with Czech characters using exportPlugin.saveAsCopy(), several accented letters disappear in external PDF viewers (such as Google Chrome or Okular).

For example, typing the Czech pangram:

Příliš žluťoučký kůň úpěl ďábelské ódy (č, š, ž, ř, ď, ť, ň, ě, ů)

renders in the exported PDF as:

Píliš žluouký k úpl ábelské ódy (, š, ž, , , , , , )

I am not an expert on the PDF format internals, but encoding of Czech characters seems to be broken, perhaps UTF-8 is not supported in the exported font?


Environment

  • @embedpdf/snippet@2
  • Export method: exportPlugin.saveAsCopy()
  • Viewers tested:
    • Google Chrome
    • Firefox
    • Okular

Steps to Reproduce

You can run the standalone reproduction testbed reproduce_issue.html or run the following snippet:

<!DOCTYPE html>
<html>
<body>
  <div id="pdf-viewer" style="width: 100vw; height: 100vh;"></div>
  <script type="module">
    import EmbedPDF from 'https://cdn.jsdelivr.net/npm/@embedpdf/snippet@2/dist/embedpdf.js';

    const viewer = EmbedPDF.init({
      type: 'container',
      target: document.getElementById('pdf-viewer'),
      src: '/sample.pdf'
    });

    const registry = await viewer.registry;
    const annotationApi = registry.getPlugin('annotation').provides();
    const exportPlugin = registry.getPlugin('export').provides();

    // 1. Add a FreeText annotation with Czech characters
    await annotationApi.importAnnotations([
      {
        annotation: {
          id: 'czech-pangram',
          type: 3, // FREETEXT
          pageIndex: 0,
          contents: 'Příliš žluťoučký kůň úpěl ďábelské ódy (č, š, ž, ř, ď, ť, ň, ě, ů)',
          rect: {
            origin: { x: 50, y: 180 },
            size: { width: 480, height: 50 }
          },
          fontSize: 14,
          fontColor: '#000000'
        }
      }
    ]);

    // 2. Export the PDF
    const arrayBuffer = await exportPlugin.saveAsCopy().toPromise();

    // 3. Download the PDF and open it in Chrome, Acrobat, or Preview
    const blob = new Blob([arrayBuffer], { type: 'application/pdf' });
    const url = URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = 'exported.pdf';
    a.click();
  </script>
</body>
</html>

What I See (Observed Results)

  1. Inside the EmbedPDF web viewer, the text displays completely fine with all Czech diacritics visible.
  2. When downloading the exported PDF and opening it in any standard viewer (Chrome, Acrobat Reader, Apple Preview, etc.):
    • Original input: Příliš žluťoučký kůň úpěl ďábelské ódy (č, š, ž, ř, ď, ť, ň, ě, ů)
    • Rendered in PDF: Píliš žluouký k úpl ábelské ódy (, š, ž, , , , , , )
  3. Notice that letters like š and ž are kept, but letters like č, ř, ď, ť, ň, ě, ů are completely dropped.
  4. When inspecting the raw PDF text rendering stream in Python (pypdf), the missing letters appear to be completely omitted from the text stream:
    (P) Tj               % Missing 'ř' (from 'Příliš') -> rendered as 'Píliš'
    (\xedli\x9a \x9elu) Tj
    (ou) Tj              % Missing 'ť' and 'č' (from 'žluťoučký') -> rendered as 'žluou'
    (k\xfd k) Tj
    ( \xfap) Tj
    (l ) Tj              % Missing 'ě' (from 'úpěl') -> rendered as 'úp l'
    (\xe1belsk\xe9 \xf3dy \() Tj % Missing 'ď' (from 'ďábelské') -> rendered as 'ábelské'
    (, \x9a, \x9e, ) Tj  % Only 'š' and 'ž' exist; 'č' is dropped
    (, ) Tj              % Missing 'ř'
    (, ) Tj              % Missing 'ď'
    (, ) Tj              % Missing 'ť'
    (, ) Tj              % Missing 'ň'
    (, ) Tj              % Missing 'ě'
    (, ) Tj              % Missing 'ů'
    (\)) Tj
    

Expected Behavior

The exported PDF should display all characters typed into the text annotation, including all Czech letters and diacritics (č, ř, ď, ť, ň, ě, ů), just like they look inside the web viewer.

Files

exported.pdf
reproduce_issue.html
sample.pdf

Lingua principale
TypeScript
Stelle
4.5k
Fork
317
Merge medio
10h 16m
PR unite (30g)
174

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di embedpdf/embed-pdf-viewer

Tutte le issue di embedpdf/embed-pdf-viewer

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.