Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Office.Interop.Word;
- using System.IO;
- using WindowsFormsWordToPDFMonitor.Properties;
- using iTextSharp.text.pdf;
- namespace WindowsFormsWordToPDFMonitor
- {
- class PendingJob
- {
- private string _name;
- private string[] pending;
- private string _done;
- private string _output;
- public PendingJob(string name, string[] pending, string pathDone, string pathOutput)
- {
- this._name = name;
- this.pending = pending;
- this._done = pathDone;
- this._output = pathOutput;
- }
- private void NAR(object o)
- {
- try
- {
- System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
- }
- catch { }
- finally
- {
- o = null;
- }
- }
- internal void Process(Microsoft.Office.Interop.Word.Application wordApp, String templates)
- {
- String outputPath = Path.Combine(Path.GetFullPath(_output), pending[1]);
- if (!File.Exists(outputPath))
- {
- // Open document
- Document doc;
- try
- {
- doc = wordApp.Documents.Open(Path.Combine(Path.GetFullPath(templates), pending[0]), Visible: true);
- }
- catch
- {
- throw new Exception("Error opening the file");
- }
- // Save document
- try
- {
- doc.SaveAs(FileName: outputPath, FileFormat: WdSaveFormat.wdFormatPDF);
- doc.Close(SaveChanges: WdSaveOptions.wdDoNotSaveChanges);
- NAR(doc);
- }
- catch
- {
- throw new Exception("Error saving the file");
- }
- }
- File.CreateText(Path.Combine(Path.GetFullPath(_done), this._name)).Close();
- }
- }
- }
Add Comment
Please, Sign In to add comment