Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected identifier (await/async) using node 6.10.3 64-bit #66

Closed
atrerice opened this issue May 10, 2017 · 10 comments
Closed

Unexpected identifier (await/async) using node 6.10.3 64-bit #66

atrerice opened this issue May 10, 2017 · 10 comments

Comments

@atrerice
Copy link

server\node_modules\pdfjs\lib\document.js:268
async _startPage() {
^^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (D:\Programming\apps.appliedtechres.com\server\node_modules\pdfjs\lib\index.js:5:20)

@rkusa
Copy link
Owner

rkusa commented May 10, 2017

Hi, thanks for reporting your issue. pdfjs requires Node.js >= 7 (or you have to transpile it with e.g. babel)

@atrerice
Copy link
Author

var pdf = doc.render() gives an error of: 'doc.render is not a function'.

@rkusa
Copy link
Owner

rkusa commented May 12, 2017

Which example are you following? Since 2.0.0-* there is no render() method anymore. An example, as of https://github.com/rkusa/pdfjs/tree/master/docs, is

const doc = new pdf.Document({
  font:    new pdf.Font(require('pdfjs/font/helvetica.json')),
  padding: 10
})
doc.pipe(fs.createWriteStream('output.pdf'))

// render something onto the document

await doc.end()

Edit: probably http://ma.rkusa.st/pdfjs/ , I have to update this page

@atrerice
Copy link
Author

atrerice commented May 12, 2017

I got it from http://ma.rkusa.st/pdfjs/, I will try the example above.

@atrerice
Copy link
Author

I need a buffer, I can't create a file on the server I am on. What would you suggest?

rkusa added a commit that referenced this issue May 12, 2017
@rkusa
Copy link
Owner

rkusa commented May 12, 2017

Depends on what you want to do. If it should be send as a HTTP request, I would directly pipe it into the HTTP response to not have to save the whole document in memory first.

Since getting a buffer was not very ergonomic, I've added an API for it, see https://github.com/rkusa/pdfjs/blob/master/docs/document.md#asbuffercallback

(requires to install pdfjs from Github until I release a new version to NPM)

@atrerice
Copy link
Author

You are awesome. I will download and use.

@atrerice
Copy link
Author

atrerice commented May 12, 2017

here is my code:

        const doc = new pdf.Document({
            font: new pdf.Font(require('pdfjs/font/Helvetica.json'))
        });
        var text;
        text = doc.text({
            fontSize: 14, lineSpacing: 1.35
        });
        text.add('This is to test pdfjs');
        doc.asBuffer((err, data) => {
            if (err) {
                console.error(err);
            } else {
                fs.writeFileSync('test.pdf', data, { encoding: 'binary' });
            }
        });

I get error:
(node:13108) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: font.instance is not a function
(node:13108) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I'm using node 7.10.0.

@rkusa
Copy link
Owner

rkusa commented May 12, 2017

Hm that is strange. Your example works for me. It sounds like it is mixing a never and older version of pdfjs together. Could you maybe try it again with the just published pdfjs@2.0.0-alpha.3?

@atrerice
Copy link
Author

Again, thank you. I have the new version installed and no errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants