[Bug]: Exported annotations are completely invisible in Mobile Chrome (pen, highlighter, shapes via `saveAsCopy()`)

Aperta
#900 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
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, typescript
Ambito
api, backend

Direzione di ricerca

Start by reading the export plugin entry point and the annotation export code that handles saveAsCopy(), then inspect the attached exported PDF for how its annotations are serialized. Compare the exported annotations with PDF viewer expectations for appearance streams and check existing export tests. Done means exported ink, highlighter, text, and shape annotations render with their intended appearance in Chrome and Firefox as well as Acrobat.

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

Descrizione

Summary

When I export a document containing annotations (pen drawings, highlighters, text notes, shapes) using exportPlugin.saveAsCopy(), the exported PDF renders inconsistently across different PDF viewers:

  1. Mobile Chrome (Android & iOS): All annotations are completely invisible. The document opens, but none of the drawn pen strokes, highlighters, or markings show up at all.
  2. Desktop Adobe Acrobat: Looks as it should.

I am not an expert on the PDF format internals, but from inspecting the generated PDF structure, I suspect this might be due to a missing /AP (appearance stream) on the exported annotations, causing viewers without built-in fallback renderers (like mobile Chrome) to ignore them entirely.


Environment

  • @embedpdf/snippet@2
  • Export method: exportPlugin.saveAsCopy()
  • Viewers tested:
    • Google Chrome on Android (annotations completely invisible)
    • Desktop Adobe Acrobat -- all good

Tested Annotation Types

This affects multiple annotation and pen types created in EmbedPDF:

  • Ink (Pen): Freehand pen drawings (red, blue, etc.)
  • Ink Highlighter: Translucent highlighter strokes
  • FreeText: Text notes
  • Shapes: Lines, rectangles, and circles

Steps to Reproduce

You can run the standalone testbed reproduce_issue.html or use 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. Draw or import ink / highlighter / text annotations
    await annotationApi.importAnnotations([
      {
        annotation: {
          id: 'pen-red',
          type: 15,
          pageIndex: 0,
          rect: { origin: { x: 80, y: 80 }, size: { width: 260, height: 60 } },
          inkList: [{ points: [{ x: 80, y: 80 }, { x: 160, y: 140 }, { x: 240, y: 80 }, { x: 340, y: 140 }] }],
          strokeWidth: 4,
          strokeColor: '#E44234',
          opacity: 1.0
        }
      },
      {
        annotation: {
          id: 'highlighter-yellow',
          type: 15,
          pageIndex: 0,
          intent: 'InkHighlight',
          rect: { origin: { x: 80, y: 220 }, size: { width: 320, height: 26 } },
          inkList: [{ points: [{ x: 80, y: 233 }, { x: 400, y: 233 }] }],
          strokeWidth: 22,
          strokeColor: '#FFCD45',
          opacity: 0.5
        }
      }
    ]);

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

    // 3. Download the PDF and open it on an Android phone in Chrome
    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, all pen strokes, highlighters, and text look great and render exactly as expected.
  2. When clicking export and opening the downloaded file:
    • On Chrome on Android: The PDF opens normally, but none of the pen or highlighter strokes are shown. The page looks completely blank/unmarked.
    • On Firefox: The highlighters and pen strokes appear as thin 1px lines instead of their drawn thickness.
  3. When inspecting the exported PDF with a parser tool (pypdf), I see:
    Annot: Subtype=/Ink, NM=pen-red
      Has /AP: False (or missing appearance stream)
    
    It seems like without an /AP entry, mobile viewers don't know how to draw the strokes, so they just ignore them.

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.