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

uiGrid ~rc.20 Export to PDF in IE #2921

Closed
mathewbeno opened this issue Mar 5, 2015 · 25 comments
Closed

uiGrid ~rc.20 Export to PDF in IE #2921

mathewbeno opened this issue Mar 5, 2015 · 25 comments

Comments

@mathewbeno
Copy link

The pdf export feature is not working in Internet explorer. Does any one else have the same issue?

Thank you

@PaulL1
Copy link
Contributor

PaulL1 commented Mar 5, 2015

What version of internet explorer? What about it doesn't work - are there console errors for example?

I don't have IE, but my usual approach would be to put a breakpoint in the pdfExport method, and step over each line to see which one is failing. My guess is that the open of the separate window is the thing that's failing, but that's native to pdfMake, so maybe it'll end up as a bug report for them?

@PaulL1 PaulL1 added this to the 3.0 milestone Mar 5, 2015
@PaulL1 PaulL1 self-assigned this Mar 5, 2015
@mathewbeno
Copy link
Author

We are using IE 11.No errors in the console, It opens the second window but it doesn't render any data to the page.

Thank you for your quick response

@PaulL1
Copy link
Contributor

PaulL1 commented Mar 5, 2015

Hmm. Without IE it's hard for me to debug, but it sounds like it's calling the pdfMake method, and then the pdf isn't turning up?

@c0bra
Copy link
Contributor

c0bra commented Mar 6, 2015

pdfmake doesn't support IE (right now): bpampuch/pdfmake#219 (comment)

@Dev63
Copy link

Dev63 commented Mar 8, 2015

@c0bra Did pdfmake ever support IE? I thought it did! Anyway, is there a way to ask ui-grid to give me the PDF data rather than make a new page? That way for IE I could create an "echo" service for IE, where I send the data to the server and then launch a new page that opens that data. That's not optimal, but the pdfMake guys are saying that's the only way to "support" IE. Plus, I have people asking to be able to automatically email the PDF, and I'd need access to the data for that, too.

@PaulL1
Copy link
Contributor

PaulL1 commented Mar 8, 2015

It looks to me like we could just call download (or give an option for download instead of open).
bpampuch/pdfmake#230

Perhaps use the code from csv download that detects IE, and then call download instead of open. Because download looks like it causes problems on iOS devices, so we can't change to that globally.

@PaulL1
Copy link
Contributor

PaulL1 commented Mar 9, 2015

I've pushed code that checks for IE and then calls download instead of open. I have no ability to test it, so it'd be great if someone could try it out.

@PaulL1 PaulL1 closed this as completed in 3a9327f Mar 9, 2015
PaulL1 added a commit that referenced this issue Mar 9, 2015
Fix(exporter): fix #2921 download rather than open pdf in IE
@c0bra c0bra removed the in progress label Mar 9, 2015
@PaulL1 PaulL1 reopened this Mar 9, 2015
@c0bra
Copy link
Contributor

c0bra commented Mar 9, 2015

@PaulL1 Confirmed, it works for me in IE11. Good job!

Note: the PDF export is still broken in IE, though.

@PaulL1
Copy link
Contributor

PaulL1 commented Mar 9, 2015

Oh, what does 'the PDF export is still broken in IE' mean then? I had thought the thing that was broken was that it didn't open the separate tab, and my impression from the pdfMake repository was that it was the open method that was broken, and that download worked fine. Is there something else I need to fix?

