added examples
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								examples/oo-empty.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								examples/oo-empty.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								examples/oo-empty_signed.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								examples/oo-empty_signed.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -33,6 +33,7 @@ class PdfSign: public QMainWindow, protected Ui::Pdfsign {
 | 
			
		||||
      if (fileName.isEmpty()) return;
 | 
			
		||||
      _pdf = std::shared_ptr<Poppler::Document>(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<Poppler::Document> _pdf;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user