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

open function won't work in a callback #587

Closed
krewx opened this issue May 23, 2016 · 9 comments
Closed

open function won't work in a callback #587

krewx opened this issue May 23, 2016 · 9 comments
Labels

Comments

@krewx
Copy link

krewx commented May 23, 2016

I can't seem to use the open function after any callback. I tried to use the function after an ajax call and after using SVG.toDataURL, in both cases i get "undefined is not an object (evaluating 'e.location')"

@daupawar
Copy link

please post some line of code

@emrahoruc
Copy link

Same issue here.
This code does not work. Gives;

pdfmake.min.js:110 Uncaught TypeError: Cannot read property 'location' of undefined

           $.post(site_url, form_data, function(json) {

                var pdfContent = {
                    content:[
                        "First paragraph",
                        "Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines"
                    ]
                };
                pdfMake.createPdf(pdfContent).open();

            }, "json");

But it is working outside of the ajax callback function.

@liborm85 liborm85 added the bug label Jan 21, 2017
@liborm85
Copy link
Collaborator

Works only download() method.

@raky291
Copy link

raky291 commented Feb 14, 2017

This is a temporary solution:
I solved this issue modified the build code ("open" method).

// add the "win" argument
Document.prototype.open = function(win) {
  // if don't exist a window, create one
  if (!win) {
    win = this._openWindow();
  }
  try {
    [...]
  } catch (e) {
    win.close();
    throw e;
  }
};

Usage

$scope.generatePdf = function() {
  // create the window before the callback
  var win = window.open('', '_blank');
  $http.post('/someUrl', data).then(function(response) {
    // pass the "win" argument
    pdfMake.createPdf(docDefinition).open(win);
  });
};

@clemf
Copy link

clemf commented Apr 1, 2017

@raky291 Did you submit a pull request? I would love to have this in the official release.

@liborm85
Copy link
Collaborator

liborm85 commented Apr 2, 2017

Implemented by commit 5f4076f.

open() example:

$scope.generatePdf = function() {
  // create the window before the callback
  var win = window.open('', '_blank');
  $http.post('/someUrl', data).then(function(response) {
    // pass the "win" argument
    pdfMake.createPdf(docDefinition).open({}, win);
  });
};

print() example:

$scope.generatePdf = function() {
  // create the window before the callback
  var win = window.open('', '_blank');
  $http.post('/someUrl', data).then(function(response) {
    // pass the "win" argument
    pdfMake.createPdf(docDefinition).print({}, win);
  });
};

@liborm85 liborm85 closed this as completed Apr 2, 2017
@cjayyy
Copy link

cjayyy commented Dec 15, 2017

Is it true that this solution can not be used unless application is powered by AngularJS?
If not, how could I implement it in pure JS?

This is the only solution to this issue i've found yet.

@liborm85
Copy link
Collaborator

No., Used framework/technology for async process is not related to pdfmake and open().

It is important at begin of action create/open new window and then pass this parameter to pdfmake open(). See readme.

@moffsugita
Copy link
Contributor

not work

I used new version. I read node_modules/pdfmake/build/pdfmake.js and same to 5f4076f

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

No branches or pull requests

8 participants