add the current date to a pdf (when opened in browser) - javascript

I currently have a javaScript in a pdf that adds the current date once the document is opened in adobe.
function dateToday()
{
var date = new Date();
field = this.getField("todayDate");
field.value = date;
}
dateToday();
Now I want to upload this documents on a Sharepoint. But logically when I open the docs in the browser the javaScript is not triggered and the date is not updated (also when printing).
Is there any way I can change the script so it triggers when the pdf is opened in a browser?
Or how can I change the script so that it instead prints an error message when downloaded and opened in Adobe?
Thanks!!

We use Muhimbi PDF Converter for SharePoint On-Open functionality to add Dynamic Content(Current Date, User name, etc). You can find more details at https://blog.muhimbi.com/2011/04/applying-user-specific-watermarks-when.html
They also provide various watermarking facilities for details see http://support.muhimbi.com/entries/23730002-What-are-the-watermarking-facilities-of-the-PDF-Converter-for-SharePoint-

Related

Replacement for active x object

I am working on developing Outlook appointment. I have a requirement where
I have to create a file and download it . When I open that file it has to open in outlook and create meeting request pop up without using active x . Is there any api developed by Microsoft. Its better if the snippet is from java script
Right now I am able to open pop up with Meeting request in Outlook from the web browser. I am able to do this by enabling Active x controls But it works in IE only. Moreover active x will not be supported by Microsoft in near future.
Current code
var outlookAppObj = new ActiveXObject("Outlook.Application");
var objNS = outlookAppObj.GetNameSpace("MAPI");
var theMailItemObj
=outlookAppObj.CreateItem(0);
theMailItemObj.display();
Your code above creates and displays a regular message. You can achieve the same result using a mailto: link.
For an appointment, create an ICS file and the user download it - Outlook will be happy to open it. the user can then click Save.
Prepare ics file as var finalAttachedData = "ATTACH;FMTTYE= application/vnd.openxmlformats-officedocument.wordprocessingml.document;ENCODING=BASE64;VALUE=BINARY;X-FILENAME=test.docx:"+base+"\n";
var icsMSG = ["BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Our Company//NONSGML v1.0//EN\nBEGIN:VEVENT\n" + finalAttachedData + "\nUID:me#google.com\nDTSTAMP:20120315T170000Z\nATTENDEE;CN=My Self ;RSVP=TRUE:MAILTO:me#gmail.com\nORGANIZER;CN=Me:MAILTO::testmail\nDTSTART:" + Date.now() +"\nDTEND:" + Date.now() +"\nLOCATION:" + "hyd" + "\nSUMMARY:Our Meeting Office\nEND:VEVENT\nEND:VCALENDAR"];

Adobe Reader Javascript Open .DOC

I just tried to many code from internet to open automatically .doc which are attached in PDF but i get this : "Cannot open type of application/msword"
I tried this:
var oDoc = openDataObject("image.doc"); console.println(oDoc.path);
I tried to find another function which are specify the type of the document and to can open it in Microsoft Word!
Regards
The openDataObject method will throw an exception instead of returning a Doc if any of the following conditions are true:
The document that this method is being called for does not contain the requested embedded data object.
The data object is not a PDF document.
Permissions forbid opening attachments by means of JavaScript.
Instead of openDataObject which tells the viewer to open the file, use exportDataObject with the launch parameter. 0 will prompt the user to save the file, 1 will save the file and launch it.
this.exportDataObject({ cName: "image.doc", nLaunch: 1 });

How to create a PDF file that will have initial view=Fit

