Quantcast
Channel: Adobe Community : Popular Discussions - JavaScript
Viewing all 12130 articles
Browse latest View live

Calculate years (age) between two dates

$
0
0

Good day!

 

I haven't been able to find an answer I've been able to use in the archives or online, and would very much appreciate some help.  I am working with Adobe Acrobat Pro XI (not LiveCycle), and have very limited programming experience (mostly copy / paste).

 

I need to create a text box that calculates the number of years between two entered dates, i.e. age when date of birth and date of death are given.  It would also be nice if it were blank until both were provided.  Would someone be able to give me the code I'd need to put in the custom calculation script?

 

Again, any help would be much appreciated!  Thanks and have a wonderful day!


Change fill color in drop down menu based on input

$
0
0

Hello everyone,

 

I have a PDF document that I'm currently working with and having trouble creating one of the elements. This document is a quarterly status report. It has boxes for Indicators, Data Sources, etc.

 

The last field is just called "Status". I turned this field into a drop-down menu with 3 options - In Progress, Needs Review, Completed. I would like the user to be able to select one of these options from the drop down menu and have the fill color of the box (field) change based on their selection. If they select "In Progress" the box changes to yellow, "Needs Review" the box changes to red, "Completed" the box changes to green. Because this document will be used by many people, the colors will provide a quick snapshot as to which projects/activities are on task and which needs to be addressed.

 

Again, based on their selection:

"In Progress" = yellow

"Needs Review" = red

"Completed" = green


The background color can be white or transparent when no options are selected.

 

I've been searching and have found a few examples, but nothing close to what I'm looking for. Is this possible to do, and could someone please provide the custom validation script? I know this option is easy and available in Excel, unfortunately there's no smooth way to convert the document without hours of clean up.

 

I appreciate any help!

Error message: trim is not a function

$
0
0

I cannot get the standard string Trim() method to work in Acro Pro 11.

What's up with that ?

Any workarounds ?

app.mailMsg help

$
0
0

I am using app.mailMsg method in my Acrobat form to create an email message . While using this method, I am facing following problem

 

1) Unless the email send button is clicked, I can't access adobe and outlook

2) Once the email send button is clicked, outlook sort of hangs. I have to close the Adobe application to bring back outlook to its normal state and physically send the email from the outlook outbox.

 

Please help. Looks like I am missing some command in my Java script that actually closes the mail connection or logoffs the sessions.

Create new folder

$
0
0

Hi all,

 

I create batch script to extract pages in one PDF into separate files. I want to create new folder automatically using this script so I could save output files into that new folder.

 

I have searched on Javascript for Acrobat API reference, but I could not find a way to create new folder using this Javascript for Acrobat.

 

So, my question is might I create new folder using script?  Or I must use Acrobat SDK?

 

 

Thank you,

 

Rocky

 

Message was edited by: Rocky H

help to improve javascript function

$
0
0

Hi, my bellow code is work fine. this code i'm using to change text fields font size into 10. always font size is not the 10. so what i want to do is, after running this code, it should give popup window to type custom font size & based on that all text fields text size should change. hope my request is clear. thanks in advance.

 

my code


 

if (app.viewerVersion < 10) {

    app.addMenuItem({ cName: "ChangeFontSize", cUser: "Change Font Size", cParent: "Tools",

    cExec: "ChangeFontSize(this)", cEnable: "event.rc = (event.target != null);"});

} else {

    app.addToolButton({ cName: "ChangeFontSize", cLabel: "Change Font Size", cTooltext: "Change Font Size",

     cExec: "ChangeFontSize(this)", cEnable: "event.rc = (event.target != null);"});

}

function ChangeFontSize(doc) {

    for (var i = 0; i < doc.numFields; i++) {

           var f = doc.getField(doc.getNthFieldName(i));

        switch(f.type) {

   case "text":

              f.textSize =10; 

             break;

             }

       }

}

How to export the XFDF file from the PDF?

$
0
0

I need to export as XFDF file from the PDF and then save that xfdf file in the same location through javascript. I used this.exportAsXFDF(); for exporting. But i dont know how to save that xfdf file through scripting. Kindly advice me. This is for Acrobat 8.0 professional and windows platform.

exportAsFDF method fails to export Comments made unless a document is Reader Extended

$
0
0

Problem-Description:

Adobe Reader 11 JavaScript exportAsFDF method fails to export Comments made unless a document is Reader Extended

 

Method:

1. Open a document that has NOT been Reader Extended

2. Add comments to the PDF file

3. Use the following JavaScript to export comments

 

// Import permission

statImport = PDDocPermRequest(pdDoc,PDPermReqObjAnnot,PDPermReqOprImport,NULL);

sprintf(szMsg,"canLoadMarkup() AnnotPerm(import)= %d.\n",statImport);

traceMsg(szMsg);

// Export permission

statExport = PDDocPermRequest(pdDoc,PDPermReqObjAnnot,PDPermReqOprExport,NULL);

sprintf(szMsg,"canLoadMarkup() AnnotPerm(export)= %d.\n",statExport);

if (statImport == 0 && statExport == 0)

{

// see ShowPermissions.cpp from Adobe Plugin SDK sample.

// statImport = -1 - permission denial

// statImport = 0 - permission granted

// statImport >= 1 - permission either unknown or pending

sprintf(szMsg,"##### reader and permissions granted: %s", prodName);

traceMsg(szMsg);

retFlag = TRUE;

}

else

{

sprintf(szMsg,"%s: Reader implies NOT okay to load markup", prodName);

traceMsg(szMsg);

retFlag = FALSE; // Reader can not load markup.

}

 

Result:

No comments are exported

 

Expected:

That if the file allows commenting via checking the PDDocPermRequest then it should also allow exporting comments.


How do i use Select file dialog box in acrobat 7.0 using js?

$
0
0
hi,

I need to use file selecting dialog box in acrobat 7.0.

i already used in indesign scripting like

var f=File.selectDialog("Select a indesign file");

this will return that selected file path.

how can i use it in same acrobat 7.0

regards,
Subha_oviya

Form Field Label

$
0
0

I'm not sure if the is the right place to post my question I've posted it under forms <http://forums.adobe.com/thread/996327> with no success hoping that someone might be able to help me here:

 

I have the same question as this thread <http://forums.adobe.com/thread/756410> plus a little bit extra.

 

So the answer (which has worked out wonderfully) was submitted by George:

 

// Custom format script for text field

if (!event.value) {

    event.value = event.target.userName;

    event.target.display = display.noPrint;

} else {

    event.target.display = display.visible;

}

 

But as George eluded in his first post in the thread was:

The problem with this approach is it precludes easily using any of the built-in formats that you may want to use (Number, ZIP code, etc.). You still can, but it requires more scripting.

 

So how can I get the combination of the Form Field Lable being displayed and also the auto formatting for Phone numbers, Zip Codes etc.?

 

Any help is greatly appreciated.

 

I'm running Acrobat X Pro on Windows if that matters.

 

Message was edited by: chad Snelson

Updated question:

So I was thinking about it some more and remembered seeing this line of code:

event.value = util.printx("99-9999999", event.value); From <http://forum.planetpdf.com/wb/default.asp?action=9&fid=34&read=43365>.

 

And then the Arbitrary Mask formatting option

<http://help.adobe.com/en_US/acrobat/standard/using/WS58a04a822e3e50102bd615109794195ff-7de 4.w.html>

and it appears that the tax id line of code uses those same guide lines.   So is there away to use George's section of code and combine it with the tax id line of code and just use the Arbitrary Mask formatting rules so if one text field was for a zip use George's section and just change the tax id line so instead of all the nines it would just have 99999 ? If this makes any sense or is possible if someone could please reply with an example I'd greatly appreciate it!

 

So I was playing around with combining both soultions and just added the Tax ID formatting to George's part and came up with this:

 

// Custom format script for text field

if (!event.value) {

    event.value = event.target.userName;

    event.target.display = display.noPrint;

} else {

    event.target.display = display.visible;

    event.value = util.printx("99-9999999", event.value)

}

 

So that works great if you put in a total of nine numeric characters but if you input letters then it still lets you it just doesn't show them verses the arbitrary mask formatting option where it doesn't even let you put in letters and requires the right about of numeric characters.

 

So my new question/problem is how to only allow numeric characters to be entered and require the right ammount of characters with the above code?

Use commitKey to change value in next field

$
0
0

if (event.commitKey == 3){myTrustedFunction(this);} So I want to run this function on a specific field after tab is used in this field. Instead of this I would like to use

var school=doc.getField("SCHOOL NAME");How can I run this function on this specific field. The tab is going to this field also. So it goes like this enter value tab value for next field is automatically entered. Bam.Tab to next field.

Extract PDF Form Data Using JavaScript and write to CSV File

$
0
0

I have been given a PDF file with a form.  The form is **not** formatted as a table.  My requirement is to extract the form field values, and write them to a CSV file which can be imported into Excel.  I have tried using the automated "Merge data files to Spreadsheet" menu item in Acrobat Pro, but the output includes both the labels and the values.  I am mostly just interested in the form field values.

 

 

I would like to use JavaScript to extract the form data, and instruct JavaScript how to write the CSV (since I know what the end spreadsheet should look like).  I got as far as extracting the form fields:

 

 

this.getField("Today_s_Date").value;

 

 

And following this post: http://stackoverflow.com/questions/17422514/how-to-write-a-text-file-in-acrobat-javascript , I tried to write to CSV using:

 

 

var cMyC = "abc";

var doc = this.createDataObject({cName: "test.txt", cValue: cMyC});

 

 

but I get the following error:

 

 

"SyntaxError: syntax error

1:Console:Exec"

 

 

Ideally, I do not want to use an online third party tool to do this, because the data is sensitive.  But please let me know if you have suggestions.  The ideal output will be a CSV file that an end business user can open in Excel to see the spreadsheet format of her choice.

 

 

Has anyone done this before?  Open to hearing any alternative solutions as well.  Thanks in advance!

Javascript in Dynamic Stamp Won't Execute

$
0
0

I have followed directions to create a dynamic stamp that asks for a reference number.  I went into create a custom stamp, chose the stamp image file, saved it to the Dynamic category with a unique name, opened the stamp file from the "user\AppData\Roaming\Acrobat\11.0\Stamps" folder, created a text box, input the custom calculation script, and saved the file.

 

The javascript executes when creating the dynamic stamp.  However, after saving the stamp and then using it on a PDF file, the stamp shows up but the script doesn't execute.  I just get the image.  I do not get the text box that I created nor does the script run that asks for input.  Anything obvious I should be watching for?  Here is the script that I entered (which I copied and amended for my intended use):

 

var cResponse = app.response({

cQuestion: "Enter the working paper reference",

cTitle: "WP Ref:",

cLabel: "Working paper ref:"

});

if (cResponse == null) {

event.value = "*INVALID*";

}

else

event.value = cResponse;

 

Many thanks!

How to disable alerts in Adobe

$
0
0

I want to make it so this pop up alert no longer occurs.

 

Capture.JPG

 

It happens every time I open a Outlook message that I converted to a PDF. I do not need Flash. I hit cancel and the document opens up fine and displays correctly. How can I make it so this pop up doesn't occur and acts as if I hit cancel WITHOUT having to download Flash? I work for State Government and downloading anything is a huge pain in the butt. Downloading and installing anything requires permission AND help from the IT department, and my whole office would have to do it because we all open these PDF files with FileDirector and this dang pop up alert happens every time. Is there a way to edit the Adobe settings or code so that this message (or any message for that matter) can be disabled?

 

Thanks.

SetLock and getLock methods in VBA

$
0
0

Hello community,

 

This is my first post here and I have a couple of question for you concerning a very particular point : I need to add a signature field that would lock all other fields in my form whe signed. I don't want to sign yet, just to add the field. This is quite simple when doing it manually, it's just a radio button to change in the properties of this field:

Capture.PNG

 

My problem is : I would like to do it using Javascript /VBA (JSObject). I'm able to add the field, but not to execute the getlock nor the setLock methods, so signing this field don't change anything to the rest of the fields.

 

Here is my code : !

Sub AddSignature()

Dim AcroApp As Acrobat.CAcroApp
Set AcroApp = CreateObject("AcroExch.App")
Dim docuPDF As Acrobat.CAcroPDDoc
Set docuPDF = CreateObject("AcroExch.PDDoc")
Dim jso As Object
Dim path As String
Dim position(3) As Integer
path = Application.GetOpenFilename("PDF Files (*.pdf), *.pdf", 1, "Choose your file")


