On Tue, 2023-03-28 at 07:19 +0200, zyx wrote:
> I can test the podofo-sign, after all I added it.
Hi,
I gave it a try, with the git master at commit
2571cdb504d63de96c3de2326839a845b9049739 (which is from April 6th), and
there are problems. Those easy are caught by the attached patch (note
there is an unrelated change shown, the first chunk, which I did not do
myself; maybe it would worth a .gitignore entry? I'm not sure).
Left problems:
- annotation texts are not shown
- using -out argument causes creation of invalid file
I did not get why the first is broken, I'm sorry.
For the second, your API changes expect read from the destination file,
but that file is empty when using the -out argument, thus the things
break. I do not follow reasons for those changes, but I believe it's a
good thing to have separate input and output files.
I stopped my tests here. There are more arguments to be tested.
To be able to easily reproduce this for anybody interested, I ran:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256
-days 365
to generate the certificate, then run the helloworld binary to create a
source PDF file (or pick any existing PDF file). Then run podofosign on
it:
podofosign -in a.pdf -cert cert.pem -pkey key.pem -password PASS \
-annot-position 1,10,10,100,100 \
-annot-text 1,1,annottext
Also, make sure you backup the a.pdf, because this call overwrites it,
thus to do another call do restore it from the backup first.
Needless to say, the svn trunk code creates expected output.
I'm not sure how to continue at this stage, I'm sorry.
Bye,
zyx
diff --git a/extern/resources b/extern/resources
index dcef880f..46cd2625 160000
--- a/extern/resources
+++ b/extern/resources
@@ -1 +1 @@
-Subproject commit dcef880f1123a3b898ea97e8b51eb3880ba804c6
+Subproject commit 46cd26250de642e0d8acdbf3f157d97be8326b2a
diff --git a/src/podofo/main/PdfSignature.cpp b/src/podofo/main/PdfSignature.cpp
index 2f532c2e..e642524d 100644
--- a/src/podofo/main/PdfSignature.cpp
+++ b/src/podofo/main/PdfSignature.cpp
@@ -56,8 +56,7 @@ void PdfSignature::init(PdfAcroForm& acroForm)
void PdfSignature::SetSignerName(nullable<const PdfString&> text)
{
- if (m_ValueObj == nullptr)
- PODOFO_RAISE_ERROR(PdfErrorCode::InvalidHandle);
+ EnsureValueObject();
if (text.has_value())
m_ValueObj->GetDictionary().AddKey("Name", *text);
@@ -67,8 +66,7 @@ void PdfSignature::SetSignerName(nullable<const PdfString&> text)
void PdfSignature::SetSignatureReason(nullable<const PdfString&> text)
{
- if (m_ValueObj == nullptr)
- PODOFO_RAISE_ERROR(PdfErrorCode::InvalidHandle);
+ EnsureValueObject();
if (text.has_value())
m_ValueObj->GetDictionary().AddKey("Reason", *text);
@@ -78,9 +76,7 @@ void PdfSignature::SetSignatureReason(nullable<const PdfString&> text)
void PdfSignature::SetSignatureDate(nullable<const PdfDate&> sigDate)
{
- if (m_ValueObj == nullptr)
- PODOFO_RAISE_ERROR(PdfErrorCode::InvalidHandle);
-
+ EnsureValueObject();
if (sigDate.has_value())
{
@@ -115,8 +111,7 @@ void PdfSignature::PrepareForSigning(const string_view& filter,
void PdfSignature::SetSignatureLocation(nullable<const PdfString&> text)
{
- if (m_ValueObj == nullptr)
- PODOFO_RAISE_ERROR(PdfErrorCode::InvalidHandle);
+ EnsureValueObject();
if (text.has_value())
m_ValueObj->GetDictionary().AddKey("Location", *text);
@@ -126,8 +121,7 @@ void PdfSignature::SetSignatureLocation(nullable<const PdfString&> text)
void PdfSignature::SetSignatureCreator(nullable<const PdfString&> creator)
{
- if (m_ValueObj == nullptr)
- PODOFO_RAISE_ERROR(PdfErrorCode::InvalidHandle);
+ EnsureValueObject();
// TODO: Make it less brutal, preserving /Prop_Build
if (creator.has_value())
@@ -146,8 +140,7 @@ void PdfSignature::SetSignatureCreator(nullable<const PdfString&> creator)
void PdfSignature::AddCertificationReference(PdfCertPermission perm)
{
- if (m_ValueObj == nullptr)
- PODOFO_RAISE_ERROR(PdfErrorCode::InvalidHandle);
+ EnsureValueObject();
m_ValueObj->GetDictionary().RemoveKey("Reference");
diff --git a/tools/podofosign/podofosign.cpp b/tools/podofosign/podofosign.cpp
index 13951218..948e3c56 100644
--- a/tools/podofosign/podofosign.cpp
+++ b/tools/podofosign/podofosign.cpp
@@ -939,7 +939,7 @@ void Main(const cspan<string_view>& args)
MySigner signer(cert, pkey, md_digest);
- FileStreamDevice device(outputfile.empty() ? inputfile : outputfile, FileMode::Open, DeviceAccess::Write);
+ FileStreamDevice device(outputfile.empty() ? inputfile : outputfile, outputfile.empty() ? FileMode::Open : FileMode::Create, DeviceAccess::ReadWrite);
PoDoFo::SignDocument(document, device, signer, *signature);
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users