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

Insert or Stamp Filename

$
0
0

I have adobe acrobat 8. I want to insert or stamp the file name to the pdf. I have approximately 400 files to stamp with the individual file names so I would like to do it automatically. All help appreciated.


Program to fill out PDF Form

$
0
0

Hello,

 

I want to look at the feasibility of doing the following pragmatically:

 

1. A user emails in a ID number, which triggers a program to grab the ID number from the email and do a query against a database and return a name, address and a few other attributes.

 

2. These attributes then need to be put into a PDF version of a form in the correct place - again all done pragmatically.

 

3. At this point the form could either be saved or sent to a printer.

 

Again all this needs to be done with a program. Its early days yet, but what language would be good for this sort of thing, libraries would I need etc.

 

Could be done in either Windows or Linux.

 

Looking forward to suggestions.

 

Cheers

 

-Al

Acrobat Pro XI Java: Deleting Page is Very Slow

$
0
0

Hi Everyone,

 

Below is a set of code I got working in Acrobat XI to pull up a popup window that, when the user selects yes, is able to search for a hidden keyword on certain pages in the PDF and then delete the corresponding pages.  This works, but the problem is that it takes almost a minute to process.  I would love someone's input as to what might be slowing the process down.  I am very new to Java so any specific suggestions would be greatly appreciated!

 

Thank you in advance,

Christian

 

var cMsg = "Continuing with the current action will remove the CHES application and its data.  This operation may take a minute to complete.";

cMsg += "\n\nDo you want to continue?";

var nRtn = app.alert(cMsg,2,2,"Question Alert Box");

if(nRtn == 4)

{// A yes Response

  // Code for doing the thing you do on a yes

  console.println("The Response Was Yes");

for (var p=this.numPages-1; p>=0; p--) {

    for (var n=0; n<this.getPageNumWords(p); n++) {

       if (this.getPageNthWord(p, n) == "CHESDELETE") {

        this.deletePages(p);

        break;

}

}

}

}

 

else if(nRtn == 3)

{//No Response

console.println("The Response Was No");

}

 

else  

{ //Unknown Response

  console.println("The Response Was somthing other than Yes/No: " + nRtn);

}

How to replace Nth Number of word in a PDF document by JavaScript?

$
0
0


I want to delete the last 19 words of each page for a PDF document, they appear as header in the document (e.g. ETMF Copy of: 270.01 - 2013-01-30 | Active | 10-Dec-2015 10:07:35 PM), how can I do it by JavaScript in Acrobat 9?

 

I know "getPageNthWordQuads",  "this.addAnnot({type:"Redact"..." and "this.applyRedactions" can replace the text with white by applying redactions, but unfortunately there is useful text overlapping with the text I want to remove.

 

The test document can be downloaded by the link below, thanks a lot!

  

http://pan.baidu.com/s/1kU0xbyn

Extract Code: a4ip

  

 

  

 

  

 

 

importIcon for toolbutton - Operation failed error

$
0
0

hi:

I am trying to create a button in tool bar using importIcon and am getting operation failed error. Here's my code -

function helloWorld()

{

     //Say Hello World

     app.alert("Hello World");

}

 

var CreateButton = app.trustedFunction( function() {

app.beginPriv();

  // Create a document

   var myDoc = app.newDoc(1,1);

  var img = myDoc.importIcon("publishbutton", "/C/Development/tst.jpg", 0);

  var oIcon = util.iconStreamFromIcon(myDoc.getIcon("publishbutton"));

  

   app.addToolButton({

       cName: "helloWorldBtn", // A name for your button

    oIcon: oIcon,

       cExec: "helloWorld()", //Function to Call

       cTooltext: "Say Hello World" //The Help Text

});

   myDoc.closeDoc(true);

   app.endPriv();

  });

 

CreateButton();

 

 

I get this error in console

GeneralError: Operation failed.

App.addToolButton:22:Folder-Level:App:PublishButton.js

 

I myself created tst.jpg in that folder with simple text and saved as jpeg format from mspaint.

 

to my surprise, when I comment the line

oIcon: oIcon

 

it works well creating a default icon.

 

Please help.

Script to Batch Remove or Change Comment Identity (=Author)

$
0
0

Hi,

 

I have some PDF files from (supposedly) anonymous reviewers that have their (login) names showing up in the Acrobat comments.  In order to be really anonymous, each of the comment Author fields needs to be changed manually (to something like "Reviewer"), but there can be literally hundreds of comments per manuscript, so this gets pretty tedious.  So, I'm wondering if there is a way to create a menu item script that can be run on a document to either remove or change the comment Author name?  Any ideas on how to go about this with Acrobat scripting?

 

I know that there is a way for folks to change this before the start commenting, but most of our reviewers are not very computer adept, so asking them to run through the steps to do this may cause issues.  So a solution that can be run on my end would help immensely.

 

Anyway, I would appreciate any help folks can lend on such a script.

 

Cheers,

JWFetz

Acrobat X -- Reorder Pages by Bookmark Sort Order

$
0
0

Is there a way to programatically / automatically re-order the pages of a PDF by sorting them according to bookmark order? I have 56 pages and each one has exactly one bookmark, which is numerical.

 

I have a 56 page PDF that was made by scanning a "booklet." The original booklet was printed two logical pages to a single sheet of paper (left and right half of a landscape 8.5"x11" sheet), with two more logical pages on printed on the reverse side. All the sheets were saddle stitched (folded in half to make pages 5.5"x8" and stapled at the fold). After cropping out the right half pages to a new document, then cropping out the left half pages to a new document, then merging the two new documents, I have a new PDF whose true (original) pages are ordered 58, 56, 54... 6, 4, then 3, 5, 7... 55, 57. Each page is bookmarked with the original page numbers.

 

If I could simply instruct Acrobat to re-order the pages by the bookmarks that appear on each page (exactly one bookmark per page), then my new PDF would be in the correct order to match the original paper booklet. Is there a way to do this?

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.


ExportAsFDF is not working with Adobe Acrobat X Pro

$
0
0

Hi,

 

I am working on Acrobat Acrobat X pro to export FDF through javascript actions.

Manually exporting FDF file is working properly, but using the script its giving me below FDF file:

 

%FDF-1.2

%âãÏÓ

1 0 obj

<</FDF<</ID[<D112096744983A4F942778C9714C68BB><18355F3D06AAA94DA58E6A87990B91AA>]/UF(/D/Te st.pdf)/F(/D/Test.pdf)>>>>

endobj

trailer

<</Root 1 0 R>>

%%EOF

 

 

I have 18 annotations in this document and no annotations are getting extracted.

Following is the javascript that I am using which is expected to set the bAnnotations to true & extract all the annotations.

 

this.exportAsFDF(true, true, null, true);

 

Experts, Any advice? Appreciate any help.

Read CSV in acrobat javascript

$
0
0

Hi,

         I am new to acrobat javascript. I want  to get the data from the CSV file and do process in active pdf file(opened current document) .Please, any one of you help , by provinding code for this.

 

 

thanks in advance

Help adding an image to pdf with buttonImportIcon

$
0
0

Hi,hoping someone can help me with this as I am pulling my hair out.

 

I create a button using the addfield command as follows

 

var cFileName = "somepathhere/filename.pdf";

var oFld = this.addField("ButtImage", "buton", this.pageNum, [222,417,363,496]);

if(oFld != null)

{

     oFld.buttonPosition = position.iconOnly;

     oFld.borderStyle = border.s;

     oFld.textColor = color.black;

     oFld.lineWidth = 1;

}

 

try{

     MyImportIcon(this.getField("ButtImage"), cFileName);

} catch(e) {

     console.println("Error Importing Signature Image")

}

 

 

