I am trying to extract the attachments from a pdf file and save them. Following is the code that I have wrote so far:
Code: Select all
private void button1_Click(object sender, EventArgs e)
{
IPXC_Document loDoc = null;
int liResult = 0;
string lsFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "AttachmentTest4.pdf");
try
{
// load the pdf file
//Getting IAFS_Inst from IPXV_Inst
IAFS_Inst fsInst = (IAFS_Inst)mTrackerInstance.GetExtension("AFS");
IPXC_NameTree loNameTree = loDoc.GetNameTree("EmbeddedFiles");
for (int i=1; i<= loNameTree.Count; i++)
{
string lsName = string.Empty;
IPXS_PDFVariant loPdfVariant = null;
// get the name of the attachment
loNameTree.Item((uint)i - 1, out lsName, out loPdfVariant);
// Converting string to name
lsName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), lsName);
// delete the file if it already exists on the file system
if (File.Exists(lsName))
{
File.Delete(lsName);
}
//
// what do I need to do here to save the attachment
//
Marshal.ReleaseComObject(loPdfVariant);
loPdfVariant = null;
}
Marshal.ReleaseComObject(loNameTree);
loNameTree = null;
loDoc.Close();
loDoc = null;
Marshal.ReleaseComObject(fsInst);
fsInst = null;
}
}
catch(Exception loException)
{
liResult = -2;
}
finally
{
if (loDoc != null)
{
loDoc.Close();
loDoc = null;
}
}
}
Regards,
M