It works (showing the PDF where intended), but apparently it’s just using the browser’s integrated viewer, as I get a different viewer for each browser. I think the forcePDFJS directive is being ignored.
I’m getting no errors (even in debug no messages or exceptions), so I don’t know how to pinpoint the problem. Any takers?
I tried both options, startup script and client script; same result: pdfobject’s options always undefined.
My code works because the PDF is loaded into the desired element (not pdfjs, however).
F12 shows no error besides the ‘undefined’ from my console.log(options) in /js/pdfobject.js, as I said before.
This is my code in the view page startup script:
ew.EMBED_PDF = true; //tried with and without this
ew.PDFObjectOptions = {
forcePDFJS: true,
PDFJS_URL: "/pdfjs/web/viewer.html"
};
var myelem = $("main").first();
myelem.parent().addClass("row");
myelem.addClass("col-md-6");
myelem.after('<div class="col-md-6 ew-pdfobject pdfobject-container"></div>');
I also tried setting ew.PDFObjectOptions at the end of the script, but got the same result.
If I remove pdfobject-container, the PDF loads into a new browser window, not the div.
I ran ew.initPdfObjects() after adding the div; same result.
The ew.PDFObjectOptions array is still not being fed into the pdfobject’s embed function: still coming as undefined.
Note that ew.PDFObjectOptions are added by ew.initPdfObjects(). If you add your own DIVs later than the page calling ew.initPdfObjects() (e.g. you add it in Startup Script), it won’t work. In that case you need to init your DIVs by ew.initPdfObjects() yourself.
You better put your options in Page_Head server event, see Example 4.
If it still doesn’t work, you may post your complete code for discussion, including:
Which page are you working with? Built-in page? Your custom file?
Where did you add your DIVs? Startup Script? How did you call ew.initPdfObjects()?
My complete code is in the client startup script of the master/detail view page of a database table (not custom file). Page_Head server event is empty. This is the code in the view page startup script:
…PDFJS loads up but, as soon as I click a PDF link, it falls back into PDFObject. Maybe this can help.
Thanks a lot for your interest in the matter and help.
Thanks. I added it and syntax error is gone, but made no difference re. PDFJS.
If I remove it, PDF object stops working on my div altogether.
True. I added it to check if that was the problem, but it is redundant.
Removed. Actually it works either way, buy only if modify /js/pfdobject.js as I previously wrote.
I only need to provide data-url attribute if I want to load a PDF automatically when the page is loaded.
My view page is a master/detail. Each detail line has a file field. As I click on each one, the pdf loads into the div.
I stress that this code works if I modify /js/pdfobject.js as stated above, forcing ew.PDFObjectOptions into the options variable, which is always undefined. I just wish I didn’t have to modify that script. My current code:
That’s probably the problem. You may post your code for the link for discussion. I guess you just add the data-url to your DIV when you click the link. If so, that won’t work.
Be reminded that you have already initiated the DIV by ew.initPdfObjects() in the Startup Script. At that time there is no data-url yet, so it embeds no PDF file. When you add or change the data-url, the PDFObject will not automatically embeds again itself, calling ew.initPdfObjects() again won’t work either because it will not repeatedly initiate DIVs. So you should embed the PDF file yourself:
Again, remove pdfobject-container. If you need to add it yourself, your code is incorrect.
In the onclick event for your links, embed the file to your DIV, you better give it an id, e.g. “my-id”
You are right. The problem was in the custom attributes of my file field.
I added an id for my div, and removed class pdfobject-container.
Now, the field’s custom attributes are:
…which will work whether #my_pdf_viewer exists or not (meaning I can disable the viewer and just download the file).
Everything works now. Thanks a lot!
Cheers