Skip to content

Commit

Permalink
test 2
Browse files Browse the repository at this point in the history
  • Loading branch information
M0Rf30 committed Sep 30, 2024
1 parent 7ccd7fd commit ea61ea7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
5 changes: 3 additions & 2 deletions libs/sign-sdk/include/PdfSignatureGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <podofo/podofo.h>

#include "Util/UUCByteArray.h"
#include "auxiliary/StreamDevice.h"

using namespace PoDoFo;
using namespace std;
Expand Down Expand Up @@ -65,9 +66,9 @@ class PdfSignatureGenerator {

PdfSignature* m_pSignatureField;

// PdfSignOutputDevice* m_pSignOutputDevice;
SpanStreamDevice* m_pSignOutputDevice;

// PdfOutputDevice* m_pFinalOutDevice;
SpanStreamDevice* m_pFinalOutDevice;

char* m_pMainDocbuffer;

Expand Down
33 changes: 25 additions & 8 deletions libs/sign-sdk/src/PdfSignatureGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

#include "PdfSignatureGenerator.h"

#include <cstdio>

#include "PdfVerifier.h"
#include "UUCLogger.h"
#include "auxiliary/StreamDevice.h"

#define SIGNATURE_SIZE 10000

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -147,6 +150,7 @@ void PdfSignatureGenerator::InitSignature(
// m_pSignatureField = new PdfSignatureField(pPage, rect, m_pPdfDocument);
m_pSignatureField = &pPage.CreateField<PdfSignature>(szName, rect);
LOG_DBG((0, "InitSignature", "PdfSignatureField OK"));
printf("help1");

if (szReason && szReason[0]) {
PdfString reason(szReason);
Expand All @@ -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"));

Expand Down Expand Up @@ -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;
Expand All @@ -238,6 +244,9 @@ void PdfSignatureGenerator::InitSignature(
}
}

printf("%d", mainDoclen);

printf("help8\n");
LOG_DBG((0, "InitSignature", "m_pMainDocbuffer %d", fulllen));

// alloca un SignOutputDevice
Expand All @@ -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
Expand All @@ -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"));
}
Expand Down

0 comments on commit ea61ea7

Please sign in to comment.