using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using Word = ;
using Excel = ;
using PowerPoint = ;
using ;
namespace ConvertToPDF
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (DOCConvertToPDF("C:/", "C:/"))
{
("DOC conversion was successful!");
}
else
{
("Sorry, the conversion failed!");
}
if (XLSConvertToPDF("C:/", "C:/"))
{
("XLS conversion was successful!");
}
else
{
("Sorry, the conversion failed!");
}
if (PPTConvertToPDF("C:/Requirement Outline.pptx", "C:/"))
{
("PPT conversion was successful!");
}
else
{
("Sorry, the conversion failed!");
}
}
//Convert Word to pdf
///<summary>
/// Convert Word files to PDF files
///</summary>
///<param name="sourcePath">source file path</param>
///<param name="targetPath">target file path</param>
///<returns>true=Conversion successful</returns>
private bool DOCConvertToPDF(string sourcePath, string targetPath)
{
bool result=false;
exportFormat = ;
object paramMissing = ;
wordApplication = new ();
wordDocument = null;
try
{
object paramSourceDocPath = sourcePath;
string paramExportFilePath = targetPath;
paramExportFormat = exportFormat;
bool paramOpenAfterExport = false;
paramExportOptimizeFor = ;
paramExportRange = ;
int paramStartPage = 0;
int paramEndPage = 0;
paramExportItem = ;
bool paramIncludeDocProps = true;
bool paramKeepIRM = true;
paramCreateBookmarks = ;
bool paramDocStructureTags = true;
bool paramBitmapMissingFonts = true;
bool paramUseISO19005_1 = false;
wordDocument = (
ref paramSourceDocPath, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing);
if (wordDocument != null)
(paramExportFilePath,
paramExportFormat, paramOpenAfterExport,
paramExportOptimizeFor, paramExportRange, paramStartPage,
paramEndPage, paramExportItem, paramIncludeDocProps,
paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
paramBitmapMissingFonts, paramUseISO19005_1,
ref paramMissing);
result = true;
}
catch
{
result = false;
}
finally
{
if (wordDocument != null)
{
(ref paramMissing, ref paramMissing, ref paramMissing);
wordDocument = null;
}
if (wordApplication != null)
{
(ref paramMissing, ref paramMissing, ref paramMissing);
wordApplication = null;
}
();
();
();
();
}
return result;
}
///<summary>
/// Convert Excel files to PDF files
///</summary>
///<param name="sourcePath">source file path</param>
///<param name="targetPath">target file path</param>
///<returns>true=Conversion successful</returns>
private bool XLSConvertToPDF(string sourcePath, string targetPath)
{
bool result = false;
targetType = ;
object missing = ;
application = null;
workBook = null;
try
{
application = new ();
object target = targetPath;
object type = targetType;
workBook = (sourcePath, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing);
(targetType, target, , true, false, missing, missing, missing, missing);
result = true;
}
catch
{
result = false;
}
finally
{
if (workBook != null)
{
(true, missing, missing);
workBook = null;
}
if (application != null)
{
();
application = null;
}
();
();
();
();
}
return result;
}
///<summary>
/// Convert PowerPoint files to PDF files
///</summary>
///<param name="sourcePath">source file path</param>
///<param name="targetPath">target file path</param>
///<returns>true=Conversion successful</returns>
private bool PPTConvertToPDF(string sourcePath, string targetPath)
{
bool result;
targetFileType = ;
object missing = ;
application = null;
persentation = null;
try
{
application = new ();
persentation = (sourcePath, , , );
(targetPath, targetFileType, );
result = true;
}
catch
{
result = false;
}
finally
{
if (persentation != null)
{
();
persentation = null;
}
if (application != null)
{
();
application = null;
}
();
();
();
();
}
return result;
}
}
}