Close

Text editing

A project log for PDF Merge

Overlay synchronized spreadsheet calculations on PDF forms

lion-mclionheadlion mclionhead 10/19/2023 at 07:240 Comments

The mane problem is it needs to show both spreadsheet cells & arbitrary text so a text editing widget is required.  Making a custom text editing widget with the full WYSIWYG, arbitrary font, highlighting, clipboard, arbitrary positions on the PDF was an unpleasant prospect.   The text editing in goog sheets is an impressive feat of javascript.  Lions just don't have the budget to create such a thing & it's just not a heavily used enough app.

Much easier would be Gimp's original text tool, which required text entry in a standard GTK window while it drew the formatted text on the image.  There would be a compromise where the user highlighted text areas on the PDF but only edited text in the editing area.

Then, basically you have a drawable with the full res PDF baked on & a bunch of drawables for each full res text object which can quickly be drawn on.  This can be zoomed & scrolled.

According to the GPT, off screen buffers in javascript are canvases.  You've got  document.createElement('canvas'); for creating unlimited buffers.

Then they're drawn on the same as on screen canvases & blitted like images.

1 problem is PDF.js can't change zoom on a single page without fetching & decoding the entire file again.  It seemed acceptable for files up to 13MB.  

A tedious process led to a minimal set of text editing commands.  The key word is minimal, yet even the minimal set is pretty comprehensive. Lions remembered the fascination with being able to draw a lasso box, move groups of objects, drag a document view around, 40 years ago.  What was remarkable then is now minimal functionality.

 The mane trick with this is differentiating user text from PDF text.  The lion kingdom settled on drawing boxes around user text.  It relies on a print mode to hide the boxes.  Selected text objects are red.   An artifact is that it can have text outside the PDF.  The most common way of changing the font size is wheeling over the size text.  The font is hard coded.

The wrench in this plan is the need to reload to renew an access token.  The easiest solution is to automatically save after the access token fails & before loading the consent URL.  Most programs asynchronously save every few seconds, but that would entail tons of locking.  A minimal program can just require the user to save.

Discussions