我尝试了下面的代码,但没有打开它就无法签署文件。是否可以在不打开证书的情况下签署带有证书的文件。
object TempFilePath = TemporaryFolder + FileTempName;
object Visible = false;
object readonlyfile = false;
try
{
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.ApplicationClass wordapp = new
Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document wordDocument = wordapp.Documents.Open(ref
TempFilePath, ref missing,
ref readonlyfile, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref Visible, ref missing, ref missing,
ref missing, ref missing);
// wordDocument.Activate();
// object sigID = "{00000000-0000-0000-0000-000000000000}";
// wordDocument.ActiveWindow.Application.ActiveDocument.Signatures.AddSignatureLine(sigID);
// wordDocument.ActiveWindow.Application.ActiveDocument.Signatures.Commit();
SignatureSet signatureSet = wordDocument.Signatures;
Signature objSignature = signatureSet.Add();
if (objSignature == null)
{
DocumentNotSigned(item);
return false;
}
else
{
signatureSet.Commit();
object saveChanges = true;
wordDocument.Close(ref saveChanges, ref missing, ref missing);
wordapp.Quit(ref missing, ref missing, ref missing);
return true;
}