From ea61ea799f8f565bfac29d19d2f819240cc33865 Mon Sep 17 00:00:00 2001 From: Gianluca Boiano Date: Sat, 21 Sep 2024 20:19:49 +0200 Subject: [PATCH] test 2 --- libs/sign-sdk/include/PdfSignatureGenerator.h | 5 +-- libs/sign-sdk/src/PdfSignatureGenerator.cpp | 33 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libs/sign-sdk/include/PdfSignatureGenerator.h b/libs/sign-sdk/include/PdfSignatureGenerator.h index 7b9610f..9c0990a 100644 --- a/libs/sign-sdk/include/PdfSignatureGenerator.h +++ b/libs/sign-sdk/include/PdfSignatureGenerator.h @@ -14,6 +14,7 @@ #include #include "Util/UUCByteArray.h" +#include "auxiliary/StreamDevice.h" using namespace PoDoFo; using namespace std; @@ -65,9 +66,9 @@ class PdfSignatureGenerator { PdfSignature* m_pSignatureField; - // PdfSignOutputDevice* m_pSignOutputDevice; + SpanStreamDevice* m_pSignOutputDevice; - // PdfOutputDevice* m_pFinalOutDevice; + SpanStreamDevice* m_pFinalOutDevice; char* m_pMainDocbuffer; diff --git a/libs/sign-sdk/src/PdfSignatureGenerator.cpp b/libs/sign-sdk/src/PdfSignatureGenerator.cpp index 8e42803..7e0dedc 100644 --- a/libs/sign-sdk/src/PdfSignatureGenerator.cpp +++ b/libs/sign-sdk/src/PdfSignatureGenerator.cpp @@ -9,8 +9,11 @@ #include "PdfSignatureGenerator.h" +#include + #include "PdfVerifier.h" #include "UUCLogger.h" +#include "auxiliary/StreamDevice.h" #define SIGNATURE_SIZE 10000 @@ -54,8 +57,8 @@ int PdfSignatureGenerator::Load(const char* pdf, int len) { if (m_pPdfDocument) delete m_pPdfDocument; try { - printf("PDF LENGTH\n"); - printf("%i", len); + printf("\nPDF LENGTH\n"); + printf("%i\n", len); printf("STOP\n"); bufferview bufferView(pdf, len); m_pPdfDocument = new PdfMemDocument(); @@ -147,6 +150,7 @@ void PdfSignatureGenerator::InitSignature( // m_pSignatureField = new PdfSignatureField(pPage, rect, m_pPdfDocument); m_pSignatureField = &pPage.CreateField(szName, rect); LOG_DBG((0, "InitSignature", "PdfSignatureField OK")); + printf("help1"); if (szReason && szReason[0]) { PdfString reason(szReason); @@ -161,9 +165,10 @@ void PdfSignatureGenerator::InitSignature( } LOG_DBG((0, "InitSignature", "szLocation OK")); + printf("help2"); - PdfDate now; - m_pSignatureField->SetSignatureDate(now); + // PdfDate now; + // m_pSignatureField->SetSignatureDate(now); LOG_DBG((0, "InitSignature", "Date OK")); @@ -218,15 +223,16 @@ void PdfSignatureGenerator::InitSignature( ? (strlen(szGraphometricData) + strlen(szVersion) + 100) : 0); + printf("help\n"); int mainDoclen = 0; m_pMainDocbuffer = NULL; while (!m_pMainDocbuffer) { try { LOG_DBG((0, "InitSignature", "fulllen %d", fulllen)); m_pMainDocbuffer = new char[fulllen]; - // PdfOutputDevice pdfOutDevice(m_pMainDocbuffer, fulllen); - // m_pPdfDocument->Write(&pdfOutDevice); - // mainDoclen = pdfOutDevice.GetLength(); + auto pdfOutDevice = new SpanStreamDevice(m_pMainDocbuffer, fulllen); + m_pPdfDocument->Save(*pdfOutDevice); + mainDoclen = pdfOutDevice->GetLength(); } catch (const ::PoDoFo::PdfError& err) { if (m_pMainDocbuffer) { delete m_pMainDocbuffer; @@ -238,6 +244,9 @@ void PdfSignatureGenerator::InitSignature( } } + printf("%d", mainDoclen); + + printf("help8\n"); LOG_DBG((0, "InitSignature", "m_pMainDocbuffer %d", fulllen)); // alloca un SignOutputDevice @@ -246,8 +255,15 @@ void PdfSignatureGenerator::InitSignature( LOG_DBG((0, "InitSignature", "m_pSignDocbuffer %d", fulllen)); // m_pFinalOutDevice = new PdfOutputDevice(m_pSignDocbuffer, fulllen); + m_pFinalOutDevice = new SpanStreamDevice(m_pSignDocbuffer, fulllen); + // m_pSignOutputDevice = new PdfSignOutputDevice(m_pFinalOutDevice); + PoDoFo::SignDocument(m_pPdfDocument, m_pFinalOutDevice, signer, + m_pSignatureField); + + printf("help9\n"); + LOG_DBG((0, "InitSignature", "buffers OK %d", fulllen)); // imposta la firma @@ -256,11 +272,12 @@ void PdfSignatureGenerator::InitSignature( LOG_DBG((0, "InitSignature", "SetSignatureSize OK %d", SIGNATURE_SIZE)); // Scrive il documento reale - // m_pSignOutputDevice->Write(m_pMainDocbuffer, mainDoclen); + m_pSignOutputDevice->Write(m_pMainDocbuffer, mainDoclen); LOG_DBG((0, "InitSignature", "Write OK %d", mainDoclen)); // m_pSignOutputDevice->AdjustByteRange(); + printf("help10\n"); LOG_DBG((0, "InitSignature", "AdjustByteRange OK")); }