DocumentWriter

DocumentWriter objects are used to create new documents in several formats.

new DocumentWriter(filename, format, options)

mutool only

Constructor method.

Create a new document writer to create a document with the specified format and output options. If format is null it is inferred from the filename extension. The options argument is a comma separated list of flags and key-value pairs.

The output format & options are the same as in the mutool convert command.

Arguments:
  • filename – The file name to output to.

  • format – The file format.

  • options – The options as key-value pairs.

Returns:

DocumentWriter.

EXAMPLE

var writer = new mupdf.DocumentWriter("out.pdf", "PDF", "");
new DocumentWriter(buffer, format, options)

wasm only

Constructor method.

Create a new document writer to create a document with the specified format and output options. The options argument is a comma separated list of flags and key-value pairs.

The output format & options are the same as in the mutool convert command.

Arguments:
  • buffer – The buffer to output to.

  • format – The file format.

  • options – The options as key-value pairs.

Returns:

DocumentWriter.

EXAMPLE

var writer = new mupdf.DocumentWriter(buffer, "PDF", "");

Instance methods

beginPage(mediabox)

Begin rendering a new page. Returns a Device that can be used to render the page graphics.

Arguments:
Returns:

Device.

EXAMPLE

var device = writer.beginPage([0,0,100,100]);
endPage(device)

Finish the page rendering. The argument must be the same Device object that was returned by the beginPage method.

Arguments:
  • deviceDevice.

EXAMPLE

writer.endPage(device);
close()

Finish the document and flush any pending output.

EXAMPLE

writer.close();