Created
March 8, 2015 15:47
-
-
Save jonghwanhyeon/3f9def11368d4c52893c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Microsoft.Office.Interop.Word; | |
namespace Converter | |
{ | |
class WordConverter : IConverter | |
{ | |
private Application application; | |
public WordConverter() | |
{ | |
this.application = new Application(); | |
this.application.ScreenUpdating = false; | |
this.application.DisplayAlerts = WdAlertLevel.wdAlertsNone; | |
} | |
~WordConverter() | |
{ | |
// casting to _Application to prevent type conflicts | |
((_Application)this.application).Quit(WdSaveOptions.wdDoNotSaveChanges); | |
} | |
public void ToPDF(string sourceFilename, string destinationFilename) | |
{ | |
Document document = this.application.Documents.Open( | |
FileName: sourceFilename, | |
ConfirmConversions: false, | |
ReadOnly: true, | |
AddToRecentFiles: false, | |
Revert: true | |
); | |
document.ExportAsFixedFormat( | |
OutputFileName: destinationFilename, | |
ExportFormat: WdExportFormat.wdExportFormatPDF, | |
OpenAfterExport: false, | |
OptimizeFor: WdExportOptimizeFor.wdExportOptimizeForPrint, | |
BitmapMissingFonts: true | |
); | |
((_Document)document).Close(WdSaveOptions.wdDoNotSaveChanges); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment