dcsimg
www.webdeveloper.com
Results 1 to 8 of 8

Thread: Print with ActiveXObject

  1. #1
    Join Date
    Feb 2017
    Posts
    18

    Print with ActiveXObject

    I have a function that currently prints a document with a header and footer. However, the function does not display the Print dialog. I want to create a similar function that adds the header and footer, but displays the Print dialog so they can print it to a PDF file. Is it possible to use the ActiveXObject to display the Print dialog?
    Here is the code I currently have that prints automatically:
    Code:
    printWord = function() {
    	var str;
    	var objWord;
    	var url="C:\\Users\\ccote1\\Desktop\\Baseline Diffs\\comparison794TableTest2.html";
    
    	objWord = new ActiveXObject("Word.Application");
    	objWord.Documents.Open(url);
    
    	ActiveDocument = objWord.Documents(1);
    
    	ActiveDocument.Tables(1).Delete();
    
    	ActiveDocument.Sections(1).Headers(1).Range.Text = "For Official Use Only (FOUO)";
    	ActiveDocument.Sections(1).Headers(1).Range.ParagraphFormat.Alignment = 1;		// 1 = center
    	ActiveDocument.Sections(1).Headers(1).Range.Font.Name = "Arial";
    	ActiveDocument.Sections(1).Headers(1).Range.Font.Size = 12;
    	ActiveDocument.Sections(1).Headers(1).Range.Font.Bold = true;
    
    	ActiveDocument.Sections(1).Footers(1).Range.Text = "For Official Use Only (FOUO)";
    	ActiveDocument.Sections(1).Footers(1).Range.ParagraphFormat.Alignment = 1;		// 1 = Center
    	ActiveDocument.Sections(1).Footers(1).Range.Font.Name = "Arial";
    	ActiveDocument.Sections(1).Footers(1).Range.Font.Size = 12;
    	ActiveDocument.Sections(1).Footers(1).Range.Font.Bold = true;
    
    	ActiveDocument.Sections(1).PageSetup.PaperSize = 1;			//1 = 11x17, 2 = Letter (8.5x11)
    	ActiveDocument.Sections(1).PageSetup.Orientation = 1;		//0 = Portrait, 1 = Landscape
    	ActiveDocument.Sections(1).PageSetup.TopMargin = 36;
    	objWord.Visible = false;
    	objWord.PrintOut();
    	alert("Your document has printed successfully.");
    	ActiveDocument.Close(0);
    	objWord.Quit(0);
    }
    I would appreciate any help I can get.

    Chris

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,429
    Mostly you right click the object you want to print and select print option from the dialogue menu.

    ActiveX is only supported by one type of browser.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Dec 2012
    Posts
    1,555
    Why not use the standard printing function?:
    https://developer.mozilla.org/en-US/...I/Window/print
    It will shurely open the dialog.

  4. #4
    Join Date
    Feb 2017
    Posts
    18
    I know that ActiveX is only supported by IE, but that is not an issue because my company doesn't allow any other browsers anyway. So if there is any way to open the print dialog using the Word.Application ActivexObject, that would be my best solution.

    Thanks,
    Chris

  5. #5
    Join Date
    Feb 2017
    Posts
    18
    Quote Originally Posted by Sempervivum View Post
    Why not use the standard printing function?:
    https://developer.mozilla.org/en-US/...I/Window/print
    It will shurely open the dialog.
    I would use the standard print function, except that I'm using the Word ActiveXObject to add a header and footer to the document before I print and I'm only printing a portion of the page that's within a particular div.

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,429
    Daft question, then why is the document not printed directly?

    If a word document is properly set up, you can lock it from being modified, you can have information inserted automatically like headers and footers... You don't need aweb browser to print a document that needs headers and footers inserted, all it takes is for some tech in the company to insert the macrosand data to tell the document where to get the data from that needs inserting.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  7. #7
    Join Date
    Feb 2017
    Posts
    18
    The reason is that the "document" is originally displayed as a "simple" web page with a table and a button above to save the HTML to PDF. So, rather than making the user reopen the web page in Word on their own, I'd like to have the HTML button automatically add the header/footer using the Word ActiveX object then have the Print dialog for that ActiveX object appear in order to allow the user to print either to their printer or to PDF. Anything that can reduce the number of mouse clicks the user has to use is best.

  8. #8
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,429
    IMHO you are better off using a PDF file that has input fields if inputs are needed. You can create PDF's directly from a PHP program on the server, there is no issue with compatibility or browser issues because the PDF original that you would have wouldn't change, only the end users copy would change and you can also POST from within the PDF to a server the data that has been entered in to the document.

    Printing the PDF would be a simple print job as the format scales to the print medium size.

    So you will be cutting out all the web page issues, printing options and other related problems, biggest being the required number of clicks would be click to download it, click to open it, click to print it after whatever needs doing has been done to it... by having the client download a PDF from the site, use it to fill in the required information, save, print, post it...

    So I say look at using PHP with the web to produce your template documents as PDF files, the different security features you can have with PDF means that you can have editable parts, web forms that post over the internet, elements that can't be edited and settings to allow elements to be printable or not and because a PDF document has the software reader, it has access to all the system resources like printers.

    You can buy software to speed up PDF development that allows via graphical input, laying out of a PDF document, its contents, etc. I use one from time to time by a company called Serif, does the job, nothing special but it showed me some special features of PDF that I experimented with.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

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