Printing to Microsoft Office Document Image Writer

B

Big Daddy

I am trying to use VSTO & C# to iterate over each page of the document and
print it to a MDI doc.

when i get to the print out part the it seems as though it is showing a
print dialog or something but its not visable, the code just hangs. My
code: (there is some other misc bs )

Word.Application app;

Office.CommandBarButton btn;

Office.CommandBarComboBox cboBox;

object UnitLine = Word.WdUnits.wdLine;

object UnitStory = Word.WdUnits.wdStory;

object wdExtend =Word.WdMovementType.wdExtend;

object wdMove = Word.WdMovementType.wdMove;

object mkTrue = true;

object OutputfileName ;

private void MDIOut()

{

string remove,fileName;

object prtCurrentPage =Word.WdPrintOutRange.wdPrintCurrentPage;

ActiveWindow.ActivePane.View.SeekView =

Word.WdSeekView.wdSeekCurrentPageHeader;

app.Selection.HomeKey(ref UnitStory , ref wdMove);

app.Selection.EndKey(ref UnitLine, ref wdExtend);

MessageBox.Show(app.Selection.Text);

app.ActivePrinter = "Microsoft Office Document Image Writer";

for (int i = 0; i <= app.ActiveDocument.Sections.Count; i++)

{

ActiveWindow.ActivePane.View.SeekView =

Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;

//ref OutputfileName

fileName = "C:\\File" + i + ".doc";


app.PrintOut( ref missing , ref missing, ref prtCurrentPage,ref missing,

ref missing, ref missing, ref missing, ref missing, ref missing,

ref missing, ref mkTrue, ref missing, ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing, ref missing );

}
 
P

Peter Huang [MSFT]

Hi

I think you may try to use the PrintOut Method as below.
Sub Test()
Application.PrintOut , , , "c:\test1.mdi", , , , , , , True
End Sub

This code is for VBA, but it should be similar in C#.

<quote>
Prints all or part of the specified document.

expression.PrintOut(Background, Append, Range, OutputFileName, From, To,
Item, Copies, Pages, PageType, PrintToFile, Collate, FileName,
ActivePrinterMacGX, ManualDuplexPrint, PrintZoomColumn, PrintZoomRow,
PrintZoomPaperWidth, PrintZoomPaperHeight)
expression Required. An expression that returns one of the above objects.

Background Optional Variant. Set to True to have the macro continue while
Microsoft Word prints the document.

Append Optional Variant. Set to True to append the specified document to
the file name specified by the OutputFileName argument. False to overwrite
the contents of OutputFileName.

Range Optional Variant. The page range. Can be any WdPrintOutRange
constant.

wdPrintAllDocument
wdPrintCurrentPage
wdPrintFromTo
wdPrintRangeOfPages
wdPrintSelection

OutputFileName Optional Variant. If PrintToFile is True, this argument
specifies the path and file name of the output file.

From Optional Variant. The starting page number when Range is set to
wdPrintFromTo.

To Optional Variant. The ending page number when Range is set to
wdPrintFromTo.

Item Optional Variant. The item to be printed. Can be any WdPrintOutItem
constant.

wdPrintAutoTextEntries
wdPrintComments
wdPrintDocumentContent
wdPrintDocumentWithMarkup
wdPrintEnvelope
wdPrintKeyAssignments
wdPrintMarkup
wdPrintProperties
wdPrintStyles

Copies Optional Variant. The number of copies to be printed.

Pages Optional Variant. The page numbers and page ranges to be printed,
separated by commas. For example, "2, 6-10" prints page 2 and pages 6
through 10.

PageType Optional Variant. The type of pages to be printed. Can be any
WdPrintOutPages constant.

wdPrintAllPages
wdPrintEvenPagesOnly
wdPrintOddPagesOnly

PrintToFile Optional Variant. True to send printer instructions to a
file. Make sure to specify a file name with OutputFileName.

Collate Optional Variant. When printing multiple copies of a document,
True to print all pages of the document before printing the next copy.

FileName Optional Variant. The path and file name of the document to be
printed. If this argument is omitted, Word prints the active document.
(Available only with the Application object.)

ActivePrinterMacGX Optional Variant. This argument is available only in
Microsoft Office Macintosh Edition. For additional information about this
argument, consult the language reference Help included with Microsoft
Office Macintosh Edition.

ManualDuplexPrint Optional Variant. True to print a two-sided document on
a printer without a duplex printing kit. If this argument is True, the
PrintBackground and PrintReverse properties are ignored. Use the
PrintOddPagesInAscendingOrder and PrintEvenPagesInAscendingOrder properties
to control the output during manual duplex printing. This argument may not
be available to you, depending on the language support (U.S. English, for
example) that you¡¯ve selected or installed.

PrintZoomColumn Optional Variant. The number of pages you want Word to
fit horizontally on one page. Can be 1, 2, 3, or 4. Use with the
PrintZoomRow argument to print multiple pages on a single sheet.

PrintZoomRow Optional Variant. The number of pages you want Word to fit
vertically on one page. Can be 1, 2, or 4. Use with the PrintZoomColumn
argument to print multiple pages on a single sheet.

PrintZoomPaperWidth Optional Variant. The width to which you want Word to
scale printed pages, in twips (20 twips = 1 point; 72 points = 1 inch).

PrintZoomPaperHeight Optional Variant. The height to which you want Word
to scale printed pages, in twips (20 twips = 1 point; 72 points = 1 inch).

</quote>


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

thom

I tried the vba code and it worked well but when i translated it to C#(Code
below) i got this error msg:

