jDownloads for Joomla 3.x => jDownloads 3.2 => General => Topic started by: Jean-Pierre on 27.10.2015 22:59:44

Title: Preview of PDF files?
Post by: Jean-Pierre on 27.10.2015 22:59:44
Hi, I just started to use jDownloads for managing free and paid downloads of PDF files. I'm very satisfied so far with the quality of the product, however there is one point where I have not found a way to do so far: for PDF files that are to be sold, I would like to offer a preview, i.e. a few pages of the full document so that users have a better idea of the PDF file before paying for it. I uploaded these preview PDF files through "Select Preview File" on the "Edit Download" page, but they do not show up anywhere. I would have expected to find a "Preview" link or button next to the "Download" button in the frontend, but  that's not the case. Any suggestion?
Title: Re: Preview of PDF files?
Post by: ColinM on 28.10.2015 08:56:16
There is no automatic  way to preview several pages of a pdf as you indicate but there are various ways you can achieve your objective.  In all of them you either make images of the relevant pages or you create a short preview pdf file.

With the present jD 3.2 series the nearest to an automatic scheme then with the appropriate Configuration setup jD will create a preview image of the front page.  See the Thumbnails Settings section of the Configuration - Pictures Tab, in particular field 'Create Thumbnails from PDF files? However the image created is only the front page of the pdf.

You can have multiple images associated with each download so these could be images made by yourself.

Perhaps a better way is to create a pdf preview file - say using the Primo pdf 'printer' to get just the pages you want of each document that you wish to have a preview.  This could be a separate 'Download' or you could use the jD Content plugin within the Description part of the main download.  A variation on this would be to embed a "pdf viewer" plugin such as the free Techjoomla pdf viewer - see
 https://techjoomla.com/free-downloads/pdf-embed (https://techjoomla.com/free-downloads/pdf-embed)

To assist in embedding other plugins in  jD then the following article may help
http://www.jdownloads.net/documentations/item/extending-with-plugins-example-using-image-gallery-videos (http://www.jdownloads.net/documentations/item/extending-with-plugins-example-using-image-gallery-videos).

Title: Re: Preview of PDF files?
Post by: Jean-Pierre on 28.10.2015 22:52:28
Thank you Colin,

I will see what approach fits best. I have already separate PDF preview files, however I would prefer not to embed them in the article, but to download them in a similar way than the main document.

Title: Re: Preview of PDF files?
Post by: ColinM on 29.10.2015 22:48:14
I was suggesting using the content plugin in the Description part of the Main download.  I have constructed, very quickly, an very basic illustrative example.The 'blue ringed ' part represents the link to the preview, which would have public download permission. I set it to have a pale blue background It uses appropriate layouts.  If you think scheme useful then I will post more details.


[gelöscht durch Administrator]
Title: Re: Preview of PDF files?
Post by: Jean-Pierre on 29.10.2015 23:57:54
Hi Colin,

Thank you. Yes, I  believe your approach is a valid answer to my request. The PDF previews can be public, no problem.

Title: Re: Preview of PDF files?
Post by: EURRWebmaater on 18.11.2017 15:28:52
I want the user to be able to read the complete file also on the website.

I use the same plugin and try this code on my website
{pdf={url_download}|100%|600|pdfjs}  but the {url_download} is replaced with a download button instead only the url. I checked the parameter list but couldn' t find and raw url link or something is there an other way to get the raw url in the layout section?
Title: Re: Preview of PDF files?
Post by: ColinM on 18.11.2017 17:10:43
In jD Config - Downloads tab - field "Which file types are to be opened in the Browser?" you can specify which files are opened in the browser.  This happens when clicking on the download button or the Download name.  But for this to work the file must be downloadable.
 If the whole file is viewable on the web then there is a lot of software which can 'steal' whatis being displayed!
Title: Re: Preview of PDF files?
Post by: EURRWebmaater on 18.11.2017 17:33:21
I noticed now  it depends on the browser. my firefox just came with a download popup while IE opened a new tab with the pdf.
I would like it if the experience is the same AND that the user says on the website.

The scraping is not a problem, all the files are only available for members.
Is a additional tag possible or is there some PHP code that i can put in my layout that gives the url?
Edit: RAW elements would also be nice to embed a filtered fabrik list with relevant files.
Title: Re: Preview of PDF files?
Post by: ColinM on 19.11.2017 20:58:40
You could try {pdf={file_title}|100%|600|pdfjs} but you would also need to set some config parameters.
See http://www.jdownloads.net/documentations/item/download-actions-direct-via-summary-page-or-via-download-details (http://www.jdownloads.net/documentations/item/download-actions-direct-via-summary-page-or-via-download-details)

Another approach is to use the jD Content Plugin with code based around something like below - also needs as above
Code: [Select]
<p>This article shows several&nbsp; jDownloads Content Plugin examples</p>
<div>{jd_file onlinelayout==Files link only v3.2}</div>
<div>This is some text with a download {jd_file file==25}in the middle of the line using layout "Files link only v3.2".</div>
<p>This is just text on a line as &lt;p&gt;</p>
for more on content plugin see
http://www.jdownloads.net/documentations/item/using-the-content-plugin-in-articles-and-modules (http://www.jdownloads.net/documentations/item/using-the-content-plugin-in-articles-and-modules)

