C # print word PDF printout Method

Source: Internet
Author: User

 

// Path of the file to be printed
Object Wordfile = lstdoc. selectedvalue. tostring (); // @ "C: \ test.doc ";
Object Omissing = missing. value;

// Boolean value of the custom object type
Object Otrue = True ;
Object Ofalse = False ;
Object Copies = nudcopies. value; // Print copies
Object Wdprintfrom = txtpage1.text; // Start page number of the print
Object Wdprintto = txtpage2.text; // Printed end page number

Object Donotsavechanges = Microsoft. Office. InterOP. Word. wdsaveoptions. wddonotsavechanges;

// define word application
Microsoft. office. interOP. word. application appword = New Microsoft. office. interOP. word. application ();

// word Program invisible
appword. visible = false ;
// no warning box is displayed
appword. displayalerts = Microsoft. office. interOP. word. wdalertlevel. wdalertsnone;

//First save the default printer
StringDefaultprinter = appword. activeprinter;

// Open the file to be printed
Microsoft. Office. InterOP. Word. Document Doc = appword. Documents. Open (
Ref Wordfile,
Ref Omissing,
Ref Otrue,
Ref Ofalse,
Ref Omissing, Ref Omissing,Ref Omissing, Ref Omissing, Ref Omissing, Ref Omissing, Ref Omissing, Ref Omissing,
Ref Omissing, Ref Omissing, Ref Omissing, Ref Omissing );

//Set the specified printer
Appword. activeprinter = cboinstalledprinters. selectedtext;//"\\\\ 10.10.96.236 \ HP Deskjet 6500 series ";

// Print
Doc. printout (
Ref Otrue, // Background: True, indicating background Printing
Ref Ofalse,
Ref Omissing, // Range page range
Ref Omissing,
Ref Wdprintfrom, // Start page number when range is set to wdprintfromto
Ref Wdprintto, // Ending page number when range is set to wdprintfromto
Ref Omissing,
Ref Copies, // Number of copies to print
Ref Omissing, Ref Omissing, Ref Omissing,Ref Omissing, Ref Omissing, Ref Omissing, Ref Omissing, Ref Omissing, Ref Omissing, Ref Omissing );

Lblmessage. Text ="Printing. Please wait!";

//Close the Word file after printing
Doc. Close (RefDonotsavechanges,RefOmissing,RefOmissing );

//Restore the original default printer
Appword. activeprinter = defaultprinter;

//Exit the word Program
Appword. Quit (RefOmissing,RefOmissing,RefOmissing );

Doc =Null;
Appword =Null;

Lblmessage. Text ="Printed successfully!";

 

 

Parameters

Background

IfTrue, You can set the customCodeContinue to work when Microsoft Office Word prints documents.

Append

IfTrueThe file is appended to the file specified by the outputfilename parameter.FalseThe content of outputfilename will be rewritten.

Range

Page range. It can be any wdprintoutrange value.

Outputfilename

If printtofile isTrueThis parameter specifies the path and file name of the output file.

From

The starting page number when range is set to wdprintfromto.

To

When range is setWdprintfromtoThe ending page number.

Item

The entry to be printed. It can be any wdprintoutitem value.

Copies

The number of copies to print.

Pages

The page number to be printed and the page number range are separated by commas. For example, "2, 6-10" indicates printing 2nd pages and 6th, 7, 8, 9, and 10 pages.

Pagetype

The type of the page to be printed. It can be any wdprintoutpages value.

Printtofile

IfTrueTo send the printer command to the file. Make sure that you use outputfilename to specify a file name.

Collate

When printing multiple documents, ifTrue, Print all pages of the document first, and then print the next copy.

Activeprintermacgx

This parameter is only available in Microsoft Office Macintosh edition. For more information about this parameter, see the language reference help for Microsoft Office Macintosh edition.

Manualduplexprint

IfTrueTo print dual-sided documents on a printer without a dual-sided printer. If this parameter isTrueThe printbackground and printreverse attributes are ignored. Use the printoddpagesinascendingorder and printevenpagesinascendingorder attributes to control the output during manual dual-sided printing. You may not be able to use this parameter, depending on the language you select or install (for example, U.S. English ).

Printzoomcolumn

The number of pages on which word is expected to be horizontally arranged on one page. It can be 1, 2, 3, or 4. When used with the printzoomrow parameter, you can print multiple pages on a single sheet of paper.

Printzoomrow

The number of pages that you want the word to vertically deploy on one page. It can be 1, 2, or 4. When used with the printzoomcolumn parameter, you can print multiple pages on a single sheet of paper.

Printzoompaperwidth

You want word to scale the width of the print page (in TDE format, 20 TDE = 1 lb, 72 lbs = 1 inch ).

Printzoompaperheight

We want word to scale the height of the print page (in TDE, 20 TDE = 1 lb, 72 lbs = 1 inch ).

Remarks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.