Failed in printing a PPT to XPS by using office COM

L

Larry_zhou

Hi,
I encountered a problem about printing of PowerPoint by using office COM. I
wrote the following code to print a ppt to XPS, but the result is not always
successful, the size of output (XPS file) is 0 byte, or it is error for
viewing. When I use the same code to print serveral ppts, the error is more
apparent.

My local environment is office 2003, and the program refernces to its COM.

Hope anyone who know the problem can give me some advice.
Thank you very much.

Code:
PowerPoint.Application ppt = new PowerPoint.ApplicationClass();
PowerPoint._Presentation pres = null;
pres = ppt.Presentations.Open(fileName, MsoTriState.msoTrue,
MsoTriState.msoFalse,
MsoTriState.msoFalse);

// set print options
pres.PrintOptions.ActivePrinter = "Microsoft XPS Document Writer";
pres.PrintOptions.RangeType = PowerPoint.PpPrintRangeType.ppPrintAll;
pres.PrintOptions.PrintInBackground = MsoTriState.msoFalse;
pres.PrintOptions.OutputType =
owerPoint.PpPrintOutputType.ppPrintOutputSlides;
pres.PrintOptions.FitToPage = MsoTriState.msoTrue;

// print document with 1 copy and without collate
pres.PrintOut(from, to, destFile, 1, MsoTriState.msoFalse);
 
F

Faisal Shafiq

Try this should work

Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();

Presentation pptPresent = ppt.Presentations.Open(@"c:/temp/Chapter3.ppt", MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoFalse);

pptPresent.PrintOptions.ActivePrinter = "Microsoft XPS Document Writer";
//pptPresent.PrintOptions.RangeType = PowerPoint.PpPrintRangeType.ppPrintAll;
pptPresent.PrintOptions.PrintInBackground = MsoTriState.msoTrue;
pptPresent.PrintOptions.OutputType = PpPrintOutputType.ppPrintOutputSlides;
//pptPresent.PrintOptions.FitToPage = MsoTriState.msoTrue;

pptPresent.PrintOut(1, 1, @"c:/temp/Chapter3Thatsit.xps", 1, MsoTriState.msoTriStateMixed);
 

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