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

Printing a PDF via Acrobat Javascript

$
0
0

Hi -

 

I have a need to print a PDF programmatically, via Javascript.  The PDF is embedded in a Web page.  I use postMessage to communicate with the PDF.

 

I've created a simple HTML page with an embedded PDF, and a Javascript link to call my "Print" function. Here's a code snippet:

 

<body>

         <a href="javascript:doPrint();">Print</a>

         <object id="PDFObj" data="testPDF.pdf" type="application/pdf" width="400" height="400" />     
</body>

 

In the HTML document's HEAD, I've added the following Javascript which posts the message to the PDF:

 

<script language="JavaScript">
        function doPrint() {
            pdfObject = document.getElementById("PDFObj");
            alert("Hello from Javascript...");
            pdfObject.postMessage(["Print", "Print"]);
       }
</script>

 

Finally, I've added an Acrobat Javascript function in the PDF document to listen for the postMessage event:

 

function myOnMessage(aMessage)
{

    app.alert("Hello from the PDF");

       // print routines here

   
}

var msgHandlerObject = new Object();
msgHandlerObject.onMessage = myOnMessage;
msgHandlerObject.onError = myOnError;
msgHandlerObject.onDisclose = myOnDisclose;

function myOnDisclose(cURL,cDocumentURL)
{
return true;
}

function myOnError(error, aMessage)
{
app.alert(error);
}

this.hostContainer.messageHandler = msgHandlerObject;

 

Here's my problem: when I test this code and click the HREF Javascript link, I see "Hello from Javascript..." and "Hello from the PDF," so I know the postMessage event is working.  However, I've tried every print command I know in the myOnMessage function, and nothing seems to work:

 

app.execMenuItem("Print"); // doesn't seem to work

this.print(); // doesn't seem to work, even when I pass in all the params, etc

 

I've also tried getting print params and passing those in, nothing seems to work.  Am I missing something?  Environement is Acrobat 9 Pro, browser's tested include Chrome 2.0, IE6.  I've attached two files, the HTML bit and the PDF I'm trying to print.  Any help is greatly appreciated!


If Else Statement for PDF Form

$
0
0

I am unfamilar with JavaScript and need to create a calculation for a PDF form. The form is used to determine profit. There is a radio button called payroll with two values, "internal" and "external". One calculation to determine costs will need to say: if payroll equals "internal" then 1.02 else .98. This number will then insert in the costs field. The other calculation to determine markup will need to say: if payroll equals "internal" then 1.2 else 1.4. Thanks in advance for the assistance.

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!

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

Acrobat Form comes up "Operation is not permitted"

$
0
0

I made a simple form to register for an event and put it up on a clients website.

The form can be filled out but when the end user tries to submit the form on the website, Acrobat reader comes back with "this operation is not permitted".

When I submit from the original form, (not on the website) it works just fine.

The submit button is configured as "mailto:email@domain.com" without the quotation marks, of course.

 

I'm running Acrobat Pro 9 from CS5

Using Javascript to reset a form on document load

$
0
0

I am trying to reset all field vaules on a acrobat form to the default values, when the form is initially loaded.  I am trying to use the resetForm() method in a document level script, but not having any luck.

 

I have been able to reset fields after user inputs such as a button that resets the form, or a script the will reset a form prior to importing field data... but I need to ensure all data is removed from the form when the form first loads

 

Any ideas?

Batch creation of bookmarks?

$
0
0

Moved from the Acrobat Macintosh forum (Batch creation of bookmarks?)

 


I would like to add 107 bookmarks to a 250-page PDF in an automated  fashion. I have a list of the bookmarks titles, pages, and their  hiearchy level.

 

What's my best bet? [This is with Acrobat 9 on a Mac, but I can use any platform...]

 

Obviously I don't want to create them by  hand with New Bookmark in Acrobat Pro.

My document is not tagged,  and I don't see an easy way to mass create tags (is there one?).

It  appears that the Acrobat Pro scripting DOM does support creating  bookmarks with the Bookmark createChild()method, but it's looking a little  dicey to me how to use that straightforwardly, so if it's easy to  provide a few pointers, I would be greatful.

 

I'd like to avoid buying a  plugin (or using one on a free trial basis, since I don't really intend  to buy one).

I initially planned on using pdftk's update_info functionality, but it turns out that while pdftk's dump_data subcommand dumps bookmark info, it's corresponding update command  doesn't handle bookmarks at all.

I considered writing some Java  code with iText and/or PDFBox, but I didn't see any good examples of  exactly how to create bookmarks that point to pages, and it seemed like  it might be a big pain to figure out.

 

I'm comfortable scripting other  Adobe products in JavaScript, but I've never dealt with Acrobat.

 

Hopefully  that sets the stage. Any advice is appreciated!

 

Thanks!

