Skip to content

Commit

Permalink
wasm: Aligns docs more with latest fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-lemon committed Jul 6, 2023
1 parent 51ffdd9 commit 4c6cd33
Show file tree
Hide file tree
Showing 17 changed files with 423 additions and 98 deletions.
1 change: 1 addition & 0 deletions docs/src/mupdf-js.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Class A-Z Index
- :ref:`PDFWidget<mutool_run_js_api_object_pdf_widget>`
- :ref:`Pixmap<mutool_run_js_api_pixmap>`
- :ref:`Story<mutool_run_js_api_object_story>`
- :ref:`StrokeState<mutool_run_js_api_stroke_state>`
- :ref:`StructuredText<mutool_run_js_api_structured_text>`
- :ref:`Text<mutool_run_js_api_text>`
- :ref:`XML<mutool_run_js_api_object_xml>`
Expand Down
111 changes: 111 additions & 0 deletions docs/src/mupdf-wasm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,117 @@ The following :title:`JavaScript` sample demonstrates how to load a local docume
console.log(doc.countPages());
Creating a PDF
-------------------

The following :title:`JavaScript` sample demonstrates how to create a blank :title:`PDF` file with an assortment of annotations.


.. code-block:: javascript
var fs = require("fs")
var mupdf = require("mupdf")
function createBlankPDF() {
var doc = new mupdf.PDFDocument()
doc.insertPage(0, doc.addPage([0, 0, 595, 842], 0, null, ""))
return doc
}
function savePDF(doc, path, opts) {
fs.writeFileSync(path, doc.saveToBuffer(opts).asUint8Array())
}
try {
var doc = createBlankPDF()
var page = doc.loadPage(0)
var annot
annot = page.createAnnotation("Text")
annot.setRect([200, 10, 250, 50])
annot.setContents("This is a Text annotation!")
annot.setColor([0,0.5,1])
annot = page.createAnnotation("FreeText")
annot.setRect([10, 10, 200, 50])
annot.setContents("This is a FreeText annotation!")
annot.setDefaultAppearance("TiRo", 18, [0])
annot = page.createAnnotation("Circle")
annot.setRect([100, 100, 300, 300])
annot.setColor([0, 1, 1])
annot.setInteriorColor([0.5, 0, 0])
annot.setBorderEffect("Cloudy")
annot.setBorderEffectIntensity(4)
annot.setBorderWidth(10)
annot = page.createAnnotation("Polygon")
annot.setColor([1, 0, 0])
annot.setInteriorColor([1, 1, 0])
annot.addVertex([10, 100])
annot.addVertex([200, 200])
annot.addVertex([30, 300])
annot = page.createAnnotation("Line")
annot.setColor([1, 0, 0])
annot.setInteriorColor([0, 0, 1])
annot.setLine([10, 300], [200, 500])
annot.setLineEndingStyles("None", "ClosedArrow")
annot = page.createAnnotation("Highlight")
annot.setColor([1, 1, 0])
annot.setQuadPoints([
[
80, 70,
190, 70,
80, 90,
190, 90,
]
])
annot = page.createAnnotation("Stamp")
annot.setRect([10, 600, 200, 700])
annot.setAppearance(null, null, mupdf.Matrix.identity, [ 0, 0, 100, 100 ], {}, "0 1 0 rg 10 10 50 50 re f")
annot = page.createAnnotation("Stamp")
annot.setRect([10, 750, 200, 850])
annot.setIcon("TOP SECRET")
annot = page.createAnnotation("FileAttachment")
annot.setRect([300, 10, 350, 60])
annot.setFileSpec(
doc.addEmbeddedFile (
"readme.txt",
"text/plain",
"Lorem ipsum dolor...",
new Date(),
new Date(),
false
)
)
annot = page.createAnnotation("Ink")
annot.setColor([0.5])
annot.setBorderWidth(5)
annot.addInkListStroke()
for (let i = 0; i < 360; i += 5) {
let y = Math.sin(i * Math.PI / 180)
annot.addInkListStrokeVertex([ 200 + i, 700 + y * 50 ])
}
page.createLink([ 500, 20, 590, 40 ], "https://mupdf.com/")
page.createLink([ 500, 40, 590, 60 ], doc.formatLinkURI({ type: "Fit", page: 0 }))
page.update()
savePDF(doc, "out.pdf", "")
} catch (err) {
console.error(err)
process.exit(1)
}
Trying the Viewer
--------------------------

