Commit Graph

115 Commits

Author SHA1 Message Date
Tim van der Meij
cc654fd38d
Provide a stub for setAttribute in order to use the SVG back-end with
Node.js

This patch fixes a regression from PR #8691 where we switched to using
`setAttribute` instead of `setAttributeNS` if no namespace is provided.
2017-09-12 23:23:41 +02:00
FAREAST\wenxh
585cd933b7 Fix the helloworld example by setting the PDFNetworkStream class (PR 8712 follow-up) 2017-09-06 00:47:35 +08:00
Mukul Mishra
d16709f5e4 Adds tests for node_stream 2017-08-24 12:46:44 +05:30
Rob Wu
9b5086d649 pdf2svg.js: Serialize the SVG to a stream
Implement a serialization "generator" for `DOMElement` in domutils.js
that yields the serialization of the SVG element. This method is used by
a newly added `ReadableSVGStream` class, which can be used like any
other readable stream in Node.js.

This reduces the memory requirements. Now, it is not needed to require
the serialization to fully fit in memory.

Note: The implementation of the serializer is a state machine in ES5
since the rest of the file is also in ES5. Its functionality is
equivalent to:

```
function* serializeSVGElement(elem) {
  yield '<' + elem.nodeName;
  if (elem.nodeName === 'svg:svg') {
    yield ' xmlns:xlink="http://www.w3.org/1999/xlink"' +
          ' xmlns:svg="http://www.w3.org/2000/svg"';
  }
  for (let i in elem.attributes) {
    yield ' ' + i + '="' + xmlEncode(elem.attributes[i]) + '"';
  }

  yield '>';

  if (elem.nodeName === 'svg:tspan' || elem.nodeName === 'svg:style') {
    yield xmlEncode(elem.textContent);
  } else {
    for (let childNode of elem.childNodes) {
      yield* serializeSVGElement(childNode);
    }
  }
  yield '</' + elem.nodeName + '>';
}
```
2017-08-16 19:16:38 +02:00
Jonas Jenwald
1f6de75585 Fix the helloworld example by importing the network.js file (PR 8617 follow-up)
Fixes https://stackoverflow.com/q/45393309/5317012
2017-07-29 22:47:46 +02:00
Rob Wu
18566091aa Fix display_svg_spec tests.
- Mark the test as async, and don't swallow exceptions.
- Fix the DOMElement polyfill to behave closer to the actual getAttributeNS
  method, which excludes the namespace prefix.
2017-07-16 11:01:52 +02:00
Rob Wu
3479a19bf0 Remove btoa from domstubs.js
btoa is already defined by src/shared/compatibility.js,
which is unconditionally imported by src/shared/util.js.
2017-07-10 18:45:47 +02:00
Rob Wu
9caaaf3a91 Add setStubs/unsetStubs to domstubs to support testing
Do not directly export to global. Instead, export all stubs in domstubs.js and
add a method setStubs to assign all exported stubs to a namespace. Then replace
the import domstubs with an explicit call to this setStubs method.  Also added
unsetStubs for undoing the changes. This is done to allow unit testing of the
SVG backend without namespace pollution.
2017-07-10 18:45:47 +02:00
Yury Delendik
9bed695ebd Merge pull request #8540 from Rob--W/svg-oom
Reduce memory requirements of pdf2svg.js example to avoid OOM
2017-06-20 17:24:48 -05:00
Rob Wu
0cc1735809 Reduce concurrent memory footprint of pdf2svg.js
Wait for the completion of writing the generated SVG file before
processing the next page. This is to enable the garbage collector to
garbage-collect the (potentially large) SVG string before trying to
allocate memory again for the next page.

Note that since the PDF-to-SVG conversion is now sequential instead of
parallel, the time to generate all pages increases.

Test case:
node --max_old_space_size=200 examples/node/pdf2svg.js /tmp/FatalProcessOutOfMemory.pdf

Before this patch:
- Node.js crashes due to OOM after processing 20 pages.

