Printing one page of the document in one paper works fine, but my intention is to print four pages in a single A4 paper. If I change the printZoomColumn, and printZoomRow parameter of the printout method, It prints out a blank page.(although the pages matches. I printed out a document of 5 pages, and with the above parameters, it prints out 2 blank pages.)
I use office 2007, and Visual Studio 2012.
My code here is,
public void test5()
{
try
{
// Declaring the object variables we will need later
object varFileName = filePath;
object varFalseValue = false;
object varTrueValue = true;
object varMissing = Type.Missing;
object False = false;
// Create a reference to Microsoft Word application
Microsoft.Office.Interop.Word.Application varWord =
new Microsoft.Office.Interop.Word.Application();
// Creates a reference to a Word document
varWord.Visible = false;
Microsoft.Office.Interop.Word.Document varDoc =
varWord.Documents.Open(ref varFileName, ref varMissing,
true,
ref varMissing, ref varMissing, ref varMissing, ref varMissing,
ref varMissing, ref varMissing, ref varMissing,
ref varMissing, varFalseValue, ref varMissing, ref varMissing,
ref varMissing, ref varMissing);
varDoc.Activate();
object copies = "1";
object pages = "";
object range = Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintAllDocument;
object items = Microsoft.Office.Interop.Word.WdPrintOutItem.wdPrintDocumentContent;
object pageType = Microsoft.Office.Interop.Word.WdPrintOutPages.wdPrintAllPages;
object oTrue = true;
object oFalse = false;
object row = "2";
varDoc.PrintOut(ref oTrue, ref varFalseValue, ref range,
ref varMissing, ref varMissing, ref varMissing,
ref items, ref copies, ref pages, ref pageType,
ref varFalseValue, ref oTrue, ref varMissing,
ref varMissing, ref row, ref row, ref varMissing,
ref varMissing);
}
catch (Exception varE)
{
MessageBox.Show("Error:\n" + varE.Message, "Error message");
}
}
On the above source, changing the printout like this works.
varDoc.PrintOut(ref oTrue, ref varFalseValue, ref range,
ref varMissing, ref varMissing, ref varMissing,
ref items, ref copies, ref pages, ref pageType,
ref varFalseValue, ref oTrue, ref varMissing,
ref varMissing, ref varMissing, ref vaMissing, ref varMissing,
ref varMissing);
But, this is not my intention. I want to print four pages inside the document in a single A4 paper. Is there some concept I'm missing?
I can't test this with Office 2007 as I only have 2010 installed here but even in the 2007 interop most (if not all) parameters are optional and if you're using VS2012 the c# should understand optional parameters
document.PrintOut(Background: true, PrintZoomRow: 2, PrintZoomColumn: 2);
So just supply the parameters you actually care about. I think you have to provide the PrintZoomColumn parameter as well for Multiple Pages per Sheet to work, from MSDN:
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.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments