diff --git a/examples/oo-empty.pdf b/examples/oo-empty.pdf new file mode 100644 index 0000000..f5b4827 Binary files /dev/null and b/examples/oo-empty.pdf differ diff --git a/examples/oo-empty_signed.pdf b/examples/oo-empty_signed.pdf new file mode 100644 index 0000000..35c10eb Binary files /dev/null and b/examples/oo-empty_signed.pdf differ diff --git a/src/pdfsign.hxx b/src/pdfsign.hxx index 6e3c64e..6d5686b 100644 --- a/src/pdfsign.hxx +++ b/src/pdfsign.hxx @@ -33,6 +33,7 @@ class PdfSign: public QMainWindow, protected Ui::Pdfsign { if (fileName.isEmpty()) return; _pdf = std::shared_ptr(Poppler::Document::load(fileName)); showPage(); + } public: void showPage(int pageNumber=0) { @@ -42,6 +43,47 @@ class PdfSign: public QMainWindow, protected Ui::Pdfsign { _pdfDisplay->setPixmap(QPixmap::fromImage(pdfPage->renderToImage())); return; } + void sign(QString filename) { + PdfSigIncMemDocument doc(filename.c_str()); + char *buffer = NULL; + buffer = (char *)malloc(809600); + PdfOutputDevice output(buffer, 809600); + PdfSignOutputDevice signOutput(&output); + signOutput.SetSignatureSize(2048); + printf( "Page count:%d\n", doc.GetPageCount()); + + PdfSigIncSignatureField *sign = doc.GetSignatureField(); + sign->SetSignatureDate(PdfDate()); + sign->SetSignatureReason(L"I dont agree"); + //sign->SetSignatureImage("e:\\sign.jpg", 0, 100, 200, 100, 100); + sign->SetSignatureText(L"Hello World", 0, 100, 200, 100, 100, 12); + doc.Initialize(); + doc.CreateVisualSign(); + doc.Write(&signOutput); + printf( "Has Signature:%d\n", signOutput.HasSignaturePosition()); + /* + char buff[809600] = {0}; + size_t len; + BYTE *Signature = NULL; + DWORD cbSignature = 0; + + signOutput.AdjustByteRange(); + signOutput.Seek(0); + len = signOutput.ReadForSignature(buff, 809600); + printf("total tbs size: %d\n", len); + SignMessage( (BYTE *)buff, len, &Signature, &cbSignature);//Digital signing using MSCAPI + printf("signature size: %d\n", cbSignature); + const PoDoFo::PdfData *sig = new PoDoFo::PdfData((char *)Signature, cbSignature); + signOutput.SetSignature(*sig); + */ + signOutput.Flush(); + + FILE *fp = NULL; + fp = fopen("/tmp/signed.pdf", "wb" ); + fwrite( buffer, signOutput.GetLength(), 1, fp ); + fclose(fp); + free(buffer); + } private: std::shared_ptr _pdf; };