After this patch:
- Node.js is able to convert all 203 PDFs to SVG without crashing.
2017-06-19 21:53:11 +02:00
Rob Wu
849d8cfa24 Improve memory-efficiency of DOMElement_toString in domstubs
Test case:
Using the PDF file from https://github.com/mozilla/pdf.js/issues/8534
node --max_old_space_size=200 examples/node/pdf2svg.js /tmp/FatalProcessOutOfMemory.pdf

Before this patch:
Node.js crashes due to OOM after processing 10 pages.

After this patch:
Node.js crashes due to OOM after processing 19 pages.
2017-06-19 21:52:39 +02:00
Rob Wu
4f22ba54bf Add getAttributeNS to domstubs for SVG example
The closePath method in src/display/svg.js relies on this.
2017-06-19 14:11:13 +02:00
Yury Delendik
a18caa730d Adds gulp dist-install command; using pdfjs-dist package in examples. 2017-06-12 10:22:16 -05:00
Yury Delendik
5438ce9b98 Wraps mozL10n to async calls; splits firefox and generic l10n libs. 2017-05-31 09:22:25 -05:00
Jonas Jenwald
c5f73edcd2 Convert the DOMCanvasFactory to an ES6 class
For consistency, also updates the `pdf2png.js` example to use the slightly less verbose `canvasAndContext` parameter name.
2017-05-11 20:15:22 +02:00
巴里切罗
8d5d97264e fix(svg) adjust strategy for decoding JPEG images 2017-05-08 11:32:44 +08:00
Jonas Jenwald
d76cfc0610 Disable the NativeImageDecoder in the node/pdf2svg.js example (issue 7901)
It doesn't really make sense to attempt to utilize the `NativeImageDecoder` in Node, since there's no native image support available, hence building on PR 8035 we can easily disable it in the example.

Fixes 7901.
2017-04-04 17:24:29 +02:00
Mukul Mishra
f885e98d20
Example for converting PDF to PNG using the Node canvas library 2017-03-26 20:24:00 +02:00
Yury Delendik
5b50e0d414 Replaces RequireJS to SystemJS. 2017-02-27 08:32:39 -06:00
Yury Delendik
facefb0c79 Move compatibility code to the shared/compatibility.js. 2017-02-23 19:18:44 -06:00
Jonas Jenwald
3e5c6e4287 Merge pull request #8030 from timvandermeij/acroforms-example
Interactive forms: rewrite AcroForms example
2017-02-06 17:45:44 +01:00
Tim van der Meij
63fa26843b Interactive forms: rewrite AcroForms example
This patch lets the AcroForms example make use of the built-in interactive
forms functionality in PDF.js. This makes the example:

- much easier to understand;
- more feature-complete;
- in sync with the core when new functionality is added;
- similar to the other examples in terms of structure.
2017-02-05 23:44:32 +01:00
Yury Delendik
2049cf01db Moves preprocessor stuff to the gulpfile. 2017-02-04 08:19:46 -06:00
Jonas Jenwald
c850968fa7 Remove globals that are now unnecessary thanks to the use of various ESLint environments (e.g. Node, ShellJS, Jasmine) 2016-12-16 21:09:55 +01:00
Tim van der Meij
1d96854019 Widget annotation: implement field name according to the specification
The original code is difficult to read and, more importantly, performs
actions that are not described in the specification. It replaces empty
names with a backtick and an index, but this behavior is not described
in the specification. While the specification is not entirely clear
about what should happen in this case, it does specify that the `T`
field is optional and that multiple field dictionaries may have the same
fully qualified name, so to achieve this it makes the most sense to
ignore missing `T` fields during construction of the field name. This is
the most specification-compliant solution and, judging by opened issue #6623, also the required and expected behavior.
2016-11-02 21:44:44 +01:00
Tim van der Meij
de6c92a96d Examples: improve SVG viewer
This patch:

- resolves a warning in the console about missing character encoding;
- makes the viewer use the same background color and PDF file as the
  regular viewer;
- simplifies the example to bring it more in line with the other
  examples.
2016-10-15 21:08:24 +02:00
Jonas Jenwald
65e9ff68aa [mobile-viewer] Add an async close method to the example, and change open to also be async (issue 7571)
Since the `mobile-viewer` example is based on the old FirefoxOS/B2G PDF viewer, it didn't need to have the same kind of `open/close` methods as the default viewer.
However, now that it has been re-purposed as a simple `mobile-viewer` example, it seems like a good idea to ensure that it has proper asynchronous `open/close` methods.