Please let us know how you get on
Title: Re: Preview of PDF files?
Post by: EURRWebmaater on 02.12.2017 18:35:13
I`ve been looking and testing but always come to the point that i  need a full URL to the PDF file for the embedded PDF viewer. The  {file_id} would be the easiest way but is not available in the 'file detail' lay-out. Then i could simple use this:

Title: Re: Preview of PDF files?
Post by: EURRWebmaater on 19.08.2019 20:44:35
Solution add the next line to \components\com_jdownloads\views\download\tmpl\default.php line 465

Code: [Select]
$body = str_replace('{file_id}', $this->item->file_id, $body);Now the pfd files are loaded embedded within the page.  :D
Title: Re: Preview of PDF files?
Post by: ColinM on 20.08.2019 10:23:03
That is a very neat solution :) .  Think it is much better than using the ImageMagick PHP Module.Will send you a PM
Title: Re: Preview of PDF files?
Post by: EURRWebmaater on 20.08.2019 11:22:20
Complete instuctions:
add the next line to \components\com_jdownloads\views\download\tmpl\default.php line 465


Code: [Select]
$body = str_replace('{file_id}', $this->item->file_id, $body);
Install PDF plugin: https://techjoomla.com/free-downloads/pdf-embed

Put the next Code to put in your download details template:
Code: [Select]
See the attachment for an example of the result.

Disclaimer I have no  idea (yet) what it does with other documents then pdf.
Title: Re: Preview of PDF files?
Post by: EURRWebmaater on 21.08.2019 12:36:28
I made some improvements:
  • No plugin needed, but you need to placepdfjs web files somewhere adjust $Path_pdfjs accordingly
  • Only shown with pdf files
  • separate tag that you can use in the layout:{file_pdfviewer}
  • Smartsearch highlighting!
pdfjs download: https://mozilla.github.io/pdf.js/getting_started/#download

components\com_jdownloads\views\download\tmpl/default.php line 465
Code: [Select]
// Added $body = str_replace('{file_id}',$this->item->file_id , $body); //for debugging but maybe nice to keep

//temp $body = str_replace('{file_id}', date_format(date_create($this->item->date_added),'Y-m-d') , $body);

// get the smartsearch from the url if exist
$search= base64_decode(htmlspecialchars($_GET["highlight"]));
$search= str_replace('[', '' , $search);
$search= str_replace(']', '' , $search);
$search= str_replace('"', '' , $search);
$search= str_replace(',', ' ' , $search);
$body = str_replace('{file_search}', $search , $body); //for debugging but maybe nice to keep

// get file extension
$file_extension = end(explode(".", $this->item->url_download));
$body = str_replace('{file_extension}', $file_extension , $body); //for debugging but maybe nice to keep

// Insert pdfviewer
if($file_extension == 'pdf')
// Path to pdfjs/web/viewer.html  **** could be installed with jdownloads
$Path_pdfjs = '/vve/plugins/content/pdf_embed/assets/viewer/pdfjs/web/viewer.html' ;
//replace the file_pdfviewer with the pdfjsviewer
$body = str_replace('{file_pdfviewer}',
'<iframe src="' . $Path_pdfjs . '?file=%22index.php%3Foption%3Dcom_jdownloads%26task%3Ddownload.send%26id%3D'
. $this->item->file_id . '#search='. $search . '" ' .
' style="width:100%;height:800px;" frameborder=1> </iframe>', $body);  // ***** the style parameters should be configurable at the backend
}  // Added
Title: Re: Preview of PDF files?
Post by: Arno on 22.08.2019 09:32:25
thanks a lot that you share this with us. I think that Colin will add a hint about this possibility in the documentation.  8)
Title: Re: Preview of PDF files?
Post by: ColinM on 22.08.2019 13:05:50
Yes a distinct improvement.  What I would suggest initially is to make this as a component override - could you do this ?  I would test out and produce some examples, document and so on. The size parametersmight need to be max-size type or percentages which we could experiment with.

Adding in the pdfjs viewer as part of the jD install would obviously be a good idea and simplify matters.  But as present we are working very much on the next major release of jD (called v3.9) so in my opinion that would be the best time to include the viewer in the jD installation. - and make the facility a feature?   

Users might want to just show a section of the pdf so is it a possiblility to specify the number of pages or even better the page range?  At this time it looks like 4 or 5 parameters in the Back End would be needed for inclusion in the jD config.xml file, probably the Specials section.First "Do you wish to use embedded pdf viewer?" with a Yes/No selection The Yes would then reveal the pages and size parameters. 

I would suggest a suitable place to load the viewer file would be in a new directory in the components/com_jdownloads/assets called say pdfjs although perhaps it could go into the existing js directory.
What do you think?Colin

Title: Re: Preview of PDF files?
Post by: EURRWebmaater on 25.08.2019 15:43:20
I tried to make an override as instructed here: https://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core (https://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core)
But it didn`t work.

I made an zip with al the files that i have adjusted  and just overwrite the default files.
It also includes the adjustments of the related module and smartsearch that i found on github so maybe not so usefull for others.
Edit removed Download zip attachment