Acrobat Forms - javascript to hide/unhide text box if any one of a number of radio buttons is enable

$
0
0
I have a form which I am designing in Acrobat 9 which has a section where there are three questions, each with a pair of radio buttons - one for 'yes' and one for 'no'. They are in the style of a check box (with a tick). I need some help to write some code which will unhide a single field (or multiple fields if I need to use something similar at a later date) if any one of the 'yes' radio buttons is checked. So if all three radio buttons were checked, the field would be hidden but if you then changed your mind and clicked a yes button, the field would be visible.

I am new to this so any help would be greatly appreciated. Many thanks in advance! I hope that i have explained this clearly btw.

How can I export adobe form data to FDF?

$
0
0

Hi.

 

I am new to programming for acrobat and I have a very simple task.

 

I already have an FDF that contains values for various form fields.

I can automatically populate the form fields just by pulling up the FDF for the associated PDF in Adobe Reader - no problem.

 

When the user saves the data, I need to export it to FDF - that is the problem.

This is not a server app - it is a desktop app.

 

Can someone please point me in the right direction or provide some sample code?

 

Thanks!

How to Extract Text coordinates from PDF

$
0
0
Hi,

can anyone tell me how to get coordinates in pdf document using VB or .NET, suppose if some text is written in pdf document then how can i get coordinates of that text. Its very Urgent.

Thanks in Advance.

How can I add javascript text fields to Acrobat pages from Applescript please?

$
0
0

I have a real need to add text fields to Acrobat document pages from Applescript. I can't access the Headers and Footers from Applescript in Acrobat XI. I can set watermarks using the following script, but cannot for the life of me work out how to add text fields. Any advice please?

 

Regards

 

setTempAttachmentNameto "(20140717121212Z)"

setPreserveFileNameto "This is a test"

setbypasstofalse

 

tellapplication "Adobe Acrobat Pro"

  activate

  setCountOfPagestocountofpages

  repeatwithPageCounterfrom 1 toCountOfPages

  tellapplication "System Events" totellprocess "AdobeAcrobat"

  try

  clickmenu item "Page..." ofmenu 1 ofmenu item "Go To" ofmenu 1 ofmenu bar item "View" ofmenu bar 1

  tellcurrent applicationtodelay 0.1

  keystrokePageCounterastext

  tellcurrent applicationtodelay 0.1

  keystrokereturn

  ifnotbypassthen

  myADDHeaderFooter(TempAttachmentName, PreserveFileName& " " & CountOfPages, PageCounter)

  endif

  endtry

  endtell

  endrepeat

endtell

 

onADDHeaderFooter(The_String1, The_String2, currentPage)

  tellapplication "Adobe Acrobat Pro"

  activate

  setmyDocumenttodocument 1

  tellmyDocument

  tellpagecurrentPage

  setcboxtocrop box

  setitem 2 ofcboxto (item 2 ofcbox) + 44

  setitem 4 ofcboxto (item 4 ofcbox) - 44

  setmedia boxtocbox

  setcrop boxtocbox

  settheResult1tomyAdd_WaterMarkText(The_String1, "IDAutomationHC39M", 12, 1, 1, 1, 0, 3, 10, 3, 0)

  do scripttheResult1

  settheResult2tomyAdd_WaterMarkText(The_String2, "Times", 16, 1, 1, 1, 0, 4, 10, -6, 0)

  do scripttheResult2

  endtell

  endtell

  endtell

endADDHeaderFooter

 

onAdd_WaterMarkText(cText, cFont, nFontSize, nS, nE, nTA, nHA, nVA, nHV, nVV, nR)

  setParamsto "cText: '" & cText& "'," & return

  setParamstoParams& "cFont: '" & cFont& "'," & return

  setParamstoParams& "nFontSize: '" & nFontSize& "'," & return

  ifclassofnSisintegerthensetParamstoParams& "nStart: " & (nS - 1) & "," & return

  ifclassofnEisintegerthensetParamstoParams& "nEnd: " & (nE - 1) & "," & return

  -- 0 = left, 1 = centre, 2 = right

  ifclassofnHAisintegerthensetParamstoParams& "nHorizAlign: " & nHA& "," & return

  -- 3 = top, 4 = bottom

  ifclassofnVAisintegerthensetParamstoParams& "nVertAlign: " & nVA& "," & return

  -- offset in points

  ifclassofnHVisintegerthensetParamstoParams& "nHorizValue: " & nHV& "," & return

  -- offset in points

  ifclassofnVVisintegerthensetParamstoParams& "nVertValue: " & nVV& "," & return

  ifclassofnRisintegerthensetParamstoParams& "nRotation: " & nR& "," & return

  setjavascriptto "this.addWatermarkFromText({" & Params& "});"

  returnjavascript

endAdd_WaterMarkText

Link to an external .js from PDF?

$
0
0

Using Acrobat 9 Pro, I have a PDF document that I want to link to an external .js file (for SCORM and LMS purposes).  I have imported a multimedia object (swf) into the PDF and it needs to call several Javascript functions.  Instead of copy/pasting each function of Javascript code into each PDF (menu path: Advanced > Document Processing > Document Javascripts), is it possible to write a line of code that links to an external .js file?

 

In HTML, it would be someting like <HEAD><SCRIPT type="text/javascript" language="Javascript" SRC="pdf.js"></SCRIPT> </HEAD>.

 

Possible?

Acrobat Pro: possible to pull user information from active directory?

$
0
0
Hi!

I just started designing Forms with Acrobat Pro 8 and Life Cycle Designer.
I was wondering, if you can pull certain information from an active directory.
Based on a users windows login i'd like to display certain information in the document/form like the user's e-mail adress or phone number.
Is this possible?

Andreas

Fill a pdf form with data using Java code

$
0
0

Hi,

 

Modern formats of Acrobat ".pdf" files allows to define form fields.

 

I have a datasource, let's say in a database.

I want to fill my ".pdf" with my database-stored data automatically, and want to write Java code for that.

 

1. What is the best way to achieve this ?

 

2. Is it necessary to install Acrobat Distiller server and if so what web services should I invoke ? Where is the doc ?

 

3. Are there efficient Java libraries to do so ?

 

Thank you for helping... As ever, this is kind of an emergency case

 

Have a good day.

 

Phil

if else statement with Radio Button

$
0
0

I'm attempting to make a PDF form for clients to order event services. I have a field that I want to populate with a number based on their upgrade choices that are set as radio buttons. If they choose option 1 or 2, the upgrade price is X. If they choose option 3 or 4, the upgrade price is Y. I want the text field to display either X or Y based on their choice. Or just 0 if they choose not to upgrade.

 

JavaScript is pretty far out of my knowledge base but I'm attempting to figure this out anyway. Any help? What I have below (and everything else I've tried) is not working.

 

if (btn1.checked){

event.value = 162;

} else if (btn2.checked) {

event.value = 182;

} else if (btn3.checked) {

event.value = 162;

} else if (btn4.checked) {

event.value = 182;

}


show/hide fields when selecting an option from a drop-down menu.

$
0
0

Hello Gurus!

 

I have a question about creating a Java Script withing Acrobat pro.  This is what i would like to do: I created a drop-down menu with several selection entries.  Upon the customer making one of the selection entries, i would like for the correct fields that i created to become visible and all other fields to hide.  Is this even possible to do?  The reasoning behind this is because we have a form that customers have to generate in order to request access to certain financial accounts; we have over 20 different types of accounts and for each instance the customer has to fill out the same form.  By creating a drop down menu, i can use the same form by just changing the drop-down selection and clicking on the designated fields for that selection.  At this time i have over 20 different forms that poing to 20 different account requests and i would hate to send the form 20 different times to one person.  The reason i can not add all fields desired for all accounts is due to the fact that the form would be filled with hundreds of checkmarks and instructions thus making the process too tideous for the customer.  Hope you guys can help out.

 

~Vader

Dependent dropdown lists in Acrobat

$
0
0

Hi,

 

I am a first time poster and was looking for help with some scripting in a PDF form I have created.

 

I am basically looking to have a second dropdown list dependant on the value of the first but I'm not having any success.

 

I have tried the following as a calculation and as a MouseUp Javascript action but to no avail.

 

Basically, I'm looking for the following: If a user selects a School/Unit called Registry in dropdown 1, it will populate with 4 or 5 locations in dropdown 2. I need to do this for about 20 units. I think I'll be ok once I get one unit working but I can't get to that stage

 


// clear the dropdown displayed value and items
this.Value = null;
this.clearItems();


// repopulate the items based on the checkboxes
if(this.getField("School/Unit").Value == "Registry")
{
     this.addItem("Location 1");     this.addItem("Location 2");     this.addItem("Location 3");     this.addItem("Location 4");     this.addItem("Location 5");

}

Can anybody help me please?

 

Many thanks

Scott

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

Javascript/ Batch Processing - Query (Please assist/advice)

$
0
0

Hi

 

Where can I find on the internet a JavaScript that will do the following for BATCH PROCESSING:

 

 

-Combine single PDF files

-Crop the pages

-Check the sequence of the pages that it goes from 1,2,3 and so on

-ad metadata to the PDF

-set view

-add bookmarks based on the content page's major headings (e.g. Regulars)

-Making single PDF files over 1.5 MB smaller

-Fix white lines

-Make the final file as a PDF that is compatible with Acrobat 5 or later

 

Thanks

 

 

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

Viewing all 12130 articles
Browse latest View live


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