If docuPDF.Open(path) Then
    Set jso = docuPDF.GetJSObject    If Not jso Is Nothing Then        Dim f As Object        Dim oLock As Object               position(0) = 414          position(1) = 73          position(2) = 526          position(3) = 40                 Set f = jso.addfield("Signature1", "signature", 0, position)        Set oLock = f.getLock()  '<---This is here my code stops working : "Object requiered" erreur        Set oLock.Action = "All"        If f.setlock(oLock) Then            MsgBox "It worked"        Else            MsgBox "Nope"        End If        Set oLock = Nothing        Set f = Nothing           End If
End If
Set jso = Nothing
Set AcroApp = Nothing
Set docuPDF = Nothing
End Sub

 

(inspiration : http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_developer_guide.pdf#page= 82)

 

My code stop working when I try to get the oLock object of my signature. If I try to read it in another procedure, I'm only able to get something if the property as been manually entered.

 

Any clues? Would I ever be able to use the setLock method or should I better look towards the setAction method to transform all fields to readOnly (How to lock a fillable pdf from within Adobe Reader (Acrobat Reader))? If I choose the setAction path, what would be the event I need to call (e.g. "MouseUp" or else) ?

 

Thanks for all of your answers.


how to find pdf page size and display alert message?

$
0
0

hi

i need to process thousands of pages every day and some of them are wrong size (i.e. not matching say 300mm X 500mm).

how can i set a javascript so that if a pdf is not 300X500 mm it would pop up an alert?

thanks in advance

arjun

Forcibly terminating Acrobat Script with "exitapp"

$
0
0

I have an Adobe XI javascript that checks several input parameters before executing.  If any of these parameters do not meet specified criteria, then I print out a message and abort the script.  I am using the command "exitapp" to abort, and this seems to work.  My question is: is "exitpp" a legitimate javascript command?  I cannot find this command in any of the javascript references.  Yet it appears to work fine for me on 2 pc's -- one running Adobe Acrobat XI Pro and the other running Adobe Acrobat XI reader..  I'm concerned that the script may fail when I distribute it to others if this is not a legitimate command.

autofill date fields with today's date - Acrobat DC ?

$
0
0

I had auto fill a form field with today's date working well in Acrobat 10, but having trouble getting it working in Acrobat DC.

 

I have a form with 3 date fields named Date_1, Date_2, and Date_3.  I would like to set all 3 to Todays Date if the form is opened and these fields are empty.

 

Here is the code I created:

 

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------

//<Document-Level>
//<ACRO_source>Enter Todays Date If Blank</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:Enter Todays Date If Blank ***********/
function EnterTodaysDateIfBlank()
{
var f = this.getField("DATE_1");
if (!f.value) f.value = util.printd ("m/d/yyyy", new Date());
var f = this.getField("DATE_2");
if (!f.value) f.value = util.printd ("m/d/yyyy", new Date());
var f = this.getField("DATE_3");
if (!f.value) f.value = util.printd ("m/d/yyyy", new Date());
}

//</ACRO_script>
//</Document-Level>

_________________________________________________________________________

 

I see no JavaScript error message for the above.  I am not sure how to "trigger" execution of this function upon form opening.

 

There is ample documentation for this on earlier versions of Acrobat on the web, but very little posted on Acrobat DC.

how to enable Javascript in Windows 10

$
0
0

I recently upgraded to Windows 10.  I keep on getting an error message everytime I look at a ,pdf file.  Arcobat wants to register but can't because it can't connect says the cause maybe my Javescript isn't enabled.  In Jave the box is checked enabling Java in my browser.

Launch Reader from PDF file in Google Chrome browser PDF viewer

$
0
0

Hello!

 

So I have a fillable PDF form which runs document level JavaScript to essentially render itself inactive (hides fields, etc.) if opened in anything other than Reader or Acrobat. This works great, especially in Google Chrome has known problems with submitting fillable PDF forms properly.

 

Here is an example form: https://luxsci.com/forms/6296/2251/Qlg5/Medical_Center_Intake_Form.pdf

 

Open in Chrome and it's unusable, there's a warning layer, and a JavaScript alert. Open in Reader or Acrobat and it renders fine and submit works great.

 

When the file is downloaded in Chrome it's saved locally, i.e. Chrome displays the file URL as: file:///C:/Users/David/Downloads/Medical_Center_Intake_Form%20(3).pdf

 

I am trying to make the process of opening the file from Chrome in reader as simple as possible for the end user. As such, I am wondering if there is a way to add a button which will launch Reader on the end-user's desktop/laptop and open this file?

 

Any advice would be greatly appreciated!


Thanks!

Viewing all 12130 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>