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

iOS issue on print with images #414

Closed
dohomi opened this issue Oct 20, 2015 · 9 comments
Closed

iOS issue on print with images #414

dohomi opened this issue Oct 20, 2015 · 9 comments

Comments

@dohomi
Copy link

dohomi commented Oct 20, 2015

Hello,

my PDF creation works fine on standard Safari, Firefox and Chrome and Android.

But on iOS it fails, a new tab is getting opened but without any content. I am using .download()method so I thought it will get downloaded immediately? Anything I could do about it? The size is ~800kb so I guess it happens because of the size of the PDF.
Thanks Dominic

@dohomi
Copy link
Author

dohomi commented Oct 21, 2015

This is the error message:

TypeError: undefined is not an object (evaluating 'e.location')
(anonymous function)pdfmake.min.js:1:1043
(anonymous function)pdfmake.min.js:1:2094
(anonymous function)pdfmake.min.js:1:771
emitpdfmake.min.js:9:26386
(anonymous function)pdfmake.min.js:10:1127
runpdfmake.min.js:10:6798
rpdfmake.min.js:10:6430

@mikehuebner
Copy link

If you can, try an unminified version, helps with debugging.
Besides that, according to the documentation the .download() only works in Chrome. It crashes every other browser for me. .open() seems to have its limits, IE is a definite case as anything over 5k doesn't seem to work. Regardless, there is no where to download it on iOS, you can't really download a file on iOS easily. Does .open() do anything?
Thanks!

@dohomi
Copy link
Author

dohomi commented Oct 23, 2015

@mikehuebner I narrowed it down with following approach and now it works on almost all platforms with all browsers. Importantly I don't use the .download()nor.open() any more because for iOS there must be the ultimate click event which calls the download of the generated blob - the click event is getting lost. Here a snippet from my approach.
function

function createPdfBuffer(){
(... creation of docDefinition)
var defered = $q.defer();
pdfMake.createPdf(docDefinition).getBuffer(function(result) {
  defered.resolve(result);
});
return defered.promise;
}

// call the function
var objectURL; 
createPdfBuffer().then(function(result){
  currentBlob = new Blob([result], {type: 'application/pdf'});
  objectURL = URL.createObjectURL(currentBlob);
}

// this is a click on any HTML link or click event
function clickDownloadPdf(){
  // making use of FileSaver project to save it
  FileSaver.saveAs({
    data:currentBlob
   filename:'Some title'
  });
}

Most importantly after all my excursion there is FileSaverincluded in the build of pdfmakebut its not available for public. Is it possible having a build without FileSaverand the public download open printfunctions?

@balilaszlo
Copy link

@dohomi
Ok, but what if the data-s come from the server as JSON pls.
I have the same issues like yours, IOS always goes on different ways :-)

@mikehuebner
Copy link

@balilaszlo
If the JSON data is coming from the server you have to massage that data to fit the format of the PDF. So as it comes in just read the specifications of what everything needs (I did a loop through the data in JS and then just ran PDF make once I felt it was ready). It's a ton of mutation of the JSON to get it to work, but it does. Honestly I found myself dropping this plugin not because its bad but because I needed massive generation support. Which this plugin just crawls with sadly... So I just did it in PHP using FPDF, so this became a sort of irrelevant issue for me. The work around was just too annoying as I couldn't find a solution that actually met the needs of what I was doing.

@balilaszlo
Copy link

Creating proper JSON on server side and sending back to client is working well in my project. I did it according the documentation.

  1. dec. 27. dátummal, 6:25 időpontban Mike [email protected] írta:

@balilaszlo
If the JSON data is coming from the server you have to massage that data to fit the format of the PDF. So as it comes in just read the specifications of what everything needs (I did a loop through the data in JS and then just ran PDF make once I felt it was ready). It's a ton of mutation of the JSON to get it to work, but it does. Honestly I found myself dropping this plugin not because its bad but because I needed massive generation support. Which this plugin just crawls with sadly... So I just did it in PHP using FPDF, so this became a sort of irrelevant issue for me. The work around was just too annoying as I couldn't find a solution that actually met the needs of what I was doing.


Reply to this email directly or view it on GitHub.

@sganeshkumar
Copy link

I also face same problem like Dohomi. Any solution plz help me.

@liborm85
Copy link
Collaborator

reference: #800

@liborm85
Copy link
Collaborator

Was previously fixed in files-saver, see eligrey/FileSaver.js#12

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

No branches or pull requests

5 participants