From be47e1a25e03374f2c531f47e7fd1cb617abbd80 Mon Sep 17 00:00:00 2001 From: "Jorj X. McKie" Date: Tue, 11 Feb 2025 09:02:30 -0400 Subject: [PATCH] Remove obsolete recipe This recipe no longer reflects the current situation. --- docs/recipes-annotations.rst | 13 ------- docs/samples/make-bold.py | 75 ------------------------------------ 2 files changed, 88 deletions(-) delete mode 100644 docs/samples/make-bold.py diff --git a/docs/recipes-annotations.rst b/docs/recipes-annotations.rst index da5340e42..84e42f62e 100644 --- a/docs/recipes-annotations.rst +++ b/docs/recipes-annotations.rst @@ -57,19 +57,6 @@ The result looks like this: - -Using Buttons and JavaScript -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Since MuPDF v1.16, 'FreeText' annotations no longer support bold or italic versions of the Times-Roman, Helvetica or Courier fonts. - -A big **thank you** to our user `@kurokawaikki `_, who contributed the following script to **circumvent this restriction**. - -.. literalinclude:: samples/make-bold.py - :language: python - --------------------------- - - .. _RecipesAnnotations_C: How to Use Ink Annotations diff --git a/docs/samples/make-bold.py b/docs/samples/make-bold.py deleted file mode 100644 index bdebc03da..000000000 --- a/docs/samples/make-bold.py +++ /dev/null @@ -1,75 +0,0 @@ -""" -Problem: Since MuPDF v1.16 a 'Freetext' annotation font is restricted to the -"normal" versions (no bold, no italics) of Times-Roman, Helvetica, Courier. -It is impossible to use PyMuPDF to modify this. - -Solution: Using Adobe's JavaScript API, it is possible to manipulate properties -of Freetext annotations. Check out these references: -https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_api_reference.pdf, -or https://www.adobe.com/devnet/acrobat/documentation.html. - -Function 'this.getAnnots()' will return all annotations as an array. We loop -over this array to set the properties of the text through the 'richContents' -attribute. -There is no explicit property to set text to bold, but it is possible to set -fontWeight=800 (400 is the normal size) of richContents. -Other attributes, like color, italics, etc. can also be set via richContents. - -If we have 'FreeText' annotations created with PyMuPDF, we can make use of this -JavaScript feature to modify the font - thus circumventing the above restriction. - -Use PyMuPDF v1.16.12 to create a push button that executes a Javascript -containing the desired code. This is what this program does. -Then open the resulting file with Adobe reader (!). -After clicking on the button, all Freetext annotations will be bold, and the -file can be saved. -If desired, the button can be removed again, using free tools like PyMuPDF or -PDF XChange editor. - -Note / Caution: ---------------- -The JavaScript will **only** work if the file is opened with Adobe Acrobat reader! -When using other PDF viewers, the reaction is unforeseeable. -""" -import sys - -import pymupdf - -# this JavaScript will execute when the button is clicked: -jscript = """ -var annt = this.getAnnots(); -annt.forEach(function (item, index) { - try { - var span = item.richContents; - span.forEach(function (it, dx) { - it.fontWeight = 800; - }) - item.richContents = span; - } catch (err) {} -}); -app.alert('Done'); -""" -i_fn = sys.argv[1] # input file name -o_fn = "bold-" + i_fn # output filename -doc = pymupdf.open(i_fn) # open input -page = doc[0] # get desired page - -# ------------------------------------------------ -# make a push button for invoking the JavaScript -# ------------------------------------------------ - -widget = pymupdf.Widget() # create widget - -# make it a 'PushButton' -widget.field_type = pymupdf.PDF_WIDGET_TYPE_BUTTON -widget.field_flags = pymupdf.PDF_BTN_FIELD_IS_PUSHBUTTON - -widget.rect = pymupdf.Rect(5, 5, 20, 20) # button position - -widget.script = jscript # fill in JavaScript source text -widget.field_name = "Make bold" # arbitrary name -widget.field_value = "Off" # arbitrary value -widget.fill_color = (0, 0, 1) # make button visible - -annot = page.add_widget(widget) # add the widget to the page -doc.save(o_fn) # output the file