So i have tried two different pieces of code for converting a doc to a pdf and i am getting the same error `PDF header signature not found` this is my code that i have:
private void Word2PDF()
{
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object oMissing = System.Reflection.Missing.Value;
DirectoryInfo dirInfo = new DirectoryInfo("C:\\TestFilestore\\");
FileInfo[] wordFiles = dirInfo.GetFiles("*.doc");
word.Visible = false;
word.ScreenUpdating = false;
foreach (FileInfo wordFile in wordFiles)
{
Object filename = (Object)wordFile.FullName;
Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(ref filename, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.Activate();
object outputFileName = wordFile.FullName.Replace(".doc", ".pdf");
object fileFormat = WdSaveFormat.wdFormatPDF;
doc.SaveAs(ref outputFileName,
ref fileFormat, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
doc = null;
}
((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
word = null;
}
And here is where it is breaking:
static public void CopyPages(string source, string dest)
{
var reader = new iTextSharp.text.pdf.PdfReader(source);
using (FileStream fs = new FileStream(dest, FileMode.Create, FileAccess.Write, FileShare.None))
{
iTextSharp.text.Document doc = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(1));
{
iTextSharp.text.pdf.PdfCopy copy = new iTextSharp.text.pdf.PdfCopy(doc, fs);
{
doc.Open();
copy.SetLinearPageMode();
for (int i = 1; i <= reader.NumberOfPages; i++)
{
copy.AddPage(copy.GetImportedPage(reader, i));
}
doc.Close();
}
}
}
}
This is the line that it breaks:
var reader = new iTextSharp.text.pdf.PdfReader(source);
Any help will be great... pleas :) Thanks!