Printing a Word document with margins from the print area

I have a code where I print a document. There is a picure section in the sample document that changes fields by the user.

When I execute the code, I get the following message:

The margins of section 1 are set outside the printable area. A.

After processing the document, buffering starts and this miss is thrown enter image description here How to disable the notification dialog?

my code is:

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 is the variable path> is the path to the file name

+4
source share
1 answer

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

Accordingly, you need to disable background printing, and then disable Application.DisplayAlerts.

EDIT

You cannot do this with Process . The verb print uses / x / dde to tell Word to print:

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

To suppress the message, you will need to do interop:

  • Add link to Microsoft.Office.Interop.Word
  • Make the 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 
+6
source

Source: https://habr.com/ru/post/1379099/


All Articles