I do not know how to disable PDF download and print in ZUML(ZK User Interface Markup Language). Do I need to embed a customized PDF viewer as I can only open PDF file by using Iframe tag in ZK and it uses browser pdf viewer.Therefore, it makes the task of disabling print and download pdf even harder.
2 Answers
There are two other solution:
Convert the file to HTML, image, or any other format that can be directly viewed in the browser. This conversion can be on-the-fly using a server-side (written in Java in this case), or you can just pre-convert all files to a readable one.
The other approach, which is the best, is to use a Flash-based PDF viewer (such as http://flexpaper.devaldi.com/). This is easy, flexible and doesn't require writing server-side code. This approach is used by many Document-sharing sites (e.g. http://www.scribd.com/, http://www.slideshare.net/, http://www.docstoc.com/)
(For reference only, If you don't want disable download pdf file, there are few solutions:
http://zkfiddle.org/sample/1dnhepc/11-PDF-viewer
http://zkfiddle.org/sample/3ojd4og/1-PDF-Viewer-in-ZK-using-Iframe#source-2 )

- 46,709
- 59
- 215
- 313
After this question I discovered the existence of PDFObject, a simple javascript plugin to embed PDF documents inside a page. I've made a fiddle so you can see it in action.
index.zul
<?script type="text/javascript" src="http://pdfobject.com/scripts/pdfobject.js"?>
<zk>
<script type='text/javascript'>
function embedPDF(_url){
var myPDF = new PDFObject({
url: _url
}).embed('pdfContainer');
}
</script>
<vlayout apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('pkg$.TestVM')" xmlns:w="http://www.zkoss.org/2005/zk/client">
<listbox model="@load(vm.pdfUrls)">
<template name="model" var="url">
<listitem>
<listcell label="@load(url)" />
<listcell>
<button label="load" onClick="@command('loadPdf', url=url)" />
</listcell>
</listitem>
</template>
</listbox>
<vlayout xmlns:n="native">
<n:object id="pdfContainer"></n:object>
</vlayout>
</vlayout>
</zk>
TestVM.java
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.BindingParam;
import java.util.List;
import java.util.ArrayList;
import org.zkoss.zk.ui.util.Clients;
public class TestVM {
List<String> pdfUrls;
@AfterCompose
public void afterCompose() {
pdfUrls = new ArrayList<String>();
pdfUrls.add("http://www.pdf995.com/samples/pdf.pdf");
pdfUrls.add("https://partners.adobe.com/public/developer/en/xml/AdobeXMLFormsSamples.pdf");
pdfUrls.add("https://www.iscp.ie/sites/default/files/pdf-sample.pdf");
}
@Command
public void loadPdf(@BindingParam("url")String url) {
Clients.evalJavaScript("embedPDF('"+ url +"')");
}
public List<String> getPdfUrls() {
return pdfUrls;
}
}
Cheers, Alex