OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



PDF embedding in 2.3.3-1

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

PDF embedding in 2.3.3-1

Postby TomCobbaert » Fri Oct 08, 2010 6:29 am

Hi all, I'm quite new to OJS and a newbie on this forum, so don't shoot me right away ;-).
The problem I'm having is with the PDF embedding in the 2.3.3-1 release. It doesn't work (well not without some changes). Having some experience with developing, I tried to find out the problem and I think I found it, but couldn't resolve it properly yet. Maybe some of you can help out?

The problem is to be found in /templates/article/article.tpl from line 19-39.

Code: Select all
      <script type="text/javascript">{literal}
         $(document).ready(function(){
            if ($.browser.webkit) { // PDFObject does not correctly work with safari's built-in PDF viewer
               var embedCode = "<object id='pdfObject' type='application/pdf' data='{/literal}{$pdfUrl}{literal}' width='99%' height='99%'><div id='pluginMissing'>{/literal}{$noPluginKey}{literal}</div></object>";
               $("#articlePdf").html(embedCode);
               if($("#pluginMissing").is(":hidden")) {
                  $('#fullscreenShow').show();
                  $("#articlePdf").resizable({ containment: 'parent', handles: 'se' });
               } else { // Chrome Mac hides the embed object, obscuring the text.  Reinsert.
                  $("#articlePdf").html('{/literal}{$noPluginText}{literal}');
               }
            } else {
               var success = new PDFObject({ url: "{/literal}{$pdfUrl}{literal}" }).embed("articlePdf");
               if (success) {
                  // PDF was embedded; enbale fullscreen mode and the resizable widget
                  $('#fullscreenShow').show();
                  $("#articlePdfResizer").resizable({ containment: 'parent', handles: 'se' });
               }
            }
         });
      {/literal}</script>


What I've already found out, is that the problem probably is to probably to be found in a syntax error after line 22. Because after some fiddling with the syntax I found out that the following syntax, where I filled in the variables $pdfUrl and $noPluginText and removed all literal-tags after the closing of the object-tag on line 22, actually works:

Code: Select all
      <script type="text/javascript">{literal}
         $(document).ready(function(){
            if ($.browser.webkit) { // PDFObject does not correctly work with safari's built-in PDF viewer
               var embedCode = "<object id='pdfObject' type='application/pdf' data='{/literal}{$pdfUrl}{literal}' width='99%' height='99%'><div id='pluginMissing'>{/literal}{$noPluginKey}{literal}</div></object>";
               $("#articlePdf").html(embedCode);
               if($("#pluginMissing").is(":hidden")) {
                  $('#fullscreenShow').show();
                  $("#articlePdf").resizable({ containment: 'parent', handles: 'se' });
               } else { // Chrome Mac hides the embed object, obscuring the text.  Reinsert.
                  $("#articlePdf").html('<p>The PDF file you selected should load here if your Web browser has a PDF reader plug-in installed (for example, a recent version of <a href="http://www.adobe.com/products/acrobat/readstep2.html">Adobe Acrobat Reader</a>).</p> <p>Alternatively, you can also download the PDF file directly to your computer, from where it can be opened using a PDF reader. To download the PDF, click the Download link below.</p> <p>If you would like more information about how to print, save, and work with PDFs, Highwire Press provides a helpful <a href="http://highwire.stanford.edu/help/pdf-faq.dtl">Frequently Asked Questions about PDFs</a>.</p>');
               }
            } else {
               var success = new PDFObject({ url: "http://wt.advn20.be/index.php/wt/article/viewFile/1/1" }).embed("articlePdf");
               if (success) {
                  // PDF was embedded; enbale fullscreen mode and the resizable widget
                  $('#fullscreenShow').show();
                  $("#articlePdfResizer").resizable({ containment: 'parent', handles: 'se' });
               }
            }
         });
      {/literal}</script>


For me, it is solved for now, but not in a very clean way. OJS deserves a better solution ;-).
TomCobbaert
 
Posts: 6
Joined: Fri Oct 08, 2010 3:32 am

Re: PDF embedding in 2.3.3-1

Postby TomCobbaert » Tue Oct 12, 2010 12:20 am

Maybe this topic suits better in the "Technical Support Section", if any of the moderators feels the same, feel free to move it over there 8)

For me, it is solved for now


And even that isn't true anymore. Now it only works in Safari, but not anymore on FF or IE.
TomCobbaert
 
Posts: 6
Joined: Fri Oct 08, 2010 3:32 am

Re: PDF embedding in 2.3.3-1

Postby jmacgreg » Tue Oct 12, 2010 1:49 pm

Hi Tom,

Happy to have you on board and contributing to the project! Could you give us a bit more detail on what the problem is exactly -- that is, are you experiencing a display problem, and if so in which browser(s)? I did some of the cross-browser testing of the new display, and managed to catch some (but probably not all) display bugs; if you could give us more detail on what the problem is, we can help work towards a solution.

Cheers,
James
jmacgreg
 
Posts: 4162
Joined: Tue Feb 14, 2006 10:50 am

Re: PDF embedding in 2.3.3-1

