www.webdeveloper.com
Results 1 to 11 of 11

Thread: How can I add picture to word document using JavaScript?

Hybrid View

  1. #1
    Join Date
    Nov 2013
    Posts
    7

    How can I add picture to word document using JavaScript?

    Hi,
    I have a problem with insert picture to word document with JavaScript. This is my code:

    var MyWordApplication = new ActiveXObject("Word.Application");
    var offerdoc = MyWordApplication.Documents.Add();

    MyWordApplication.Selection.InlineShapes.AddPicture("E:\logo.jpg");



    I've tried a lot of combination, and it doesn't works correct.
    IE show error, that is wrong path to file.

    Could somebody help me with this problem, and show me, where is my mistake?

    Thanks.

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,199
    What version of Word are you using?

    Where are you using the script?
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    Nov 2013
    Posts
    7
    I'm using Word 2007.

    I'm using this script in Internet Explorer.
    Function is calling by button.
    I see in processes, that Word is open, but not display on the screen.
    IE show, that wrong path to file is.

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,199
    Would turning on picture content control for that image help? You have to have the developer tools switched on to do that. I know you can specify external images, generally Word like images to be embedded in the document. TBH I am not sue that you will be able to alter a document externally with JavaScript but you might be able to have a URL to the resource and have the script like PHP determine the resource to deliver.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  5. #5
    Join Date
    Nov 2013
    Posts
    7
    I don't want use PHP for that. This web application must be work locally without any complications.
    I don't understand why it doesn't works, if function for this exist. I saw a lot of examples in VB script (I didn't test it). But for javascript I can open document, write text, format text. Only with picture i have problem with correct path. On microsoft page, I found, that this function for javascript have the same structure, like for C#, VBS. And path to the picture was from local disk.
    I think here should be also possible. Do You have any idea or advice, what can I check more?

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,199
    also... You may have to try E:\\logo.jpg because the \ may be denoting \E as an escaped pair of characters
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  7. #7
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,199
    Ok, have you tried prefixing with file:// so you then have file://E:\logo.jpg
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  8. #8
    Join Date
    Nov 2013
    Location
    London, United Kingdom
    Posts
    15
    With the escaped backslash the code works well for me in the WSH environment.

  9. #9
    Join Date
    Nov 2013
    Posts
    7
    Thanks a lot. It works now
    I used this way: E:\\logo.jpg

    Problem was solved. Thank You \\.\

  10. #10
    Join Date
    Nov 2013
    Posts
    7
    Hi,
    I would like to continue this topic with other questions related creating word document using javascript.
    Few questions:
    1. How can I change margins size in the word document using JS?
    2. How can I make text alignemnt with JS?
    3. How can I table create using JS?

    Did somebody do these operations, or have any information or tutorials about creating word document by Javascript?

    Thanks.

  11. #11
    Join Date
    Jun 2013
    Posts
    37
    I program my document image reading and processing library using visual basic but not javascript or asp.net controls. While, I also can share my codes on Word image adding, which allows for adding and inserting image into Word page programmatically without having any dependency on Microsoft Office tools.

    Public Sub AddImageToPage(page As DOCXPage, img As REImage, x As Single, y As Single, compression As WordCompression)
    page.AddImage(img, x, y, compression)
    End Sub

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles