/    Sign up×
Community /Pin to ProfileBookmark

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 = 11×17, 2 = Letter (8.5×11)
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);
}
[/CODE]

I would appreciate any help I can get.

Chris

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@rootApr 25.2017 — 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.
Copy linkTweet thisAlerts:
@SempervivumApr 26.2017 — Why not use the standard printing function?:

https://developer.mozilla.org/en-US/docs/Web/API/Window/print

It will shurely open the dialog.
Copy linkTweet thisAlerts:
@ccote1authorApr 26.2017 — 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
Copy linkTweet thisAlerts:
@ccote1authorApr 26.2017 — Why not use the standard printing function?:

https://developer.mozilla.org/en-US/docs/Web/API/Window/print

It will shurely open the dialog.[/QUOTE]


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.
Copy linkTweet thisAlerts:
@rootApr 27.2017 — 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.
Copy linkTweet thisAlerts:
@ccote1authorJun 29.2017 — 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.
Copy linkTweet thisAlerts:
@rootJun 29.2017 — 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.
×

Success!

Help @ccote1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...