then I have a seperate js file MyImportIcon.js

var MyImportIcon = app.trustedFunction(function(oFld, cPath)

{

app.beginPriv();

if(cPath != null)

{

     oFld.buttonImportIcon(cPath, 0);

}

else

{

     oFld.buttonImportIcon();

{

app.endPriv();

});

 

When this code all runs I get no errors in the console, a button is created in the pdf but it is blank and no icon is set. 

 

I am running Acrobat X Standard.

 

Thanks in advance for your responses.

Can we send the pdf we are working on as input to web service? example please

$
0
0

Can we send the pdf we are working on as input to web service? example please...

 

Thanks.

PDF to TXT Conversion

$
0
0
I'm using Acrobat Standard 8.1.0.

I would like to run from Excel VBA a process to convert PDF files into TXT files. The same affect of opening the files in Acrobat and clicking on Save As and changing the filetype to .txt. I've looked through the online SDK and am rather familiar with VBA, etc. I get the following error no matter what syntax I use to try to save the file as anything other than a pdf file. Here's my code and the error:

Code:

Dim AcroXApp As Acrobat.AcroApp
Dim AcroXAVDoc As Acrobat.AcroAVDoc
Dim AcroXPDDoc As Acrobat.AcroPDDoc
Dim Filename As String

Filename = "R:\My Documents\ZBIR006A_8781830 - DRC000004311.pdf"

Set AcroXApp = CreateObject("AcroExch.App")
AcroXApp.Show

Set AcroXAVDoc = CreateObject("AcroExch.AVDoc")
AcroXAVDoc.Open Filename, "Acrobat"

Set AcroXPDDoc = AcroXAVDoc.GetPDDoc

Dim jsObj As Object
Set jsObj = AcroXPDDoc.GetJSObject

jsObj.SaveAs "R:\My Documents\pdfTest.txt", "com.adobe.Acrobat.plain-text"

AcroXAVDoc.Close False
AcroXApp.Hide
AcroXApp.Exit

Error:
On the jsObj.SaveAs line I get the following error:
"UnsupportedValueError: Value is unsupported. ===> Parameter cConvID.
Doc.saveAs:-1:

I've looked through all of the documentation online and cannot come up with a reason why I'm not able to do this. Please help!!

How can I make part of the Text as Bold in a Text field using Adobe Javascript for a Pdf document?

$
0
0

I want to get part of the below text Bold like: aProduct.getItemAt(aSelection,false) + "\n\nQuote\n\n You have Selected the <b>Second<\b> Option";

 

Output: You have Selected the Second Option

 

But I can't use <b>....not sure how to do this. Can you please help me with any solution for below.

 

(function () {

    // Do nothing if not committed
    if (event.willCommit) return;

    // Set up an array to hold the individual paragraphs of text
    var aProduct = this.getField("Motor_Combo_Box");
    var aSelection = aProduct.currentValueIndices;
     switch(aSelection)
    {
        case 0:
                this.getField("Motor_paragraph_text").value = aProduct.getItemAt(aSelection,false) + "\n\nQuote\n\n You have Selected the <b>First</b> Option"
                break; 

        case 1:
                this.getField("Motor_paragraph_text").value = aProduct.getItemAt(aSelection,false) + "\n\nQuote\n\n You have Selected the <b>Second</b> Option";
                break;

        case 2:
               this.getField("Motor_paragraph_text").value = aProduct.getItemAt(aSelection,false) + "\n\nQuote\n\n You have Selected the <b>Third</b> Option";
                break;
    }

})();

How can I print multiple "class completion certificates" with a list of students?

$
0
0

I don't need step-by-step instructions from the community -- just pointed to the appropriate documentation. I want to learn and do this on my own. Just having trouble finding exactly what I need.

 

I'm thinking this starts with either:

  • importing a text file, or
  • typing/pasting the list into a PDF form

Then, user clicks a button that does the following:

  • adds a page for each student name
  • inserts name into a form field (with formatting like typeface and alignment)

 


My main question at this point is, should the script(s) add new, blank pages with a layer containing the certificate "background" or use a stamp that places the certificate image? Or, perhaps the page after the form (or "import names" button) is the certificate with dynamic text field and the script simply duplicates that page for each student, inserting the name.

 

The remaining task is to add a date but that seems pretty easy--I haven't decided whether that will by dynamic/automatic or if the user will need to type it into another field (in the initial form).


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?

Insert images into interactive PDF

$
0
0

Hello All,

 

I am trying to create an Interactive PDF (forms) for users that should insert:

 

- Name

- Surname

- Profile picture

 

These information are then used to generate a badge and print it.

So far I was able to figure out the textfields and the button that runs the print() function within Javascript.

I am looking for a flexible solution that allows user to choose a profile picture on their local machines through a file dialog window (or something similar).

 

Does anybody know how can I do it?

 

 

Thanks

app.addToolButton in folder level script creates a floating Add-on Tool bar in Acrobat Pro DC

$
0
0

I've created a folder level script to create few buttons and add them to a custom toolbar. This all worked fine in Acrobat Pro XI. However after migrating to Acrobat Pro DC, I notice a floating 'Add-On Tool bar' with all the buttons created in the folder level script.

 

This tool bar appears every time acrobat is launched and the user needs to close it. We don't need it as users access the buttons configured on a custom tool bar(using the 'Create Custom Tool').

 

Is there a way to prevent/hide this floating tool bar?

 

Thanks in advance

 

Folder level script content:

   app.addToolButton({

           cName: "TestButton",

           cExec: "app.alert('Hello World!')",

           cLabel: "Test Button Label",

           cTooltext: "Test Button Tool Tip"

   });

  

Screenshot

floating add-on bar.jpg

How to generate multi-line bulleted list with javascript

$
0
0

I am creating a resume form in which the job descriptions will be multi-lines. I need it to be set up such as the following:

 

1996 – 2013      COMPANY NAME  |  CITY, STATE

                         • Job description one which will may be longer than this line and

                            need to wrap to here.

                         • Job description two which may do the same thing as the previous line and

                           need to wrap to here.

                         • And so on with the descriptions.

 

 

*How can you indent, or tabstop, to a certain point?

How to format a text field for credit card numbers?

$
0
0

OK, I found this conversation, http://forums.adobe.com/message/3598185, that gave some useful insight, and I adapted the code presented in it to make sure the user types in a 16-digit number, and it tells them to do it right if they don't.

 

Here's my problem:

With the code as given, I can either get a single string of 16 digits (i.e.: 1234567890123456), or, I have to make the user manually type in the spaces to get the usual CC format (1234 5678 9012 3456).

 

What I'm hoping for is some code that will let me allow the user to simply type in 16 uniterrupted digits, but that will then display that entry in the expected format. (So, user types 1234567890123456, but the field once they tab or click out of it will show 1234 5678 9012 3456)

 

Here's the code I have thus far (like I said, copied alomst verbatim from the link above):

In the Format tab, under Custom Format Script:

function checkFormat(s) {

 

    if (!s) return true;

 

    var aRE = [

        /^\d{16}$/

    ];

 

    return AFExactMatch(aRE, s);

 

}

 

In the Format tab, under Custom Keystroke Script:

(function () {

 

     if (event.willCommit) {

 

         var isValid = checkFormat(event.value);

 

         if (!isValid) {

            app.alert("Please enter a valid 16 digit credit card number with no spaces or dashes.", 1);

            event.rc = false;

        }

    }

 

})();

 

I'm sorry it's so simplistic. Though I've rooted around in other programming languages (HTML, C++), so I'm not a complete noob, I don't know anything about Java at all...

Thanks in advance!

Viewing all 12130 articles
Browse latest View live


Latest Images

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