We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

JavaScript closeDoc and Web Browsers

Hi,

I am implementing an ASP.NET application for distributing various documents on demand as PDF. The restrictions I build (printing, etc) and the JavaScript I embed work fine in Acrobat Reader, but not in web browsers. I’m guessing that I need to restrict the document so that it can be opened only by Reader. Is that possible?

Hi Steven,

As I can understand, the PDF files are opened in browser using the Adobe Reader etc. So, the properties should be working fine over there as well. I’m afraid, there is no way to restrict that a PDF file can’t be viewed using the web browser. However, if you could elaborate your issue with the help of a sample file and other details etc. that would be great to understand the problem and then help you out accordingly.

We’re sorry for the inconvenience.
Regards,

Thanks for the reply. Part of the problem was me - while working on the project, I broke the part that sets the printing restrictions, etc. That is working, and was never a problem. Sorry for the false alarm there.

The part that I still have trouble with is the embedded JavaScript. We require that the document close itself after displaying a message, under certain conditions. My C# code is:

String jscode = “app.alert(‘You are not authorized to read this document!’);this.closeDoc(true);\r\n”;

PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf(inputFile);
editor.AddDocumentAdditionalAction(PdfContentEditor.DocumentOpen, jscode);
editor.Save(outputFile);

This works fine when Acrobat Reader opens the document. When opened by a browser, the alert is displayed, but the document remains open. This tells me that closeDoc does not work in browsers. If we can not implement this in both Reader and browsers, then I thought the next best thing would be to prevent it from being opened by anything but Acrobat Reader. Any ideas would be welcome.

I have attached a small example, output.pdf

Thanks for your time.



Hi Steven,

I have tested the sample file and got the idea of your requirement. I’m afraid, we need to investigate whether this is feasible or not. I have logged this issue as PDFKITNET-19915 in our issue tracking system. Our team will look into this issue and you’ll be updated with the results accordingly.

We’re sorry for the inconvenience.
Regards,

Hi,

I understand that this question is being looked at by your team. Is there any way to know when more information may be available? We have been asked for an anticipated delivery date. I can continue to wait if I have some idea of the time frame in which we are working.

Thanks

Hi Steven,

I’m afraid, the ETA is not available at the moment; however, I have asked our development team to share the ETA for this issue. You’ll be updated as soon as a response is received from our team.

We’re sorry for the inconvenience.
Regards,

Hi Steven,

Our team has further looked into this issue and I would like to share with you that closeDoc method doesn’t work in web browsers due to security limitations. Also, it is not guaranteed that the PDF file will be opened with enabled JavaScript; that’s why it is not feasible to control privileges using JavaScript.

I hope you understand. We’re sorry for the inconvenience. If you have any further questions, please do let us know.
Regards,


OK. Thanks for taking the time to look into that. What about the question of preventing a browser plugin from opening the PDF at all, restricting it to Reader or Acrobat?

Hi Steven,

The only reliable way to secure the PDF files could be to protect it using a password as shown in the following code snippet:


PdfFileSecurity fileSecurity = new PdfFileSecurity(“input.pdf”, “output.pdf”);

fileSecurity.EncryptFile(“password”, “”, DocumentPrivilege.AllowAll, KeySize.x256, Algorithm.AES);

However, in that case, the user will have to enter the password while opening the PDF using either a web browser or Adober Reader etc. Other than that, I'm afraid, there is no way to secure the PDF file only in a web browser.

We're sorry for the inconvenience. If you have any further questions, please do let us know.
Regards,

Thanks. I appreciate the responsiveness. Your customer service is very good.