Fixes 7571.
2016-08-27 12:57:34 +02:00
Tim van der Meij
a20f814265 Refactor the mobile viewer example
This mostly removes B2G-specific code and adds the styles from the B2G
components.
2016-07-27 17:31:52 +02:00
Tim van der Meij
a9dd2ab0ab Move B2G viewer to the examples folder 2016-07-27 17:31:52 +02:00
klemens
6f03f62327 trivial spelling fixes 2016-07-17 14:33:41 +02:00
Yury Delendik
5f883d763f Better components examples. 2016-04-28 13:30:03 -05:00
Yury Delendik
81fc46e666 Refactors FindController dependencies. 2016-04-24 08:25:55 -05:00
Yury Delendik
ae415f9e80 Removing "entry-loader" dependency from webpack. 2016-04-13 08:24:25 -05:00
Brendan Dahl
68e8f5fff5 Merge pull request #7126 from yurydelendik/rm-pdfjs-display
Move all PDFJS display/ usages into global.js file.
2016-04-07 11:47:58 -07:00
Yury Delendik
1e4886a15a Remove global window and navigator usages from the core code. 2016-04-07 13:46:07 -05:00
Yury Delendik
1e3e14e6b2 Exposes all functional members via lib exports and use them in viewer. 2016-04-07 13:46:07 -05:00
Tim van der Meij
b293d1caf5 Update Webpack and Browserify example README files
Previously the commands were not properly parsed as such by GitHub
because they need to be indented with four spaces.

Furthermore, address some minor textual nits.
2016-04-06 18:36:41 +02:00
Yury Delendik
d7d7935648 Initial browserify example. 2016-04-04 11:32:01 -05:00
Tim van der Meij
b8aaa24257 Convert all node make instances to gulp 2016-03-04 20:30:36 +01:00
Jonas Jenwald
4a6575643b [SVG] Specify the PDFJS.cMapUrl/PDFJS.cMapPacked parameters in the svgviewer example
Re: issue 7017.
This should prevent the error, but does not fix the broken rendering.

The rendering issues are caused by `svg.js` not supporting the various text rendering modes, in this case specifically "invisible" (as indicated in the console `Warning: Unimplemented method setTextRenderingMode`).

Compared to the canvas case, where we just ignore invisible text, a smarter solution is probably required for the SVG case. Since just ignoring invisible text in `svg.js` would mean that text-selection isn't possible.
2016-02-26 23:07:39 +01:00
Yury Delendik
85e95d34ed Use RequireJS in the viewer, examples and tests. 2015-12-29 09:20:52 -06:00
Yury Delendik
79c2f69c32 Adds/modifies examples for node.js and webpack. 2015-12-21 13:46:50 -06:00
Jonas Jenwald
3079dd937f Remove a superfluous "s" in AnnotationsLayerBuilder from files in web/
This patch makes the naming consistent with the `TextLayerBuilder`, and also the new `AnnotationLayer`, and should thus help reduce possible confusion when working with the code.
Please note that the files were renamed using `git mv`, in order to preserve blame.
2015-12-18 19:55:54 +01:00
Yury Delendik
6b60c8f4db Adds UMD headers to core, display and shared files. 2015-12-15 13:24:39 -06:00
Tim van der Meij
91274d6d2d Rename annotation_helper.js to annotation_layer.js 2015-12-02 23:30:28 +01:00
Yury Delendik
06c1904675 Refactors FontLoader to group fonts per document. 2015-11-24 13:27:22 -06:00
Yury Delendik
56ccaea99b Move text layer building logic into src/display/text_layer.js 2015-11-19 10:50:27 -06:00
Yury Delendik
2f34fd46cb Move CustomStyle. 2015-11-19 10:47:17 -06:00
Manas
a2ba1b8189 Uses editorconfig to maintain consistent coding styles
Removes the following as they unnecessary
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
2015-11-14 07:32:18 +05:30
Yury Delendik
601d29b14e Fixes all examples to require workerSrc to be set. 2015-11-06 07:50:21 -06:00