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

How to Count total number of Words in PDF?

$
0
0

I am used Adobe Acrobat javascript inbuilt function getPageNumWords(<pagenumber>) it return the number of words present in specified page, but while am copy and paste text content from PDF file to MS Word, Words count given by MS Word is little bit differ, so any one know in which aspect Acrobat count the words?

Which words count result is correct?

Shall is go with Acrobat Words count result or MS Words count result?

But I want to count the total number of words in PDF file (my input is PDF file) else can I go with iText?

Words count in PDf using iText is possible?


Check to see if any field is empty

$
0
0

I have a pretty large document that has over 200 text/check boxes. What I want to do is create a button that makes a pop-up warning for any blank fields in the entire document.

 

Right now the only way I've seen to do this is using javascript using an array of every field and checking them 1 by 1 in a for-loop. I would like to avoid this as the array requires you to type the title of each field so with 200+ fields it becomes quite tedious typing them all in.

 

Currently my code looks something like this:

var a1 = new Array(getField("box1"), getField("text1"));

for (number of items in a1)

   check if empty

      popup box if empty

 

Is there an easier way to do this without typing in the name of every field?

 

Using Acrobat XI Pro, thanks.

Open Data Object - Open File attachment within pdf document

$
0
0

I am trying to build a script which will open file attachments embedded in a pdf document.

 

I have used the following javascript to list all embedded files within a document so I can retrieve the name

 

var d = this.dataObjects;

for (var i = 0; i < d.length; i++)

console.println("Data Object[" + i + "]=" + d[i].name);

 

The console reported:

 

Data Object[0]=MTP-300-X-1210_A.pdf

Data Object[1]=MTP-300-X-1240_A.pdf

 

 

I then used the following script to open the file     

 

this.openDataObject("MTP-300-X-1210_A.pdf");

 

Console reports back as follows and does not open the file:

 

[object Doc]

 

Can anyone please offer assistance in how to open an embedded pdf attachment within a document?

 

Many thanks!

How becomes poor in one print?

$
0
0

This is not a Joke

 

For Acrobat 10.1.10, please, follow the next steps:

 

 

- Open  my “Lol.PDF” (PDF file must contain type 1 fonts)

 

https://workspaces.acrobat.com/?d=ZAvzEMTb42PNKlnJcDve5A

 

Pause a PCL printer , and set offline “Use printer Offline

Open JavaScript console

Copy, paste and execute the following lines:

 

var pp = this.getPrintParams();
pp.interactive = pp.constants.interactionLevel.automatic;
pp.interactive = pp.constants.interactionLevel.silent;
pp.printerName = "MyprinterName";
this.print(pp);
this.closeDoc(true);

-----------

Don’t forget to change to your printer name, before execute.

 

Print out the file or ecofrienly check your SPL file (google search the  “SPLView”, nice work, thank you Mr Dieter )  usually in ”C:\WINDOWS\System32\spool\PRINTERS”

 

All graphics will print correctly. Characters are changed for next one in the ANSI character set.

ie:“0” prints as “1”, “1” prints as “2” , “A” prints as “B”

 

This also happens (some times), printing large amount of PDF files (1 of 400), without setting the printer in Offline mode,

 

There are a fews workarounds:

- Printing text as graphics, but a 300kb file becomes a 70MB file (i have more than 800 files to print often)

- Buy a PS printer,

- Give enough time to acrobat, do not execute the last line "this.closeDoc(true)"

 

It’s a old BUG (Google search “gobbledygook my adobe acrobat pdf files are printing garbage text sometimes", this is one more step. I hope someone can fix it.

JavaScript Validation to Submit Form

$
0
0
Hi,

How do you validate all the fields in JavaScript when the user clicks the Submit button so that if any required fields are empty or any field validation fails, nothing (submission, JavaScript code, execute menu items, etc.) will be executed? I found something about execValidate() but it didnt work for me. It wouldnt do anything. I am using Adobe Acrobat Professional 8.0.

For instance, I have a field set up to accept numbers between 1111 and 9999. If the user enters 1 and tabs out of the field, he gets an error message and the value is deleted. The field is also set as a required field. But if the user clicks the Submit button, all JavaScript code will be executed, menu items too. The only thing that fails is "Submit a Form" only for the required field part. What can I include in the JavaScript code to check if all fields are valid, according to their corresponding rules, and if yes, continue to execute all the other actions. If not, cancel all and let user make the necessary changes.

Thank you for your help!

Classic 'Flatten PDF' question

$
0
0

So I have created a fairly complex fillable form in Acrobat Pro (10.1.8)... I have saved it for use by other users in Adobe Reader. (File>Save As>Reader Extended PDF>Enable Additional Features...)

 

The users can open file in Adobe Reader just fine, all formulas work, all values display correctly, life is grand.

 

Now all I want is for the user to save a 'flattened' version of the pdf to their machine, either to print or email at a later date. If the user saves the document from Reader all fields can still be edited on next use. If I use a "lock all field" button like this:

 

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

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

    if (f!=null && f.type!="button")

        f.readonly = true;

}

 

 

When I open the saved, field locked document, I lose all the formatting in my fields. (ie. no $ symbols, or commas in numbers, etc. )

 

And of course, there is no "print to pdf" option when you try and go that route... which of course, would make life too easy, wouldn't it?

 

So. Does anyone have a solution for what I can only imagine is a fairly common problem? I've searched high and low to no avail.

Using Adobe Air Auto Print and Download in Web application

$
0
0

HI All,

 

We need to integration Adobe Air in the MVC4 Asp.net Application and Javascript. We have a requirement to download to the PDF/DOCX file into user selected destination and print it automatically.

 

Browser Support : IE, Firefox,Chrome and safari

Integrated with Javascript/JQuesry

 

It would be great any one of you provide the inputs how to integrate adobe air in the web application using javascript to achieve above requirement.

 

Send me the email nhsubash@gmail.com

Searching an index repeatedly with different keywords and saving the results each time

$
0
0

Hello,
I have a set of over 2,000 PDF documents that I have created a library index for, using Adobe XI Pro.

I can search individual keywords just fine, and save those search results in .CSV.

But I have a list of keywords (rather large list, >1000 keywords) that I would like to search for one-by-one, reporting the results in CSV for each individual keyword search.

Basically what i'm looking for is to find a way to run this search/save-results action over and over, using a different keyword each time.

In the end I want to be able to have a repository where I can state that keyword XYZ appears in these PDF documents X-amount of times, and on the following pages in each document.

 

I found this answer, but I want to automate it to loop through a large list of keywords, saving the results each time: Re: Export Search Results of Multiple PDFs

 

Is there a way to script this?

I've looked at the highlight & replace script, trying to create a Macro in Excel to search the PDF docs (which is VERY slow),... none worked so far.

Any help would be greatly appreciated.

 

Thanks


Script to Insert a Custom Stamp/Annotation

$
0
0

Hello,

 

I have created a new custom stamp and need to add a script to "Batch Processing" to insert this stamp on 1,000 drawings.

 

The sample script available from the JavaScriptfor Acrobat API Reference inserts a stamp from the "Standard" Stamp File.

 

The standard stamp file is located in the following directory:

 

C:\Program Files\Adobe\Acrobat 8.0\Acrobat\plug_ins\Annotations\Stamps\ENU\Standard.pdf

 

The script needs to be modified to insert a stamp from a custom stamp menu called "Doc Control" and the custom stamp name is "Received".

 

The actual file which contains the custom stamp is located in the following directory:

 

C:\Documents and Settings\username\Application Data\Adobe\Acrobat\8.0\Stamps\Doc Control.pdf

 

 

Please find below the script which needs revising to include the new custom stamp.

 

 

var annot = this.addAnnot({

page: 0,

type: "Stamp",

name: "myStamp",  rect: [400, 400, 550, 500],

contents: "Received Stamp!",

AP: "NotApproved" }); This part of the script needs revising to refer to the new custom stamp not the stamp in the standard stamp file?

 

Any assistance will be greatly appreciated - Thank you.

 

 

 

 

 

 

 

Custom Format Script Help

$
0
0

I am not too familiar with scripting but am hoping someone can provide some guidance or at least somewhere online that will show me how to do this.  Here's what I'm trying to do:

 

I have a text field that I need users to enter a specific number format in.  They have three choices of formats but only one type must be entered.  If I go by the arbitrary format options, they would look like this: 99-9999999OO, 999-99-9999, or 999999-99999.  Now, is there a way to write a script so that it forces the user to enter the text/number in one of those three formats only?  I am able to set up an arbitrary mask and get one of them but I need to provide options to the user.

 

If there is some good reading online where I can figure this out myself, let me know.  Otherwise, any input would be greatly appreciated.

 

Thanks,

 

Dustin

Exporting FDF files using Acrobat Reader

