Results 1 to 8 of 8

Thread: Print with ActiveXObject

  1. #1
    Join Date
    Feb 2017

    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:
    printWord = function() {
    	var str;
    	var objWord;
    	var url="C:\\Users\\ccote1\\Desktop\\Baseline Diffs\\comparison794TableTest2.html";
    	objWord = new ActiveXObject("Word.Application");
    	ActiveDocument = objWord.Documents(1);
    	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;
    	alert("Your document has printed successfully.");
    I would appreciate any help I can get.


  2. #2
    Join Date
    Mar 2007
    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
    Why not use the standard printing function?:
    It will shurely open the dialog.

  4. #4
    Join Date
    Feb 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.


  5. #5
    Join Date
    Feb 2017
    Quote Originally Posted by Sempervivum View Post
    Why not use the standard printing function?:
    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
    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
    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
    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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12270 seconds
  • Memory Usage 2,929KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (8)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates