Hi Team,
We are trying to convert a .Odt file to .pdf via first saving the .odt file as .doc and then opening up the .doc file and save it as .pdf.
But while saving the file as .pdf it is giving error : An unhandled exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll
Additional information: The given key was not present in the dictionary.
We are using Spire.doc version : 5.6.62 and Spire.PDF version : 3.6.260 (Trial one)
Please find the below sample code :
public void generateDoc()
{
string strParth = @"C:\Users\nirad_smart\Downloads\";
string FileName = @"Sample_invoice.odt";
string FileName1 = @"Sample_invoice_doc";
string FileExt = @".doc";
string docfileName = strParth + FileName1 + FileExt;
Stream stream = File.OpenRead(strParth + FileName);
using (Stream file = File.Create(strParth + FileName1 + FileExt))
{
CopyStream(stream, file);
}
stream.Close();
Document doc = new Document();
doc.LoadFromFile(docfileName);
doc.SaveToFile("final.pdf", FileFormat.PDF);
}
/// <summary>
/// Copies the contents of input to output. Doesn't close either stream.
/// </summary>
public static void CopyStream(Stream input, Stream output)
{
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, len);
}
}
}
Can you please help us out here ?