XPages: Embed PDF and possibly Office files

倾然丶 夕夏残阳落幕 提交于 2020-02-07 07:58:29

问题


I need to embed PDF files in an xpage application. We are using IE11 x64 and this cannot be changed. Eventually, I'll also need to embed MS Office files (Word, Excel, Power Point).

I have looked at a lot of pages and couldn't get a working solution for this... I have some code that works if I force IE11 in IE10 mode, but then Dojo starts acting weird (cannot close dialog boxes, ...).

The code I have right now in my computed field looks like this:

var id:string = pageDocument.getDocument().getUniversalID();
var attNames = @AttachmentNames();
var url = getAttachmentURL(id,attNames);

'<object data="' + url + '#view=Fit&pagemode=none&statusbar=0&messages=0"' + 
'type="application/pdf" width="100%" height="100%" > ' + 
'<p>It appears your Web browser is not configured to display PDF files.  ' +  
'No worries, just <a href="' + url + '">click here to download the file.</a></p>'+
'</object>'

I need a free solution.

IBM, This should be made easy if we want to compete with SharePoint, no???


回答1:


Short answer: don't bother.

Long answer: While you might get it to work for PDF in IE11, your boss won't be happy, because it will not show on her iPad, so you need to have a plan B.... and there is another gotcha down the road (read below). This is what I would do:

  • Use Apache PDFBbox to extract text from the PDF and show that in the XPage.
  • Add a link to the page to open the whole PDF
  • Do the same thing for office documents using Apache POI eventually using OpenNTF POI4XPages
  • The download link should make use of WebDAV for Domino to allow round-trip editing

Why all this fuzz:

  • Your users will use mobile at some point of time and NO mobile browser does support embedding (nor do any browsers on a Mac)
  • Even if you successfully get embedding working, users will start to edit the embedded document and get really really upset since you don't save back the changes

On a side note: asking IBM to support a technology that is vendor proprietary working in one browser (that has been EOL for future updates - see project Spartan) - ain't going to happen.




回答2:


I got this working nicely in IE11 for PDF files with this very simple line:

<embed src="MyPDFFile.pdf" width="640px" height="755px" alt="pdf"  />

I'll go along with Stephen's answer: I won't bothe rtrying to mak ethis work with Office files. It will give our "Notes is bad" users some munitions to move to SharePoint, but we do have other advantages!




回答3:


I tried using Bumpbox, and pdf.js and while I could get them working, iframes seemed to work best for me with using normal Domino attachment urls in xpages

I am not sure if this solution is right or not, but it works well for an app I have that only has PDFs. It does work on mobile too, at least on iOS.

<iframe
    src="#{javascript:
var url = 'https://app.nsf/';

var doc = sessionScope.docID;


var atname = @RightBack(sessionScope.aname,'Body');



var end = '/$file'+atname;
return url+doc+end}"
    width="800" height="1000">
</iframe>



回答4:


Probably the best approach is to use a pure HTML5/JavaScript renderer for PDF documents without any third-party plugins (e.g. PDF.js)

For further discussion take a look at the following stackoverflow entry recommended way to embed pdf in html

In my opinion, it's the best way to use a commercial product (e.g. crocodoc) for other documents like MS Office (Word, Excel, etc.).



来源:https://stackoverflow.com/questions/29636743/xpages-embed-pdf-and-possibly-office-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!