Expand Down
8 changes: 0 additions & 8 deletions docs/src/mutool-object-color-space.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
.. method:: isGray()

|mutool_tag|

Returns true if the object is a gray color space.

Expand All @@ -107,7 +106,6 @@
.. method:: isRGB()

|mutool_tag|

Returns true if the object is an RGB color space.

Expand All @@ -120,7 +118,6 @@
.. method:: isCMYK()

|mutool_tag|

Returns true if the object is a CMYK color space.

Expand All @@ -132,7 +129,6 @@
.. method:: isIndexed()

|mutool_tag|

Returns true if the object is an Indexed color space.

Expand All @@ -144,7 +140,6 @@
.. method:: isLab()

|mutool_tag|

Returns true if the object is a Lab color space.

Expand All @@ -156,7 +151,6 @@
.. method:: isDeviceN()

|mutool_tag|

Returns true if the object is a Device N color space.

Expand All @@ -170,7 +164,6 @@
.. method:: isSubtractive()

|mutool_tag|

Returns true if the object is a subtractive color space.

Expand All @@ -184,7 +177,6 @@
.. method:: getType()

|wasm_tag|

Returns a string indicating the type.

Expand Down
29 changes: 8 additions & 21 deletions docs/src/mutool-object-device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.

.. method:: fillPath(path, evenOdd, transform, colorspace, color, alpha, colorParams)

|mutool_tag_wasm_soon|

Fill a path.

Expand All @@ -52,12 +51,11 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: strokePath(path, stroke, transform, colorspace, color, alpha, colorParams)

|mutool_tag_wasm_soon|

Stroke a path.

:arg path: `Path` object.
:arg stroke: The :ref:`stroke dictionary<mutool_run_js_api_stroke_dictionary>`.
:arg stroke: `StrokeState` The :ref:`stroke state object<mutool_object_stroke_state>`.
:arg transform: `[a,b,c,d,e,f]`. The transform :ref:`matrix<mutool_run_js_api_matrix>`.
:arg colorspace: The :ref:`ColorSpace<mutool_run_javascript_api_colorspace>`.
:arg color: The :ref:`color value<mutool_run_js_api_colors>`.
Expand All @@ -79,7 +77,6 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: clipPath(path, evenOdd, transform)

|mutool_tag_wasm_soon|

Clip a path.

Expand All @@ -98,12 +95,11 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: clipStrokePath(path, stroke, transform)

|mutool_tag_wasm_soon|

Clip & stroke a path.

:arg path: `Path` object.
:arg stroke: The :ref:`stroke dictionary<mutool_run_js_api_stroke_dictionary>`.
:arg stroke: `StrokeState` The :ref:`stroke state object<mutool_object_stroke_state>`.
:arg transform: `[a,b,c,d,e,f]`. The transform :ref:`matrix<mutool_run_js_api_matrix>`.

|example_tag|
Expand All @@ -117,7 +113,6 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: fillText(text, transform, colorspace, color, alpha, colorParams)

|mutool_tag_wasm_soon|

Fill a text object.

Expand All @@ -136,12 +131,11 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: strokeText(text, stroke, transform, colorspace, color, alpha, colorParams)

|mutool_tag_wasm_soon|

Stroke a text object.

