Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing word document with margins out of printable area

I have a code where i am printing word document. In the sample document there is a section with picure that has modified margins by user.

When i execute the code I recieve following message:

The margin of section 1 are set outside of printable area.

After processing document, it starts spooling and throws this promt enter image description here How do i turn the notification dialog box off?

my code so far:

        Process printJob = new Process();
        printJob.StartInfo.Verb = "PrintTo";
        printJob.StartInfo.Arguments = printerName;
        printJob.StartInfo.ErrorDialog = false;
        printJob.StartInfo.CreateNoWindow = true;
        printJob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        printJob.StartInfo.FileName = path;
        printJob.StartInfo.UseShellExecute = true;
        printJob.StartInfo.Verb = "print";
        printJob.Start();

Where variable path > is file name path

like image 582
cpoDesign Avatar asked Nov 01 '11 09:11

cpoDesign


1 Answers

http://word.mvps.org/faqs/macrosvba/OutsidePrintableArea.htm

According to this, you'll need to turn off background printing, then turn off Application.DisplayAlerts.

EDIT

You're not going to be able to do this with Process. The "print" verb uses /x /dde to tell Word to print:

/x Starts a new instance of Word from the operating shell (for example, to print in Word). This instance of Word responds to only one DDE request and ignores all other DDE requests and multi-instances. If you are starting a new instance of Word in the operating environment (for example, in Windows), it is recommended that you use the /w switch, which starts a fully functioning instance.

To suppress the message, you're going to need to do interop instead:

  1. Add a reference to Microsoft.Office.Interop.Word
  2. Make a Print(string path) method:
Application wordApp = new Application();
wordApp.Visible = false;

//object missing = Type.Missing;

wordApp.Documents.Open(path); //for VS 2008 and earlier - just give missing for all the args

wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone;
wordApp.ActiveDocument.PrintOut(false); //as before - missing for remaining args, if using VS 2008 and earlier

wordApp.Quit(WdSaveOptions.wdDoNotSaveChanges); //ditto
like image 58
sq33G Avatar answered Sep 30 '22 16:09

sq33G