$
0
0
I have developed some forms using Acrobat Pro v9 that have buttons to save the data as FDF files using the exportAsFDF function and another button that saves the file as a PDF file with the new data.

This has been done as we normally only save the FDF file to save space but need the PDF file with data if we are E-mailing it to a client.

Both buttons work fine when used in Acrobat v9 but when a Reader enabled file is used in Adobe Reader v9 only the PDF button works. The FDF button does nothing when it is clicked.

I assume that this is because the security settings on the exportAsFDF function prevent its use in Reader by default.

Is there any way of enabling this function via Acrobat and the form so that the a user having Adobe Reader only can save an FDF file after editing the data?

Using Excel VBA to save PDF file as a text (plain) file?

$
0
0

I'm using 8.0 Acrobat Pro.

 

Third party apps are not an option (I'm restricted from installing anything on my office PC).

 

I could simply save each PDF manually, but given the number of files this would not be practical.

 

The text it will output does not have to be pretty by any means (and I'm aware it won't be).

 

As long as I can get the PDF files in a text file format, there would be no further obstacles for me - because I would then be able to get Excel to gather-import all the data and consolidate-clean-organize everything accordingly at that point.

 

What's in these PDF files are simply names, numbers, and email addresses (basic office text type data stuff simple).

 

I wish to save them all as text files, and then use Excel to suck all the data from those newly created text files and consolidate-organize them accordingly.

 

The VBA module I've seen referrenced around the web is the following beneath; however, I am having no luck with it.

 

 

 

I keep getting the error message:

ActiveX component can't create object or  return reference to this object (Error 429)

 

I am running Microsoft Office 2010 | Excel (and using Adobe Acrobat Pro 8.0).

 

Any help is extremely appreciated.

 

Here is the VB code in Excel I'm having trouble with:  What this is supposed to do is simply find the specified PDF file and save it as a Plain Txt File.

 

 

Sub Convert_PDF_To_Text_File()

'---------------------------------

Dim AcroXApp As Object

Dim AcroXAVDoc As Object

Dim AcroXPDDoc As Object

 

Set AcroXApp = CreateObject("AcroExch.App")

AcroXApp.Hide

 

Set AcroXAVDoc = CreateObject("AcroExch.AVDoc")

AcroXAVDoc.Open strPDFPath, "Acrobat"

AcroXAVDoc.BringToFront

 

Set AcroXPDDoc = AcroXAVDoc.GetPDDoc

 

Dim jsObj As Object

Set jsObj = AcroXPDDoc.GetJSObject

 

jsObj.SaveAs strOutputFile, "com.adobe.acrobat.plain-text"

 

AcroXAVDoc.Close False

AcroXApp.Exit

'---------------------------------

End Sub

Display Filename in PDF File

$
0
0

Hi there, hoping for some help on what I think is quite a simple issue.

 

I want to create a blank single page PDF file which has a text field automatically and dynamically completed based on the file name of the pdf document. So for example if the file is named "My Sample File.pdf", the pdf file will display "My Sample File.pdf" and that is all. If I then rename the pdf file in Windows Explorer to "My Renamed File.pdf", when I next open the file it will display "My Renamed File.pdf".

 

I would then insert this one page pdf into an array of existing pdf files as their new page no1 to effectively be a title page for each created automatically based on their current filenames.

 

My research suggests this is possible using Javascript in a text field, or a form field (although I would prefer text field), however, as I have no experience of Javascript or its implementation within Acrobat, is proving impossible for me to do. The nearest I have got is a script which puts the filename as a watermark; unfortunately that script keeps overlaying the new filename over the old filename watermark, rather than updating it. For information that script was:-

 

this.addWatermarkFromText({

cText: this.documentFileName,

nTextAlign: app.constants.align.center,

nHorizAlign: app.constants.align.center,

nVertAlign: app.constants.align.bottom,

nFontSize: 12,

nVertValue: 12});

 

Ideally I would like the script to strip the file extension and if possible split the output onto two lines based on the filename portion which preceeds/follows a comma in the filename (which it would also strip). For example, if a had a file which was named "My Sample File, created on Monday.pdf", it would display as:-

 

My Sample File

created on Monday

 

If anyone has any ideas on this, it would be greatly appreciated.

 

Regards and thanks in advance,

Malcolm Dowers

cities javascript pulldown

$
0
0

Does anyone know where I can find javascript that has listed all the the US cities that I can use in a PDF pulldown window?

Validating an Acrobat forms text field

$
0
0

I'm using Acrobat X1 Pro and Live Cycle Designer ES4

 

I have a numeric text field to capture a blank or 14 digit number.

The display pattern is: null{}|num{zzzzzzzzzzzzzz}

The edit pattern is: null{}|num{zzzzzzzzzzzzzz}

The validation pattern is:

The data pattern id : null{}|num{zzzzzzzzzzzzzz}

 

I'm trying to make test that the user:

only enters numbers

enters nothing or a 14 digit number.

 

Display an error message and set focus back on the field for wrong entries.

 

This is the code:

topmostSubform.Page1.AU01::exit - (JavaScript, client)

// Test AU number format

var re = /^[0-9]{14}$/

//Allow blank space in field

if (event.value !="") {

  if (re.test(event.value) == false) {

    app.alert ({

       cTitle: "Incorrect AU Format",

       cMsg: "Enter a valid 14-digit AU number."

    });

     getField("AU01").setFocus);

  }

}    

 