:arg text: `Text` object.
:arg stroke: The :ref:`stroke dictionary<mutool_run_js_api_stroke_dictionary>`.
:arg stroke: `StrokeState` The :ref:`stroke state object<mutool_object_stroke_state>`.
:arg transform: `[a,b,c,d,e,f]`. The transform :ref:`matrix<mutool_run_js_api_matrix>`.
:arg colorspace: The :ref:`ColorSpace<mutool_run_javascript_api_colorspace>`.
:arg color: The :ref:`color value<mutool_run_js_api_colors>`.
Expand All @@ -161,7 +155,6 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: clipText(text, transform)

|mutool_tag_wasm_soon|

Clip a text object.

Expand All @@ -177,12 +170,11 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: clipStrokeText(text, stroke, transform)

|mutool_tag_wasm_soon|

Clip & stroke a text object.

:arg text: `Text` object.
:arg stroke: The :ref:`stroke dictionary<mutool_run_js_api_stroke_dictionary>`.
:arg stroke: `StrokeState` The :ref:`stroke state object<mutool_object_stroke_state>`.
:arg transform: `[a,b,c,d,e,f]`. The transform :ref:`matrix<mutool_run_js_api_matrix>`.

|example_tag|
Expand All @@ -195,7 +187,6 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: ignoreText(text, transform)

|mutool_tag_wasm_soon|

Invisible text that can be searched but should not be visible, such as for overlaying a scanned OCR image.

Expand Down Expand Up @@ -235,7 +226,6 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: fillImage(image, transform, alpha, colorParams)

|mutool_tag_wasm_soon|

Draw an image. An image always fills a unit rectangle `[0,0,1,1]`, so must be transformed to be placed and drawn at the appropriate size.

Expand All @@ -255,7 +245,6 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: fillImageMask(image, transform, colorspace, color, alpha, colorParams)

|mutool_tag_wasm_soon|

An image mask is an image without color. Fill with the color where the image is opaque.

Expand All @@ -277,7 +266,6 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: clipImageMask(image, transform)

|mutool_tag_wasm_soon|

Clip graphics using the image to mask the areas to be drawn.

Expand Down Expand Up @@ -305,7 +293,6 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: beginMask(area, luminosity, backdropColorspace, backdropColor, backdropAlpha, colorParams)

|mutool_tag_wasm_soon|

Create a soft mask. Any drawing commands between `beginMask` and `endMask` are grouped and used as a clip mask.

Expand Down Expand Up @@ -337,13 +324,13 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.
.. method:: beginGroup(area, isolated, knockout, blendmode, alpha)
.. method:: beginGroup(area, colorspace, isolated, knockout, blendmode, alpha)

|mutool_tag_wasm_soon|

Push/pop a transparency blending group. See the PDF reference for details on `isolated` and `knockout`.

:arg area: `Path` Blend area.
:arg area: `[ulx,uly,lrx,lry]` :ref:`Rectangle<mutool_run_js_api_rectangle>`. The blend area.
:arg colorspace: :ref:`ColorSpace<mutool_run_javascript_api_colorspace>`.
:arg isolated: `Boolean`.
:arg knockout: `Boolean`.
:arg blendmode: Blendmode is one of the standard :title:`PDF` blend modes: "Normal", "Multiply", "Screen", etc.
Expand All @@ -359,7 +346,7 @@ The methods that clip graphics must be balanced with a corresponding `popClip`.

.. code-block:: javascript
device.beginGroup(path, true, true, "Multiply", 0.5);
device.beginGroup([0,0,100,100], mupdf.ColorSpace.DeviceRGB, true, true, "Multiply", 0.5);
Expand Down
1 change: 0 additions & 1 deletion docs/src/mutool-object-display-list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ A display list records all the device calls for playback later. If you want to r
.. method:: search(needle)

|mutool_tag_wasm_soon|

Search the display list text for all instances of the `needle` value, and return an array of search hits. Each search hit is an array of :ref:`rectangles<mutool_run_js_api_quad>` corresponding to all characters in the search hit.

Expand Down
Loading

0 comments on commit 4c6cd33

Please sign in to comment.