4

okay so I have a webpage that is generating a PDF. The code to create the PDF so far is rock solid - however I'm having troubles with displaying the created PDF.

I have gotten the display code rock solid in Chrome - however I can't get IE to work AT ALL. I need a way to generate the PDF in Javascript and display it using IE.

The key issue here is that I'm generating the PDF on the client side - which means that there is no server-side URL to load the PDF from. This requires me to use blobs or dataurls and IE will not render either of those for some odd reason. From what I read this is by design, but they offer no work-around that I can find

The project requires that the PDF be loaded in the background and merely pop up the print dialog once displayed (I cannot simply save the file to the client's computer). The data being printed is also very specifically positioned for the forms that they are printed on, which means I cannot render the PDF into a canvas and merely print the canvas element as that places an extra margin on the page with the URL and page number.


Here are my questions:

  1. Is there any kind of workaround to this issue for IE? I've used PdfObject in the past however it's still go the same issue with blobs and dataurls in IE

  2. The backend for this website is classic ASP (it's being redone in .Net but that will not be available until next around this time at the earliest) - is it possible to upload the binary data of the blob to an ASP page, store it in session, and then direct an iframe to a page that returns the contents of that session variable? This would circumvent the blob, but I fear it's a little ambitious of a task...

Robert Petz
  • 2,718
  • 4
  • 23
  • 52
  • 2
    I've always handled PDF generation from the "server-side" using Classic ASP then streamed it to the client. I think your going to struggle to use [Data URIs with IE](http://caniuse.com/#feat=datauri) as even in IE11 it is only "partially supported". – user692942 Oct 09 '14 at 08:46
  • 2
    agreed as well, I would hate to rewrite all this drawing code in ASP now though >. – Robert Petz Oct 09 '14 at 09:21
  • 2
    Yeah, I feel your pain. – user692942 Oct 09 '14 at 09:25
  • ultimately went with the ASP route - however I gave the answer to @Derek朕會功夫 because it answers the question of javascript issues very well – Robert Petz Oct 09 '14 at 17:58

1 Answers1

1

There is no way you can generate a PDF file on the go then display it without a server or a plugin involved.

If you try displaying it with data URI:

Data URIs are supported only for the following elements and/or attributes.

  • object (images only)
  • img
  • input type=image
  • link -CSS declarations that accept a URL, such as background, backgroundImage, and so on.

http://msdn.microsoft.com/en-us/library/cc848897(v=vs.85).aspx

You can't use it as a URL for a frame.

If you trying displaying it with Blob:

The Blob that is created can be used for resources in elements such as Image, video, audio, XMLHttpRequest, css backgroundImage, and css fonts.

http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx

Still no.


What you can do is to convert the PDF into HTML5 or a canvas. There are libraries that can already handle that part for you such as ViewJS. Not sure about the "extra margin" you mentioned, but the page URL and page number, even the margin, can be changed and turned off on the client side before print.

enter image description here

Community
  • 1
  • 1
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
  • Yea I think I agree with you in regards to the need for a server. However, as far as printing goes, I think I misspoke about extra 'margin' - what I meant was the extra data that the browser places on there no matter what. Most people get around this with a PDF, but then we are back to my issues here haha. See the following question: http://stackoverflow.com/questions/255534/remove-the-default-browser-header-and-footer-when-printing-html – Robert Petz Oct 09 '14 at 09:19
  • 1
    I'm gonna mark this as the answer however I ultimately decided to port the drawing code over to ASP (which wasn't too bad because ASP can run Javascript) - for anyone else in this situation who might be using the jsPDF library: you can port it to an ASP page pretty easily using ASP FPDF as it's API is almost identical (aside from the naming convention being UpperCase and not camelCase). Here's [The library](https://sites.google.com/site/aspfpdf/home) and here's [The examples](http://www.fpdf.org/) – Robert Petz Oct 09 '14 at 17:56