I am trying to figure out how to allow users to sign a pdf that will be rendered with the PdfRenderer class in Android. Basically it will display a form that will need to be signed and dated and then submitted. I can handle showing the pdf with the PdfRenderer class but I am not seeing a decent way to allow the user to sign and date that rendered pdf and then save the signed pdf to a database. Is there a way to do this without using a third party? And if not is there a free third party product out there?
Well, I really hope there is some solution without the use of any third party library. But, I had a similar requirement of signing the Pdf(ie annotating the pdf in my case) where I used iText . It is licensed as AGPL software
you can add itext to your android project by adding jar or the following to the build.gradle file :-
dependencies {
compile 'com.itextpdf:itextg:5.5.11' //Or the latest variant
}
And the java code would be :-
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("ThisIsYourPdfFile.pdf"));
document.open();
Image img = Image.getInstance("GetTheSignatureInAnImageFormat.png");
document.add(new Paragraph("Sample 1: This is where you can add text stuff say you want to add date"));
document.add(img);
document.close();
See the imports if you are confused
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
Now,coming to your last part of question. Saving them in database. Now your Pdf is just a file. Which is nothing but a bunch of bytes. So you can read the file into byte using nio as below or
From Java7
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
Path pdfPath = Paths.get("/path/to/file.pdf");
byte[] pdf = Files.readAllBytes(pdfPath);
You can do a simple search for converting file to bytes array to save in database. There are alot of ways.
And you can write this to SQLite as Blob object.
Hope this helps.
This is just a rough guess how other applications are doing it as I have not done it myself.
I have not used any of those libs to claim if they work properly or not, but I leave it for you to find out :P.
To get it done You need to have a HTMl developed similar to your PDF then capture signature inside a popup on HTML5 canvas using sketch.js
and that will give you an image which you will render inside the signature box of your HTML and then finally that HTML you will convert to PDF using EVO HTML to PDF Converter
http://www.evopdf.com/?gclid=CMDxuua-odMCFYQYGwodKpsA-w . This is a paid service once you bring the license you can integrate it in a simple way. That is how I did it :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.