IText reading PDF like pdftotext -layout?

The problem with your approach inserting spaces like this final Float dist = chunk.distanceFromEndOf(lastChunk)/3; for(int i = 0; i<Math.round(dist); i++) { sb.append(‘ ‘); } is that it assumes that the current position in the StringBuffer exactly corresponds to the end of lastChunk assuming a character width width of 3 user space units. This needs not … Read more

How to continue field output on a second page?

This will only work if you flatten the form. I’ve written a proof of concept where I have a PDF form src that has a field named “body”: public void manipulatePdf(String src, String dest) throws DocumentException, IOException { PdfReader reader = new PdfReader(src); Rectangle pagesize = reader.getPageSize(1); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); Paragraph … Read more

How can I serve a PDF to a browser without storing a file on the server side?

The people who advise you to use response.getOutputStream() instead of creating a FileOutputStream are right. See for instance the Hello Servlet from Chapter 9 of my book: public class Hello extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(“application/pdf”); try { // step 1 Document document = new Document(); // … Read more

HTML to List using XMLWorker

You need to implement the IElementHandler interface in a class of your own: public class SampleHandler : IElementHandler { //Generic list of elements public List<IElement> elements = new List<IElement>(); //Add the supplied item to the list public void Add(IWritable w) { if (w is WritableElement) { elements.AddRange(((WritableElement)w).Elements()); } } } Instead of using the file … Read more

How to enable LTV for a timestamp signature?

This is the sample code this question is about: public void addLtv(String src, String dest, OcspClient ocsp, CrlClient crl, TSAClient tsa) throws IOException, DocumentException, GeneralSecurityException { PdfReader r = new PdfReader(src); FileOutputStream fos = new FileOutputStream(dest); PdfStamper stp = PdfStamper.createSignature(r, fos, ‘\0’, null, true); LtvVerification v = stp.getLtvVerification(); AcroFields fields = stp.getAcroFields(); List<String> names = … Read more