Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Google chrome doesn't recoginize the util.printd() function

Community Beginner ,
Feb 23, 2016 Feb 23, 2016

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?

TOPICS
Acrobat SDK and JavaScript
1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 23, 2016 Feb 23, 2016

‌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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2016 Feb 23, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 23, 2016 Feb 23, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2016 Feb 23, 2016

That is possible, I probably got my "causing me and my customers nothing but headaches" PDF viewers in browsers mixed up

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2016 Feb 23, 2016

pdf.js is the PDF viewer of Firefox.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 23, 2016 Feb 23, 2016

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 23, 2016 Feb 23, 2016

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2016 Feb 23, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 23, 2016 Feb 23, 2016

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 23, 2016 Feb 23, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 23, 2016 Feb 23, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 23, 2016 Feb 23, 2016
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines