Forum for discussing general topics related to Couch.
3 posts Page 1 of 1
Afternoon,

I am trying to make it so PDF files are viewable but not printable or downloadable (e-learning). Have tried a number of possible solutions on the forums / documentation without too much joy. I then stumbled across Adobe PDF embedding which does exactly what I (we) need.

I have managed to get it working locally but need to delete the .htaccess file as the files are in the secure file folder. When I do that it works great, but defeats the purpose.

I have tried it with cloaking the URL(S) but just get a file not found error. Have tried cloaking the initial URL,the 2 in the viewer file and a mixture of them with not luck, Can you please advise?

Code - Success Page. Loops through JSON (Array) of purchased courses. Passing the link to the file and name of the course but think i'll be dropping the name part.

Code: Select all
<cms:each purchased.courses>
  <li>
     <a href="<cms:cloak_url link='<cms:show k_site_link />pdf-viewer.php?course_link=<cms:show item.course_link />&course_name=<cms:show item.course_name />' />" style="color:#234655;"><cms:show item.course_name /></a>
  </li>
</cms:each>


PDF Viewer Code - Javascript Auto-Generated by Adobe just added the Couch tweaks.

Code: Select all
<cms:template title="PDF Viewer" parent="_modules_" icon="" hidden="1" order="10" />

<cms:set course_link="<cms:gpc 'course_link' method='get' />" />
<cms:set course_title="<cms:gpc 'course_name' method='get' />" />

<div id="adobe-dc-view"></div>
<script src="https://documentcloud.adobe.com/view-sdk/main.js"></script>
<script type="text/javascript">
   document.addEventListener("adobe_dc_view_sdk.ready", function(){
      var adobeDCView = new AdobeDC.View({clientId: "b823990a282f42f49b424177466cb118", divId: "adobe-dc-view"});
      adobeDCView.previewFile({
         content: {
            location: { url: "<cms:show course_link />"}
         },
         metaData: {
            fileName: "<cms:show course_link />" }
         },
         {
            showDownloadPDF: false,
            showPrintPDF: false
      });
   });
</script>


The other reason for using the cloaking is the client only wants material to be accessable for a set period of time. Think its a simple thing, just having a slow day.

Thank you.
Hi,

First, please allow me to correct an error in your Couch code -
Code: Select all
<cms:cloak_url link='<cms:show k_site_link />pdf-viewer.php?course_link=<cms:show item.course_link />&course_name=<cms:show item.course_name />' />

In the code above, since the value given to the 'link' param is enclosed in 'single quotes', it would be considered a literal string. You need to use 'double-quotes; for the enclosed Couch tags to be executed and the resulting values to be used in the URL (https://docs.couchcms.com/concepts/sett ... eters.html).

Second, the <cms:cloak_url> link (as shown in the docs https://docs.couchcms.com/concepts/cloaked-links.html) works with two things -
1. Links
2. Files

For links, it expects the 'redirect' param to be set for it to redirect to the new location; the files, on the other hand, trigger downloads.
In your case, we are dealing with a link and so the redirect param would be needed else the tag will try to download the URL (and fail, as seems to be happening).

The revised code could become this (I am setting link via a variable for better readability)-
Code: Select all
<cms:each purchased.courses>
    <li>
        <cms:set my_link="<cms:show k_site_link />pdf-viewer?course_link=<cms:show item.course_link />&course_name=<cms:show item.course_name />" />
        <a href="<cms:cloak_url link=my_link redirect='1' />" style="color:#234655;"><cms:show item.course_name /></a>
    </li>
</cms:each>

So now that we have the code that would work, we can discuss your use-case.
The solution, as it stands now, won't help you in keeping the paths to your PDFs secret - the JS in your target page will reveal it.

You may try doing the following (it may or may not work depending on how the JS code internally works) -
instead of setting the plain link of the PDF as target, try using <cms:cloak_url> here e.g.
Code: Select all
content: {
    location: { url: "<cms:cloak_url link=course_link />"}
},

instead of
Code: Select all
content: {
    location: { url: "<cms:show course_link />"}
},

Needless to say, if this works, we won't be passing the link as URL param to the template; it would be figured out through code from within the template itself.

Hope this helps.
Hi KK,

I did accidentally come across the redirect to show the file and as you said the url was then shown in the address bar.
Used some JavaScript to hide the parameter which will hopefully help deter the average person.

If the link is put in directly the htaccess file blocks access anyway. Explained to the client that you can't protect 100% but at least we've made it reasonably difficult.

Thank you
3 posts Page 1 of 1
cron