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.
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 )
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
Related
[Note this might be similar to https://stackoverflow.com/questions/48138874/can-make-print-js-print-a-variable, but I don't know PHP]
I have an ASP.Net core action that creates a PDF on the fly. I currently have the PDF download to the client, like so:
<a asp-controller="Home" asp-action="Pdf">Download PDF</a>
and the controller action
public IActionResult Pdf()
{
using (MemoryStream ms = new MemoryStream())
{
...
return File(ms.ToArray(), "application/pdf", "file.pdf");
}
}
Instead, I would like it to go to the print preview dialog of the browser, for which I was planning to use printjs. But I have to specify a server-based file (such as "docs/file.pdf"). The printjs sample is:
<button type="button" onclick="printJS('docs/file.pdf')">Print PDF</button>
Is there a way to cause the printJS file to download the pdf file without needing to save it somewhere?
Doh. Too easy:
<a onclick="printJS('/home/Pdf')">Print PDF</a>
Instead of supplying an href to a file, have the onclick function call printJS with the action name which will execute and download the PDF.
I have adopted various approaches to embed PDF blob in html in IE in order to display it.
1) creating a object URL and passing it to the embed or iframe tag. This works fine in Chrome but not in IE.
</head>
<body>
<input type="file" onchange="previewFile()">
<iframe id="test_iframe" style="width:100%;height:500px;"></iframe>
<script>
function previewFile() {
var file = document.querySelector('input[type=file]').files[0];
var downloadUrl = URL.createObjectURL(file);
console.log(downloadUrl);
var element = document.getElementById('test_iframe');
element.setAttribute('src',downloadUrl);
}
</script>
</body>
2) I have also tried wrapping the URL Blob inside a encodeURIcomponent()
Any pointers on how I can approach to solve this?
IE doesn't support iframe with data url as src attribute. You could check it in caniuse. It shows that the support is limited to images and linked resources like CSS or JS in IE. Please also check this documentation:
Data URIs are supported only for the following elements and/or
attributes.
object (images only)
img
input type=image
link
CSS declarations that accept a URL, such as background, backgroundImage, and so on.
Besides, IE doesn't have PDF viewer embeded, so you can't display PDFs directly in IE 11. You can only use msSaveOrOpenBlob to handle blobs in IE, then choose to open or save the PDF file:
if(window.navigator.msSaveOrOpenBlob) {
//IE11
window.navigator.msSaveOrOpenBlob(blobData, fileName);
}
else{
//Other browsers
window.URL.createObjectURL(blobData);
...
}
I'm writing a program for Booth's Multiplication as a JAVA Web Application in Netbeans 8.2. I am using selenium-server-standalone-2.50.1.jar and Firefox 46.
When I write my code and run it, it just opens the page but no tests happen. Please help.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*
*/
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class booth {
private WebElement element, element1;
public String str;
public void Mul_Positive(){
WebDriver driver = new FirefoxDriver();
driver.get("http://localhost:8080/BoothsMul/index.html");
element = driver.findElement(By.xpath("//input[#name='t1']"));
element.sendKeys("2");
str = driver.findElement(By.xpath("//input[#name='t1']")).getText();
System.out.println(str);
element1 = driver.findElement(By.xpath("//input[#name='t2']"));
element1.sendKeys("5");
str = driver.findElement(By.xpath("//input[#name='t2']")).getText();
System.out.println(str);
driver.findElement(By.xpath("//input[#name='submit']")).click();
driver.quit();
}
public void Mul_Negative(){
WebDriver driver = new FirefoxDriver();
driver.get("http://localhost:8080/BoothsMul/index.html");
element = driver.findElement(By.xpath("//input[#name='t1']"));
element.sendKeys("c");
str = driver.findElement(By.xpath("//input[#name='t1']")).getText();
System.out.println(str);
element = driver.findElement(By.xpath("//input[#name='t2']"));
element.sendKeys("5");
str = driver.findElement(By.xpath("//input[#name='t2']")).getText();
System.out.println(str);
driver.findElement(By.xpath("//input[#name='submit']")).click();
driver.quit();
}
public static void main(String[] args){
booth b = new booth();
b.Mul_Positive();
b.Mul_Negative();
}
}
My index.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<body>
<form name='f1' action='http://localhost:8080/BoothsMul/Boothmul' method='get'>
First No. <input type='text' name='t1'><br>
Second No. <input type='text' name='t2'><br>
<input type='submit' name='submit' value='submit'>
</form>
</body>
</html>
UPDATED:
If you're using selenium 3.0.1 or higher then JAVA version should be 1.8 also, you'll need to make use of geckodriver to run Firefox. (Make sure you are using latest versions of all the required component in this case)
Else, you need to upgrade your Selenium Version to 3.0 or higher.
Being new to TYPO3 fluid I was wondering if there's an easy way to create a link to a PDF-file which is located in the filelist as you would in simple html as follows:
Click here to open pdf (in a new window)
I couldn't find a solution so far that wouldn't require an extension or that wouldn't render the pdf direclty on the page (<flux:field.inline.fal name="settings.image" required="1" maxItems="1" minItems="1"/>)
Should/Can this be done with <f:link.external href="filePathOnServer/file.pdf"> ? (I've got another problem at the moment preventing me from checking if this works...)
EDIT
I've tried using <f:link.external> which didn't work. For the time being I'm using the (non-fluid) <a>-tag...
I had to do the same thing and I resolved it by writing a custom ViewHelper just to get the site url.
ViewHelper:
class InternalViewHelper extends AbstractViewHelper
{
/**
* Renders a link to a specific path from the root path of TYPO3.
*
* #param string $path The path to an internal resource relative to the TYPO3 site URL.
* #return string The absolute URL to the given resource.
*/
public function render($path)
{
$siteUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
return htmlspecialchars($siteUrl . $path);
}
}
Fluid Template:
{namespace ext = Vendor\MyExt\ViewHelpers}
<f:link.external target="_blank"
uri="{ext:internal(path: 'uploads/tx_myext/myfile.pdf')}">
Link
</f:link.external>
I am creating an openlaszlo application where an html tag will be present and i have some components that are draggable in the swf. I want to drag these components over the html. This is not possible.
So what i am thinking of is to take a screenshot of the html content and replace it with the actual html content when i need to drag over it.
Theoretically this should be possible and it's possible in flex I verified my self. I am trying to do the same thing in Openlaszlo. But i am not getting any leads
So far i have tried like this
And i am getting an error that the html tag is not object of IBitmapDrawable
<canvas width="800" height="600" bgcolor="white" debug="true">
<script when="immediate"><![CDATA[
class MagUtils {
#passthrough (toplevel: true) {
import flash.display.DisplayObject;
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.filters.*;
import flash.events.MouseEvent;
import mx.graphics.ImageSnapshot;
import flash.utils.ByteArray;
import flash.display.IBitmapDrawable;
}#
var temp:lz.view;
var colorTransform:ColorTransform;
var rect:Rectangle;
public function snap (m:IBitmapDrawable, t:lz.view):void {
temp = t;
var temp_mc = temp.sprite; // getMCRef();
var mainView_mc = main.sprite; // getMCRef();
var scale = 1;
var x;
var y;
var w;
var h;
var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(m);
var imageByteArray:ByteArray = imageSnap.data;
colorTransform = new flash.geom.ColorTransform();
rect = new flash.geom.Rectangle(0, 0, temp.width, temp.height);
var bitmap:BitmapData = new flash.display.BitmapData(w, h, false);
bitmap.setPixels(rect, imageByteArray);
var bm:Bitmap = new Bitmap(bitmap);
temp.sprite.addChild (bm);
bitmap = null;
}
}
lz.MagUtils = new MagUtils();
]]>
</script>
<button name="magnifier" text="magnifyingtool" >
<handler name="onclick">
lz.MagUtils.snap(canvas.main.ht,canvas.temp);
</handler>
</button>
<view name="main" x="5" y="15" width="200" height="200" bgcolor="yellow">
<html name="ht" width="200" height="200" src="http:hello.html"/>
</view>
<view id="temp" name="temp" x="5" y="300" visible="true" width="200" height="200" bgcolor="gray">
</view>
</canvas>
And the HTML Content is
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML>
<HEAD>
<TITLE>
A Small Hello
</TITLE>
</HEAD>
<BODY>
<H1>Hi</H1>
<P>Test Page</P>
</BODY>
</HTML>
It's no possible to take a screenshot in Flash of elements which are not managed by the Flash display list, which includes iFrame content placed below the SWF movie in the browser. And that seems to be what you are trying to do.
If you want to drag a visual object from the iFrame into the SWF movie area, one approach might be to render the content in HTML into an HTML5 canvas element, extract the bitmap data and push that into the SWF movie to be displayed in an OpenLaszlo view. But that would mean that all visual elements you want to drag need to be drawn into an HTML5 canvas.
Here is an example where uses Flash Player's filter functionality to apply the filter to an image in an HTML5 canvas element:
http://www.quasimondo.com/archives/000695.php
Here are the links to the relevant files for this example:
The HTML page embedding an invisible SWF for processing the image.
JavaScript file with functions for sending the data to the SWF movie clip.
ActionScript class processing the image data sent from JavaScript, and passing the processed data back to the HTML page.
But I'm not sure that all the content you have in your iFrame can be rendered into a canvas element.