I get the error message when I exit the field regardless of what is in the field. And the set focus does not seem to work.

 

I can program in VBA but find Javascript challenging. What good reference books can you recommend?

 

May thanks.

 

Brian Dunkin


Change from one color to another

$
0
0

I have an image PDF (just one image per page, no text). The image is black with a white background. I need to change the black areas to magenta. I've not been able to figure out how to do that with any of Acrobat's built in features. Does anyone know of a script that can do that?

Split/Extract pages by bookmarks

$
0
0

I have created a script which will successfully split the pdf at the first bookmark.

 

I need for the script to split all bookmarks from the pdf. 

 

I have modifed the script but the console reports the following error:

TypeError: bookmarkRoot.children[i] is undefined

 

Can someone please provide assistance to modify the script to split all bookmarks from the pdf?

 

Script to split the pdf at the first bookmark - this works!

 

if (this.bookmarkRoot.children!=null)
{
var bm = bookmarkRoot.children[0].execute();
var bmname = bookmarkRoot.children[0].name;
this.extractPages({nStart:bm, cPath: "/C/Temp/"+bmname+".pdf"});
}

 

Script to split all bookmarks in the pdf - this does not work!

 

if (this.bookmarkRoot.children!=null)
{
for (var i=0; i < this.bookmarkRoot.children.length; i++)

var bm = bookmarkRoot.children[i].execute();
var bmname = bookmarkRoot.children[i].name;
this.extractPages({nStart:bm, cPath: "/C/Temp/"+bmname+".pdf"});

}

 

Thank you!

Lock form & email as PDF Javascript

$
0
0

Hi Guys,

 

I am using Adobe Acrobat X and creating a Forms natively. We do not use LiveCycle.

 

So I have created a form with several fields, buttons a date picker - some of which I have found online.

 

The forms that I will be creating will be placed on the Intranet of the Organisation that I work for.

 

So what I need is for our users to fill out the form online. Press the Submit button. When they press submit the form must lock all the contents. We do not want to contents edited when it reaches its destination. The submit button will also call up the default email program, populate the TO: field with a specified email address and the Subject field with specified text.

 

The form must arrive at its destination in PDF format.

 

Been stuck on this one for a while. I used some simple html with the submit button for a while and that mostly worked except the part about locking the form.

 

So if someone can java me up a solution i would greatly appreciate it.

 

I have tried a few of the solutions a few solutions from the lifecycle partof the forum but apparently the java is different!

 

Many thanks,

Nick

Need Help Creating Custom Calculation Script Please

$
0
0

Untitled-1.jpg

Hello,

 

I am in desperate need of a custom script here if anyone knows how to do it. I essentially want the percentage field to automatically fill in based on the fraction, rounded to the nearest integer, show "0" if F2 is "0", and not display "NaN" before it's filled out. I also do not want the error message to pop up "The value entered does not match the format of the field [ P ]"

 

F1 and F2 will always be a whole number between 0-9, and P will always be a whole number between 0-100.

 

I've been using (F1/F2)*100 as a Simplified Field Notation, but it keeps showing decimals and displaying "NaN" when nothing has been entered in F1 and F2. Any gurus out there that could help me? I'd really appreciate it. Thanks

Custom Text Field in a Dymanic Stamp

$
0
0

Im creating a new dymanic custom stamp, but instead of the date/time, when inserted, I need to then manually enter text into the dymanic text field.

 

How do I change the script in the dymanic feild of the stamp to do that?

 

Thanks

BrianV

Acrobat 8.0 Pro

Win XP Pro

Viewing all 12130 articles
Browse latest View live