(it's a bit of a pain not having IE to test with!!)

@keerthimysa
Copy link

As of Internet Explorer 11, the User Agent String has changed
function toDetectIE() {
var ua = window.navigator.userAgent;

var msie = ua.indexOf('MSIE ');
if (msie > 0) {
    // IE 10 or older => return version number
    return true;
}

var trident = ua.indexOf('Trident/');
if (trident > 0) {
    // IE 11 => return version number
    var rv = ua.indexOf('rv:');
    return true;
}

var edge = ua.indexOf('Edge/');
if (edge > 0) {
   // IE 12 => return version number
   return true;
}

// other browser
return false;

}

@PaulL1
Copy link
Contributor

PaulL1 commented Mar 11, 2015

@keerthimysa : any chance of a pull request that adds that code? I don't have IE to test on, and that code looks partial/indicative only - since it isn't setting version numbers anywhere, and I think we need to both know that it's IE and also know which IE version. I think the current isIE function was intended to return 0 if not IE, and otherwise return the version number.

@keerthimysa
Copy link

Sorry, I don't have any pull request that adds the code.
I modified pdfExport function in ui-grid js to the below code to work in IE.
/**
* @ngdoc function
* @name pdfExport
* @methodOf ui.grid.exporter.service:uiGridExporterService
* @description Exports rows from the grid in pdf format,
* the data exported is selected based on the provided options.
* Note that this function has a dependency on pdfMake, which must
* be installed. The resulting pdf opens in a new
* browser window.
* @param {Grid} grid the grid from which data should be exported
* @param {string} rowTypes which rows to export, valid values are
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
* uiGridExporterConstants.SELECTED
* @param {string} colTypes which columns to export, valid values are
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
* uiGridExporterConstants.SELECTED
/
pdfExport: function (grid, rowTypes, colTypes) {
var exportColumnHeaders = this.getColumnHeaders(grid, colTypes);
var exportData = this.getData(grid, rowTypes, colTypes);
var docDefinition = this.prepareAsPdf(grid, exportColumnHeaders, exportData);
if (this.isIE()) {
pdfMake.createPdf(docDefinition).download();
} else {
pdfMake.createPdf(docDefinition).open();
}
},
/
*
* @ngdoc function
* @name isIE
* @methodOf ui.grid.exporter.service:uiGridExporterService
* @description Checks whether current browser is IE and returns true or false
*/
isIE: function () {
var ua = window.navigator.userAgent,
msie = ua.indexOf('MSIE '), // IE 10 or older
trident = ua.indexOf('Trident/'), // IE 11
edge = ua.indexOf('Edge/'); // IE 12
if (msie > 0 || trident > 0 || edge > 0) {
return true;
}
// other browser
return false;
},

@PaulL1
Copy link
Contributor

PaulL1 commented Mar 13, 2015

I would prefer that the function continues to return a version number, but I don't know the format that it returns currently.

Could you check what it currently returns for the version number - I think it was formatted like '11.0' or something. Could you then check what value is stored in ua, and whether there's a version number in there? Ideally we'd have a method that returns 12.0 or 11.1 or whatever. Otherwise I'm going to end up with two IE detection methods.

@keerthimysa
Copy link

isIE function needs to be changed to below code to work for both csv and pdf.

isIE: function () {
var match = navigator.userAgent.match(/(?:MSIE |Trident/.*; rv:)(\d+)/);
return match ? parseInt(match[1]) : false;
},

match value
[0]: "Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; MS-RTC LM 8; InfoPath.3; rv:11"
[1]: "11"

@PaulL1
Copy link
Contributor

PaulL1 commented Mar 13, 2015

What about edge?

@keerthimysa
Copy link

Unfortunately, I don't have IE12 to test.

@c0bra
Copy link
Contributor

c0bra commented Mar 13, 2015

Just want to drop a note here: pdfmake does not support IE currently: bpampuch/pdfmake#219 (comment)

@PaulL1
Copy link
Contributor

PaulL1 commented Mar 13, 2015

Yeah, I'm separately working on that: bpampuch/pdfmake#16

If I can either get them to return the file as a blob, or get them to implement our same crappy download code, then we would be able to use it on IE.

@PaulL1 PaulL1 mentioned this issue Mar 15, 2015
@PaulL1 PaulL1 closed this as completed in be5c0ba Mar 15, 2015
@bpampuch
Copy link

Hey @PaulL1

I'm not sure if it's still relevant, but just to let you know - you can get the file as a blob using the following method:

var document = pdfMake.createPdf(docDefinition);

document.getBuffer( function (buffer) {
  blob = new Blob([buffer]);
});

@PaulL1 PaulL1 reopened this Jun 6, 2015
@PaulL1
Copy link
Contributor

PaulL1 commented Jun 6, 2015

Refer also #3642. I've implemented this code, which should result in IE getting a PDF downloaded, rather than attempting (and failing) opening the document. Of course, I don't have IE, so can't actually test it. :-)

PaulL1 added a commit to PaulL1/ng-grid that referenced this issue Jun 6, 2015
@c0bra
Copy link
Contributor

c0bra commented Jun 11, 2015

@PaulL1 not working on IE11 w/ latest unstable.

@c0bra c0bra modified the milestones: 3.1, 3.0 Jun 11, 2015
@c0bra
Copy link
Contributor

c0bra commented Jun 11, 2015

Going to move this up to 3.1 as it seems to be an on-going issue and we need to move on 3.0.

@PaulL1
Copy link
Contributor

PaulL1 commented Jun 11, 2015

There's another issue out there with a fix on it I believe - can probably be applied quickly.

Sent from my iPhone

On 12 Jun 2015, at 9:24 am, Brian Hann [email protected] wrote:

Going to move this up to 3.1 as it seems to be an on-going issue and we need to move on 3.0.


Reply to this email directly or view it on GitHub.

@PaulL1
Copy link
Contributor

PaulL1 commented Jun 26, 2015

I've applied the fix to #3642, closing this and leaving that open as the master.

@kushalt
Copy link

kushalt commented Jul 16, 2015

I have IE 10 version and getting following error when trying to export data in .pdf

TypeError: Object doesn't support property or method 'defineGetter'

Any help would be greatly appreciated.

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

8 participants