Discuss this help topic in SecureBlackbox Forum
Sign document
To sign OpenXPS (Open XML Paper Specification, XPS) document using XML digital signature handler you need to
C#:
void SignXPS(string sourceFilename, TElX509Certificate certificate)
{
using (TElOfficeDocument Document = new TElOfficeDocument())
{
Document.Open(sourceFilename);
if ((Document.DocumentFormat != TSBOfficeDocumentFormat.OpenXPS) || !Document.Signable)
throw new Exception("Cannot sign document using XML signature handler");
TElOfficeOpenXPSSignatureHandler OpenXPSSigHandler = new TElOfficeOpenXPSSignatureHandler();
Document.AddSignature(OpenXPSSigHandler, true);
OpenXPSSigHandler.AddDocument();
OpenXPSSigHandler.Sign(certificate);
}
}
Delphi:
procedure SignXPS(const SourceFilename : string; Certificate : TElX509Certificate);
var
Document : TElOfficeDocument;
OpenXPSSigHandler : TElOfficeOpenXPSSignatureHandler;
begin
Document := TElOfficeDocument.Create(nil);
try
Document.Open(SourceFilename);
if (Document.DocumentFormat <> dfOpenXPS) or not Document.Signable then
raise Exception.Create('Cannot sign document using XML signature handler');
OpenXPSSigHandler := TElOfficeOpenXPSSignatureHandler.Create(nil);
Document.AddSignature(OpenXPSSigHandler, True);
OpenXPSSigHandler.AddDocument();
OpenXPSSigHandler.Sign(Certificate);
finally
FreeAndNil(Document);
end;
end;