Postby mcrider » Fri Oct 15, 2010 10:08 am

Hi Tom,

Yes, please let us know what the exact problem with Safari you were seeing was. I'm not sure why your changes would have fixed any issues.. those variables should be filled out (and the literal tags removed) before they hit the browser. The side effect of your change is that the 'noPluginText' variable won't be translated (if you're using more than one locale on your site), and the PDF embedder will only be able to show one PDF (!). Are you sure you have PDF plugins installed for Firefox and IE?

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: PDF embedding in 2.3.3-1

Postby TomCobbaert » Sat Oct 16, 2010 2:16 am

Matt,
James,

Thanks for your replies, and sorry that I'm answering them rather late (was kind of busy with some other stuff).
Well, I've tweaked the code a little more and now it works on every browser (with it's PDF plugin correctly installed, that is :wink:).
But let's start at the beginning:
The problem was that, even with a PDF plugin correctly installed, when choosing to view a PDF it immediately showed the $noPluginText-message instead of a browser-embedded PDF. Whereas in other websites using PDFObject, embedding worked perfectly.
After some trial and error I found out that the problem should be in the script embedding the PDF (found in /templates/article/article.tpl from line 19-39). The tweak I made earlier was indeed wrong and kept showing the same PDF, but at least the embedding worked. Adding the '{/literal}{$pdfUrl}{literal}' back at line 31 and using my own localization (we mainly use Dutch) on line 28, every now works as it should.
What is changed from the original code then? Well, at this moment I only left out the literal-calling of $noPluginText at line 28. This is the actual result:

Code: Select all
      <script type="text/javascript">{literal}
         $(document).ready(function(){
            if ($.browser.webkit) { // PDFObject does not correctly work with safari's built-in PDF viewer
               var embedCode = "<object id='pdfObject' type='application/pdf' data='{/literal}{$pdfUrl}{literal}' width='99%' height='99%'><div id='pluginMissing'>{/literal}{$noPluginKey}{literal}</div></object>";
               $("#articlePdf").html(embedCode);
               if($("#pluginMissing").is(":hidden")) {
                  $('#fullscreenShow').show();
                  $("#articlePdf").resizable({ containment: 'parent', handles: 'se' });
               } else { // Chrome Mac hides the embed object, obscuring the text.  Reinsert.
                  $("#articlePdf").html('<p>Het PDF bestand dat u gekozen hebt zal hier geladen worden als uw webbrowser een plugin voor het lezen van PDF geïnstalleerd heeft. Gebruikelijk volstaat een recente versie van <a href="http://get.adobe.com/nl/reader/" target="_blank">Adobe Acrobat Reader (gratis)</a>. In een aantal gevallen moet er een speciale plugin geïnstalleerd worden, te vinden via de productpagina van uw browser (bvb. <a href="http://support.mozilla.com/nl/kb/PDF-bestanden+openen+binnen+Firefox">Firefox voor Mac OSX</a>).</p> <p>U kunt het PDF bestand ook direct naar uw computer downloaden en het openen in een PDF-lezer. Om een PDF de downloaden, klik op de download-link onderaan deze pagina.</p>');
               }
            } else {
               var success = new PDFObject({ url: "{/literal}{$pdfUrl}{literal}" }).embed("articlePdf");
               if (success) {
                  // PDF was embedded; enbale fullscreen mode and the resizable widget
                  $('#fullscreenShow').show();
                  $("#articlePdfResizer").resizable({ containment: 'parent', handles: 'se' });
               }
            }
         });
      {/literal}</script>


As far as I can think the problem lies in the calling or definition of $noPluginText?
BTW: is it correct that in the aforementioned script, before the closing of the object-tag, you first call the, apparently non-defined, $noPluginKey instead of the defined $noPluginText?

Thanks for your help!
TomCobbaert
 
Posts: 6
Joined: Fri Oct 08, 2010 3:32 am

Re: PDF embedding in 2.3.3-1

Postby mcrider » Mon Oct 18, 2010 5:10 pm

Hi Tom,

That is indeed a typo -- Which I've filed at http://pkp.sfu.ca/bugzilla/show_bug.cgi?id=6052. Thanks!

Are you saying that the article is embedded only when you change line 28 from $("#articlePdf").html('{/literal}{$noPluginText}{literal}'); to $("#articlePdf").html('{$noPluginText}');? I think it should probably work either way, but it should definitely work with the {literal} tags there. Would you be able to try again, with the fix from the bug report above in place (i.e. change that call to 'noPluginKey' to 'noPluginText')?

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: PDF embedding in 2.3.3-1

Postby TomCobbaert » Wed Oct 20, 2010 3:08 am

Hi Matt,

Typo: I thought so :-)

Embedding: I know it doesn't make any sense, but the only way I get the embedding to work is to avoid the call to $noPluginText. Either by maintaining the typo (on line 22) or by filling in my own locale-version (on line 28). I just can't make any sense out of it.
TomCobbaert
 
Posts: 6
Joined: Fri Oct 08, 2010 3:32 am


Return to OJS Development

Who is online

Users browsing this forum: No registered users and 3 guests