PdfReader rdr = new PdfReader( " pdf_file_path") In order to fill the fields programmatically, first we need to include a namespace and then create an object for reading and writing PDF document.Ĭopy Code // PDFReader Class is used to read a PDF file - // there are 12 methods provided by this class to read PDF file // Among those methods, the simplest way is to just give a // file name along with its complete path (as shown below) Editable PDF Forms created through other than Adobe products does not allow user to save data into same PDF file.įew lines of code in Actual Code are quite lengthy hence I put here pseudo code for Filling PDF Form (see source code file for actual code). For demonstrating this, I created a Sample PDF Form Template using Open Office 4.0.1. To fill the PDF Form Template programmatically - the most important thing is that - one should know how many fields are present in that PDF form and their associated internal names, so that appropriate values can filled in it.įrom the C# Port of iText - iTextSharp - The Dictionary variable Fields of class AcroFields gives a list of field names & their associated values present in PDF Form Template. The sample PDF Template contains 5 fields (softwarename, softwaretype, license, category, platforms). The iText PDF Library allows 7 fields to be used programmatically as follows:įrom these 7 fields, this tip represents how to fill the Text Box field programmatically. Before filling a PDF Form, we should be aware of the fields used in the PDF Form so that we can fill the appropriate values in it. I have created a sample PDF Form Template to fill it (see the download section above). The iText PDF Library is free and open source software, & there is a C# port - iTextSharp, used for creating and manipulating PDF documents programmatically. However, I posted this tip to enhance my programming skills and abilities.įor this, I use Microsoft Visual C# 2010 Express as the programming environment and iText PDF Library to fill PDF form programmatically. I know that already lots of articles have been posted by other experts, software developers/programmers which can be easier to adopt for anyone. Signer.signDetached(digest, signature, chain, null, null, null, 0, SUBFILTER) Īs said your coordinates might be outside of the page visible area as not all PDF pages have the bottom left corner at (0, 0).This tip shows the simple way to fill a PDF Form Template programmatically. IExternalSignature signature = new PrivateKeySignature(pk, DigestAlgorithms.SHA256, providerBC.getName()) IExternalDigest digest = new Bounc圜astleDigest() tCertificationLevel(PdfSigner.CERTIFIED_NO_CHANGES_ALLOWED) tFieldName("Banca en Línea - Envío de Documentos") setSignatureCreator("SignerJAGC - iText 7.1.11") PdfSignatureAppearance appearance = signer.getSignatureAppearance() Rectangle rect = new Rectangle(10, 10, 150, 50) PdfSigner signer = new PdfSigner(reader, fos, new StampingProperties()) PrivateKey pk = (PrivateKey) ks.getKey(alias, password) įileOutputStream fos = new FileOutputStream(new File(dest)) String alias = ks.aliases().nextElement() Ĭertificate chain = ks.getCertificateChain(alias) Ks.load(new FileInputStream(keystore), password) KeyStore ks = KeyStore.getInstance("pkcs12")
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |