Copy link to clipboard
Copied
Hi,
I would like to have my Adobe form to display a specific date with specific format. It works fine when the form is openend using any pdf reader, but when I try to open it using google chrome, it doesn't recognize the util.printd() function and only returns the current date.
Those are the lines that is not working properly:
var date = util.printd("dd/mm/yyyy", new Date(milliseconds));
this.getField("dateConverted").value = date;
Does anyone know what is going on or if there is another way to do this so Chrome can convert my date properly?
Copy link to clipboard
Copied
‌i'm amazed it supports any JavaScript. I think you need to insist on Reader or not use forms; expecting forms to work in other browsers is optimistic. Some ignore forms, some have limited support, and the default Mac browser breaks firms beyond repair.
IF you still want to know the specifics of what works in Chrome's PDF viewer you'd need to ask Google. If they tell you, please share!
Copy link to clipboard
Copied
The PDF Viewer in Chrome is an open source project, and you can review it's files and functionality here: GitHub - mozilla/pdf.js: PDF Reader in JavaScript
It is impressive what they have done with JavaScript and HTML5 to render PDF files, but it's functionality is still far from what you get with Adobe's desktop PDF viewers. Keep in mind when you create forms like this, they not only behave differently when viewed in non-Adobe viewers on the desktop, but also when you open them in Adobe Reader for mobile devices.
Copy link to clipboard
Copied
That's very interesting, but isn't it the PDF Viewer in FireFox, rather than Chrome? It mentions an extension for Chrome PDF Viewer - Chrome Web Store, but I'd expect that to be different from Google's built in viewer (since that requires no extension to be separately installed). cf Comparison Between Firefox PDF Viewer (PDF.js) and Chrome PDF Viewer | Techdows
Copy link to clipboard
Copied
That is possible, I probably got my "causing me and my customers nothing but headaches" PDF viewers in browsers mixed up ![]()
Copy link to clipboard
Copied
pdf.js is the PDF viewer of Firefox.
Copy link to clipboard
Copied
Chrome's PDF viewer (pdfium, initially supplied and still supported by Foxit) actually has pretty good support for JavaScript and does have at least some support for the util.printd method. What are you using for the milliseconds variable, exactly?
Copy link to clipboard
Copied
Hi George,
Basically, what I'm trying to do is: the user have to type the date and the number of days he wants to add to this date, and then the form will return the final date in a specific format (dd/mm/yyyy) in the field "dateConverted.
Example:
date: 23/02/2016
number of days: 30
dateConverted: 23/03/2016
This is what I did:
var numberOfDays = this.getField("numberOfDays").value;
var startDate = this.getField("startDate").value;
var numberOfDaysMS = 24 * 60 * 60 * 1000 * numberOfDays;
var startDateMS = util.scand("dd/mm/yyyy",startDate).getTime();
var milliseconds = numberOfDaysMS + startDateMS;
var date = util.printd("dd/mm/yyyy", new Date(milliseconds));
this.getField("dateConverted").value = date;
Copy link to clipboard
Copied
There is actually a simpler way to add a number of days to a date in JavaScript:
var numberOfDays = this.getField("numberOfDays").value;
var startDate = this.getField("startDate").value;
var newDate = util.scand("dd/mm/yyyy", startDate);
newDate.setDate(newDate.getDate() + numberOfDays);
this.getField("dateConverted").value = util.printd("mm/dd/yyyy", newDate);
However, I doubt that this will work in Chrome either.
Copy link to clipboard
Copied
Thanks, George and Karl!
I tried to do the way Karl pointed out but the result is just the same. The "dateConverted" field keeps returning the current date in Chrome's pdf viewer but It works perfectly in Adobes Acrobat Pro DC. Maybe I should try other ways to make the form more user friendly...
Thank you, anyway!
Copy link to clipboard
Copied
I think the problem is with the util.scand method. I seem to recall it sets the time differently than Acrobat/Reader does, but I'd have to go back and check my notes. But you can revise the code so that it's not needed, you just lose the convenience it provides. The code Karl provided might work, but since util.scand behaves differently, you'll want to do some testing.
Copy link to clipboard
Copied
I did just a bit of testing and it looks like the getTime method isn't implemented, but there are alternatives for what you're doing as Karl pointed out.
Copy link to clipboard
Copied
I just tested with the latest version of Chrome, and now it looks like there's a problem with util.printd, where there wasn't before. I'll post again if I find anything useful.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more