Hi
I facing issue while opening pdf while it give me erroe as
There was an error in opening document,root object is missing or invalid
I use following code for pdf ,
In temporay folder it created new decrypted file on click of preview button that decrypted file is open.this code is working fine for all pdf,just failed for one particualr pdf.only for one particular pdf it giving me error as
There was an error in opening document,root object is missing or invalid</b>
what to do in such case?
private void ListFieldNames()
{
int formID = 0;
string formName = "";
bool isDeleted = false;
DataTable formIDTable = new DataTable();
try
{
PdfReader pdfReader = null;
isApplInfo = 1;
if (this.CalledFrom != "1")
{
pdfForm = ucmbForm.SelectedRow.Cells["FormFileName"].Value.ToString();
Client client = new Client();
pdfTemplate = client.GetApplicationFolderPath(ApplicationUser.LicenseType) + @"\" + pdfForm + "";
}
else
{
pdfForm = Path.GetFileName(utxtBrowse.Text.Trim());
pdfTemplate = utxtBrowse.Text.Trim();
}
decryptedPDFPath = localPath + @"\" + ConfigurationSettings.AppSettings["TempFilesPath"] + @"\DecryptPDFFolder";
if (!Directory.Exists(decryptedPDFPath))
{
Directory.CreateDirectory(decryptedPDFPath);
}
int i = 0;
decryptedPDFPath = decryptedPDFPath + @"\" + pdfForm + "";
Security security = new Security();
if (File.Exists(decryptedPDFPath))
{
File.Delete(decryptedPDFPath);
}
if (File.Exists(pdfTemplate))
{
isFilepresent = 0;
try
{
if (calledFrom == "")
{
security.DecryptFile256("DSSIPL", pdfTemplate, decryptedPDFPath); pdfReader = new PdfReader(decryptedPDFPath);
}
else
{
File.Copy(pdfTemplate, decryptedPDFPath, true);
pdfReader = new PdfReader(decryptedPDFPath);
}
}
catch
{
if (calledFrom == "1")
{
File.Copy(pdfTemplate, decryptedPDFPath, true);
}
pdfReader = new PdfReader(decryptedPDFPath);
}
arrayPdffields = new string[pdfReader.AcroFields.Fields.Count];
foreach (DictionaryEntry dictionaryentry in pdfReader.AcroFields.Fields)
{
arrayPdffields[i] = dictionaryentry.Key.ToString();
i = i + 1;
}
pdfReader.Close();
}
else
{
isFilepresent = 1;
UltraMessageBox.Show(" The PDF file of the form that you have selected is missing.\n Please download this form again",
applicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
formID = Convert.ToInt32(ucmbForm.Value);
formName = Convert.ToString(ucmbForm.Text);
formIDTable.Columns.Add("FormID", typeof(System.Int32));
formIDTable.Columns.Add("FormName", typeof(System.String));
formIDTable.Rows.Add(new object[] { formID, formName });
isDeleted = iApplicationFormsBridge.DeleteDispatchFormsRows(formIDTable);
if (isDeleted)
{
FillForm();
}
isDeleted = false;
}
}
catch
{
throw;
}
}
internal void DecryptFile256(string strKey, string fileNameInput, string fileNameOutput)
{
Stream fileIn = null;
Stream fileOut = null;
MemoryStream decStream = null;
try
{
fileIn = OpenFile(fileNameInput, FileMode.Open, FileAccess.Read);
fileOut = OpenFile(fileNameOutput, FileMode.OpenOrCreate, FileAccess.Write);
decStream = DecryptStream256(strKey, fileIn); decStream.WriteTo(fileOut);
}
catch
{
throw;
}
finally
{
fileIn.Close();
fileOut.Close();
decStream = null;
}
}
}
internal MemoryStream DecryptStream256(string strKey, Stream inputStream)
{
byte[] byteKey = null;
byte[] buff = null;
int lenRead = 0;
Cryptography.CryptoStream decStream = null;
MemoryStream outputStream = null;
Cryptography.SymmetricAlgorithm objSymmAlgorithm = null;
try
{
buff = new byte[1000];//decryption buffer.
byteKey = GetByteKeys256(strKey);
outputStream = new MemoryStream();
objSymmAlgorithm = new Cryptography.RijndaelManaged();
decStream = new Cryptography.CryptoStream(outputStream, objSymmAlgorithm.CreateDecryptor(byteKey, VECTOR_IV_256), Cryptography.CryptoStreamMode.Write);
//do the deryption ...
inputStream.Position = 0;
while( (lenRead = inputStream.Read(buff, 0,buff.Length))>0)
{
decStream.Write(buff, 0, lenRead);
}
decStream.FlushFinalBlock();
outputStream.Flush();
return outputStream;
}
catch
{
throw;
}
finally
{
objSymmAlgorithm = null;
decStream = null;
byteKey = null;
buff = null;
}
}