Open a PDF in browser disable the embedded Javascript - java

I created a wicket page which allow to the user to open PDF files. These PDF files are forms, which the user fill and send back. There is also Javascript which is used to automatically fill some fields.
The file is correctly open in the browser but there is a problem: Javascript is disabled and I don't know why. Is it normal? Is it for security reason?
When I download the file and open in Acrobat Reader, it works correctly.
I also disabled the option in Acrobat Reader to force the plugin to be used in place of the default reader of the browser. It works only in Firefox.
Is it possible to activate Javascript?
If not, is it possible to open automatically Adobe Reader?
I prefer not to save directly the file if possible.

If you talk about smartforms, you have to enable JavaScript in Acrobat. It has to be similar in browser or standalone. Also there can be many security reasons in different browsers due to enable/disable JS itself. One of the common reason is XSS voluentabirity. Also you have to know if the browser or its plugin supports JS. Not all browsers use Acrobat reader as well. However see http://www.smartforms.business.gov.au/DeveloperResources/Documents/JavaScript_Instructions.pdf how to enable JS in Acrobat Reader.
Generaly I do not recommend you to use PDF forms instead of HTML forms.

Related

Jsoup get dynamically generated HTML

I can connect to most sites and get the HTML just fine but when trying to connect to a website where most of the content is generated after the initial page load with JavaScript, it does not get any of that data. Is there any way to do this with Jsoup or does it not support it?
JSoup has some basic connection handling included, but it is not a web browser. It excels at parsing static html content. It does not run any javascript, so you are out of luck. However, there are different options that you might follow:
You can analyze the page that you want to retrieve and find out how the content you are interested in gets loaded. Often it is not very hard to tap the original source of the loaded content and work with this. This approach has the benefit that you get what you want with no need of extra libraries and the retrieval will be fast.
You can use a (full) browser and automate the loading of the page. A very good tool for this is selenium webdriver in combination with the headless webkit browser phantomjs. This however requires extra software and extra libraries in your project and will run much much slower than the first solution.

Java How to close PDF from using pdf javascript?

I'm using a servlet to send a pdf stream to a browser.
There is a request that the pdf must open the print dialog when I show it to the user.
I was successful doing this using iText api. Something like this:
stamper.setPageAction(PdfWriter.PAGE_OPEN, new PdfAction(PdfAction.PRINTDIALOG), 1);
Now I do need to close the pdf file after print. I tried using pdfactions, but I'm can't get it. What I tried is:
writer.setAdditionalAction(PdfWriter.DID_PRINT, PdfAction.javaScript("app.execMenuItem('Close');", writer));
or
writer.setAdditionalAction(PdfWriter.DID_PRINT, PdfAction.javaScript("app.close();", writer));
I don't necessarily need to use pdfActions, but I don't see how to get it after user sent the pdf to printer.
Do you have any ideas?
There's a reason why app.execMenuItem('Close'); and app.close() don't work. These methods are designed to close the standalone version of Adobe Reader/Acrobat. I guess you're viewing the PDF in a browser, in which case you use Adobe Reader as a plug-in, Chrome's PDF viewer, pdf.js in Firefox, or any other PDF viewer.
Problem #1: you need to close the browser window from a PDF document. PDFs don't have the power to control your browser. Suppose they would: wouldn't that be a serious security issue?
Problem #2: you embed the PDF inside a HTML page (e.g. using an <object> tag) and establish a communication between the JavaScript in the PDF and the JavaScript in the HTML. I've described how to do this in my book, but: it won't work with all browsers on all OSs. For instance: Chrome's PDF viewer and Firefox's pdf.js will completely ignore your commands.
You are asking a solution using our iText library, but you're asking something that can't be done with any software.

Direct file upload using Ajax or JQuery (with or without a form)

I'm trying to use the second "Direct file upload" method described at the end of the page here: http://www.playframework.org/documentation/2.0/JavaFileUpload
How do I implement the required Ajax/Jquery/Js function that will allow me to use this? Can anyone please provide some hits or snippets?
Thanks.
You cannot upload files using AJAX. At least not in browsers that do not support the HTML5 File API. For those browsers you could use some existing file upload control such as Uploadify, Blueimp File upload, Valums File Uploader, ...
Those controls detect whether the browser supports the File API and it will use it. If it doesn't it will use other techniques such as using hidden <iframe>, Flash, Silverlight, ...

How to show the printable document directly in acrobat with out saving?

I am using PD4ML to print a PDF file and It is working fine. Now the thing is I want show that file directly in acrobat with out save that file. In Local version I am using
Program.launch(getFilePath());
It is working fine but in web version I am unable to get that.
Can you please suggest me, Its very helpful.
Thanks,
Vara Kumar PJD
The web isn't like your desktop, so forget about doing things on the web the way you do them on the desktop without at least some effort.
Know that you don't read PDF files on the web using Acrobat without a browser plugin. Or some other reader like Foxit Reader.
My recommendation: forget about doing it this way. Either server your pdf as a file that can be downloaded, or read this SO post about embedding PDF in HTML.
I don't think this will be possible: "showing file outside browser in an application without user consent" because that is how browser are made for security reason. The best you can do is, as pointed in earlier post is by darioo, to show file in browser or prompt user to download/open.

Multiple file uploader with previews

I'm trying to find something that will let users upload multiple files to a website. The requirements are that it let them easily select multiple files (preferably with something like check boxes) and that it displays a preview of the images they select.
I'd prefer to only use Javascript or Flash if possible, but Java is also an option (this needs to work on platforms where Silverlight isn't available).
So far all I've been able to find are things that use the native file selector (which doesn't show previews on Windows, and makes it unclear that you can select multiple by holding ctrl).
I'm not sure if the preview requirement is even possible, but it's the most important.
This is a firefox solution:
It uses the FileReader javascript object to load, display and upload images.
http://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/
It still doesnt show previews in the FileSelection dialog but at least allows you to preview the images before uploading.
And here is a ready made java applet solution:
http://jumploader.com/doc_overview.html
To upload multiple files I use RichFaces rich:fileUpload component.
Concerning the preview, I've got the similar problem and the best I found after couple of days of googling is following.
Alfresco has the same problem and resolved it with :
An open office which runs in server mode (socket) and all the office documents are sent by alfresco to open office in order to convert them in PDF
Those PDF are converted to .swf viewer thanks to SWFTOOLS
This .swf is integrated in the HTML
For images, it uses ImageMagick to create small version of the file I suppose
Personnaly, I will try to implement it this way :
Converting office documents to PDF thanks to open office in socket mode
Transform the first page of the PDF into a PNG thanks to JPedal library
Diplay that PNG to the end user
For images I would perhaps use ImageMagick too ... but for now, I'm using Seam Image.scaleToFit API
I am assuming 2 things here:
1) Some kind of client/enduser will be doing the file upload
2) You get some kind of say on what the client installs on their computer to help make this happen.
If this is the case, my first suggestion would be:
Give them FTP or SFTP client software to upload files. The php page you make can have a link to Filezilla, along with instructions on how to use it. ftp and sftp are THE protocols to use for transferring files. HTTP is just not designed(well) for it, nor are browsers.
Once the user has the (S)FTP client software installed, you can give them URL's to upload files to that are specific to their user account, and you can have a backend script process and load/move files that they upload. It's pretty easy to create a local temporary directory using a server side script, have the client upload files via ftp, then go back to the web browser and click a button that says "Done uploading, please process my stuff".
The browser can even give back confirmations on everything that gets uploaded/processed.

Categories