Word experienced an error trying to open the file.
try these suggestions.

Check the file permissions for the document or drive.
make sure there is suffcient free memeory and disk space.
open the file with the text recovery converter


CODE :

Word.Application app;
Office.CommandBarButton btn;
Office.CommandBarComboBox cboBox;
object UnitLine = Word.WdUnits.wdLine;
object UnitStory = Word.WdUnits.wdStory;
object wdExtend =Word.WdMovementType.wdExtend;
object wdMove = Word.WdMovementType.wdMove;
object mkTrue = false;
object OutputfileName ;
private void MDIOut()
{
try
{
string remove,fileName;
object prtCurrentPage =Word.WdPrintOutRange.wdPrintCurrentPage;

ActiveWindow.ActivePane.View.SeekView =
Word.WdSeekView.wdSeekCurrentPageHeader;

app.Selection.HomeKey(ref UnitStory , ref wdMove);
app.Selection.EndKey(ref UnitLine, ref wdExtend);

MessageBox.Show(app.Selection.Text);

ActiveWindow.ActivePane.View.SeekView =
Word.WdSeekView.wdSeekMainDocument;

// app.ActivePrinter = "Microsoft Office Document Image Writer";

for (int i = 0; i <= app.ActiveDocument.Sections.Count; i++)
{
ActiveWindow.ActivePane.View.SeekView =
Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;

//Documents and Settings\\krr\\My Documents\\File\\

// I TRIED USING EACH OF THESE FOR THE FILE NAM NIETHER WORKED
OutputfileName = "C:\\doc" + i +".mdi";
OutputfileName = @"C:\doc1.mdi";


app.PrintOut(ref missing, ref missing, ref prtCurrentPage, ref
OutputfileName,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref mkTrue, ref missing, ref OutputfileName, ref
missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
}
}catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
 
P

Peter Huang [MSFT]

Hi,

The code below works at my side. Please have a try.

private void button1_Click(object sender, EventArgs e)
{
Word.Application app = new Word.ApplicationClass();
object o = System.Reflection.Missing.Value;
Word.Document doc = app.Documents.Add(ref o, ref o, ref o, ref
o);
doc.Content.Text = "Test";
object outputname = @"C:\testAAA.mdi";
object ptf = true;
app.PrintOut(ref o, ref o, ref o, ref outputname, ref o, ref o,
ref o, ref o, ref o, ref o, ref ptf, ref o, ref o, ref o, ref o, ref o, ref
o, ref o, ref o);
}


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

thom

I modified your code to print only the current page to an mdi doc with a
varaible filename, the code didnt throw an exception, but when i tried to
open the mdi file i get the message:

The selected file is not a valid Microsoft office document imaging file.

i tried changing the print to file - false that didnt work and then i added
the line
app.ActivePrinter = "Microsoft Office Document Image Writer";
with that line, i dont even see a file at c:\ but when the app closes down i
see them.

the only problem now is that the mdi docs open, i would rather them not this
doc has 137 pages and after many open a msgbox shows "There are too many
documents open please close some" but other wise the endresult works liek a
charm

try
{
object ptf = false;
object o = System.Reflection.Missing.Value;
object prtCurrentPage =Word.WdPrintOutRange.wdPrintCurrentPage;
app.ActivePrinter = "Microsoft Office Document Image Writer";
for (int i = 0; i <= app.ActiveDocument.Sections.Count; i++)
{
object outputname = string.Format(@"C:\mdiTest\test{0}.mdi", i);

app.PrintOut(ref o, ref o, ref prtCurrentPage, ref outputname,
ref o, ref o,ref o, ref o, ref o, ref o, ref ptf,
ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
}

any idea how to stop the mdi docs from showing and the msgbox???
 
P

Peter Huang [MSFT]

Hi,

Based on my understanding, now you can print the word document to a MDI
file.
But you did not want the pop up MDI window when the print is off.

I think this is somewhat related with the printer driver of the MDI
printer. I have browsing all the possible setting for the MDI printer, it
seems that there is no such option to disable it.

For detailed information I suggest you contact MSPSS directly because for
the issue about how MDI printer working is out of the scope of this
newsgroup.
http://support.microsoft.com

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top