Skip to main content
Participant
November 18, 2008
Question

open file using Javascript

  • November 18, 2008
  • 7 replies
  • 35685 views
I am trying to open a file using a javascript dropdown menu. I know acrobat allows users to open a single file using the standard features, but I have about 30 different files that need to be referenced. the general idea is currently;

window.open("C:\Documents and Settings\Desktop\" + event.value + ".pdf");

Besides the fact it doesn't work at all, I'm getting an error message "unterminated string literal". This is due to the \ right before the end of the directory string. but I cannot think of a way to finish the directory string without using this methoid. (i've also tried assigning the '\' to it's own variable but that is throwing the same error. if you have any idea, please let me know. I may have fixed this issue, i'm using \\ instead of \ after Desktop, but the file still will not open. I've also tried using app.launchURL to no avail. please help me with another open command, please.
    This topic has been closed for replies.

    7 replies

    Participant
    November 18, 2008
    actually... i figured it out. I was using .txt files as a basis for the testing (as the 30 someodd PDF files have not yet been created. Turns out, you cannot open a .txt file, but CAN open a PDF. Thanks very much for all the help!! Saved me hours of useless struggle. (don't ask how I came about to create a random pdf and check that, just a random moment I had)
    Participant
    November 18, 2008
    still no luck, i copied the line you added, and it doesn't even think about it now (when i had what i listed there was a bit of a delay then nothing happened)

    I've checked the file extension and names MANY times already (because i often make stupid mistakes like that) and all is correct, even case sensitive correct. I am using Acrobat 8, not sure if that makes app.openDoc useless or not. please let me know. Thank you
    Inspiring
    November 18, 2008
    I believe the Acrobat JavaScript API Reference has examples. like:

    var otherDoc = app.openDoc("/c/temp/myDoc.pdf");
    otherDoc.getField("name").value="Enter your name here: "
    otherDoc.getField("name").setFocus();
    this.closeDoc();

    Note there is no ":" and the "/" delimiter is used.

    So you would create your statement like:

    app.openDoc("/C/Documents and Settings/Admin/Desktop/" + event.value + ".pdf");
    Participant
    August 3, 2009

    var otherDoc = app.openDoc("/c/temp/myDoc.pdf");
    otherDoc.getField("name").value="Enter your name here: "
    otherDoc.getField("name").setFocus();
    this.closeDoc();

    this code doesnt work wen i hav changed it to suit my needs.(interms of the document name)

    placed it in a catch block it returned otherDoc doesnt has no properties.

    could you assist me please really need the help with this.

    try67
    Community Expert
    Community Expert
    August 4, 2009

    Do you have a file with that name in that location? Is it being opened?

    try67
    Community Expert
    Community Expert
    November 18, 2008
    Replace all the back slashes with forward slashes, drop the colon and the extra slash at the end, like so:

    app.openDoc("/C/Documents and Settings/Admin/Desktop/" + event.value + ".pdf");
    Participant
    November 18, 2008
    hi, i'm using the app.openDoc methoid and don't seem to be getting anywhere. i've read a few forums that say that only works with Acrobat 7. I'm on Acrobat 8. I'll keep researching, but if someone has another answer for me I would appreciate it.

    verbatum line;

    app.openDoc("\C:\Documents and Settings\Admin\Desktop\\" + event.value + ".pdf");
    Inspiring
    November 18, 2008
    You need to use the app.openDoc method, and specify the path correctly, something like:

    "/c/Documents and Settings/Desktop/"

    The Acrobat JavaScript reference has more information.

    George
    Bernd Alheit
    Community Expert
    Community Expert
    November 18, 2008
    You can use the openDoc method. Details in the Acrobat JavaScript Reference.