I am trying to use the iText Stamper to change a PDF file so that it will always open with full page display. I tried,
PdfStamper stamper = new PdfStamper(new PdfReader(src), new FileOutputStream(dest));
PdfWriter writer = stamper.getWriter();
PdfAction action = PdfAction.gotoLocalPage(1, new PdfDestination(PdfDestination.FIT), writer);
writer.setAdditionalAction(PdfWriter.DOCUMENT_OPEN, action);
but DOCUMENT_OPEN is not defined. How can I do this? Should I be using instead stamper.addJavascript? but what JS code will setup the initial view?
I could use setPageAction(PAGE_OPEN, action, 1) and that works, but I think it might be annoying to the user if every time they look at page 1, the view changes.
BTW, initially I tried to use the PDF Open Parameters, but they are very unreliable. I displayed the pdf using
<embed src='myfile.pdf#view=Fit'>
and Adobe Reader often ignores the view for no apparent reason. That is why I am trying to set the initial view within the PDF itself.
Try this instead:
writer.setOpenAction(action);
Also see the documentation for setOpenAction.

Choose file window in extension firefox

Iam building an extension and i want to take the path of a file from a window popup like windows does . Is something like that to use in an extension in firefox?
You should check out this page on MDN
Creating a file picker
To begin, you need to create a file picker component and initialize it.
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["#mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(window, "Select a File", nsIFilePicker.modeOpen);
First, a new file picker object is created and stored in the variable
'fp'. The 'init' function is used to initialize the file picker. This
function takes three arguments, the window that is opening the dialog,
the title of the dialog and the mode. The mode here is modeOpen which
is used for an Open dialog. You can also use modeGetFolder and
modeSave for the other two modes. These modes are constants of the
nsIFilePicker interface.
Getting the selected file
Finally, you can show the dialog by calling the show() function. It
takes no arguments but returns a status code that indicates what the
user selected. Note that the function does not return until the user
has selected a file. The function returns one of three constants:
returnOK - the user selected a file and pressed OK. The file the user
selected will be stored in the file picker's file property.
returnCancel - the user pressed Cancel.
returnReplace - in the save
mode, this return value identifies that the user selected a file to be
replaced. (returnOK will be returned when the user entered the name of
a new file.) You should check the return value and then get the file
object from the file picker using the file property.
var res = fp.show();
if (res != nsIFilePicker.returnCancel){
var thefile = fp.file;
// --- do something with the file here ---
}

Auto Save a file in Firefox

I am trying to find a way where by we can auto save a file in Firefox using JS. The way I have done till yet using FireShot on a Windows Desktop:
var element = content.document.createElement("FireShotDataElement");
element.setAttribute("Entire", EntirePage);
element.setAttribute("Action", Action);
element.setAttribute("Key", Key);
element.setAttribute("BASE64Content", "");
element.setAttribute("Data", Data);
element.setAttribute("Document", content.document);
if (typeof(CapturedFrameId) != "undefined")
element.setAttribute("CapturedFrameId", CapturedFrameId);
content.document.documentElement.appendChild(element);
var evt = content.document.createEvent("Events");
evt.initEvent("capturePageEvt", true, false);
element.dispatchEvent(evt);
But the issue is that it opens a dialog box to confirm the local drive location details. Is there a way I can hard code the local drive storage location and auto save the file?
If you are creating a Firefox add-on then FileUtils and NetUtil.asyncCopy are your friends:
Components.utils.import("resource://gre/modules/FileUtils.jsm");
Components.utils.import("resource://gre/modules/NetUtil.jsm");
var TEST_DATA = "this is a test string";
var source = Components.classes["#mozilla.org/io/string-input-stream;1"].
createInstance(Components.interfaces.nsIStringInputStream);
source.setData(TEST_DATA, TEST_DATA.length);
var file = new FileUtils.File("c:\\foo\\bar.txt");
var sink = file.openSafeFileOutputStream(file, FileUtils.MODE_WRONLY |
FileUtils.MODE_CREATE);
NetUtil.asyncCopy(source, sink);
This will asynchronously write the string this is a test string into the file c:\foo\bar.txt. Note that NetUtil.asyncCopy closes both streams automatically, you don't need to do it. However, you might want to pass a function as third parameter to this method - it will be called when the write operation is finished.
See also: Code snippets, writing to a file
Every computer has a different file structure. But still, there is a way. You can save it to cookie / session, depends on how "permanent" your data wants to be.
Do not consider writing a physical file as it requires extra permission.

Categories

Resources