I am trying to combine two or more pdf documents so that the pieces on each document appear on one page in a new pdf.
The pieces on each document contain a form with multiple fields, but the forms only take up a fraction of a page. I know the typical way to merge documents in iText is PdfCopy.addDocument(reader), but I don't want each doucment on it's own page.
Is there a way to copy the fields and/or acroform of each document and put it into a new document where the snippets flow one right after another?
One way I have been thinking about doing this is creating a table with one column in a new document and adding each snippet into a cell, but I haven't been able to get it yet and I don't know if that is even possible.
Or is there a way to make the form a template and copy the template and put it into a cell in a table or on a new document? I don't want the template for the entire page, just the form with the fields.
I also realize that PDF is page-based, but I was hoping there would be a way to combine two pdf pages with form fields onto one page. Also, my fields do not need to be interactive. The forms are already filled out and can be flattened if they need to be.
Related
I got stuck with PDFBox, trying to integrate a table/list in my acroform.
What I have:
I have a PDF-Template with form fields, which I fill with PDFBox in a JSF application. I must have these templates, because users can upload custom templates (they only have to insert form fields with defined names, that the application will fill).
Now I have the problem, that I want to be able to print a list on a defined form field. This template starts e.g. with a header with logo etc. Then in the middle it has a kind of placeholder where the list/table will be printed. After this a kind of footer (e.g. with signature, ...) will be included. All the content after the list/table must move downwoards, to avoid the table be written over the footer content.
My Questions:
(How) Can this be done with PDFBox?
Can the content under the list be moved downwoards, when the table becomes longer?
I have to create a pdf using itext which will contain a button, when clicked should add a row in an existing PdfPTable. I wrote some code to create a PushbuttonField. While trying to set action I can only find PdfAction.javaScript. I am not able to figure out how to add a row in a table. I tried searching online but all I could find is PdfAction.javaScript
Any help would be greatly appreciated. Thank you.
When you create a PDF file, you draw text, lines and shapes to a canvas. That is also what happens when you add a PdfPTable to a Document. If you look at the syntax of the PDF page, you won't recognize a table. You'll find text (the content of the cells), lines (the borders), and shapes (the backgrounds), but you won't find a table. If the table is distributed over different pages, the "table" on one page won't know that it is related to the "table" on the other page.
Sure, you can add semantic structure to the document by introducing marked content, and by creating a structure tree, but that mechanism which we call Tagged PDF can't be used to make the PDF "editable" the same way a Word document is editable. Tagged PDF is (among others) used to allow assistive technology to present the content to the visually impaired (e.g. in the context of PDF/UA). The presence of structure doesn't change the fact that all text, all lines, and all shapes are added at absolute positions.
This is very different from HTML where the position on a page of a <table>, <tr>, <th>, or <td> is calculated at the moment the page is rendered. In HTML this position can even change when you resize the browser window.
There is no such thing in PDF (except if you use XFA (*), a technology that is deprecated since ISO 32000-2). All content on a page has a fixed position, hardcoded into the page's content stream. Changing the size of the PDF viewer window won't change anything to the position of the page content.
Because of all of this, your question is invalid. It is impossible to create a button in PDF that adds a row to a table, because:
In many cases there is no table: there is just a bunch of text, lines, and shapes at absolute positions,
Even if there is the notion of a table (using Tagged PDF): the visual represenation of that table is fixed at creation time, it can't be changed at consumption time.
You want to use an ordinary PDF viewer as if it were a PDF editor. That is impossible for all the reasons listed above.
(*) XFA was deprecated for different reasons. One of the most important reasons it is the lack of support for XFA. There aren't many viewers that support XFA. If you would post a follow-up question asking *"How can I create an XFA document?", the answer would be: "Don't do this!" Creating XFA is extremely complex, and once you've succeeded in creating an XFA form, you'll discover that many of your customers won't be able to consume the file because their viewer doesn't support the format.
Can we create table of content s only by merging with another PDF? The examples I went through in your site have hardcoded string values, but I need to add the titles dynamically.
I don't want to merge the PDF; the PDF I am exporting has other pages like cover page, introduction page, images page etc.. I need to list these as titles in table of contents, the name of the titles varies dynamically. Can you please advise on it?
I've made a form in the PDF document and all works well. However, when the content of the document extends over to the second page, the form fields are applied to the second page instead of the first page where the table is.
If I switch the statement writer.addAnnotation(form) to a line before the content that causes the creation of the second page, then all's fine. However, if I add it to the end of the document, this form is applied on the second page.
Is there any way to overcome this? Is there a method I'm missing that allows me to set the page to which the form is applied?
Additionally, I wish to keep one single form that spans across multiple pages with paragraphs between the fields.
Another method of overcoming this is by adding each field to the document as and when they're created instead of adding the entire form at the end of the document as shown in the examples.
I have to edit an existing pdf file using itext in java. My problem is in the existing pdf it contains lots of pages. When inputting the page number of that existing pdf i have to edit the footer of that page to a new text and have to output only that page with edited footer page along with the page contents in that page. No need to output the remaining pages. Also the existing pdf is in A6 format and I have to change the output pdf to A4 format. How it is possible?
You can split and merge PDF files using iText. That means, you need to split your original document into three parts and keep only the middle (required) part. You can also delete and add objects. That means you can find the footer object, delete it and and add a new object in its place. I do not think you would be able to change the format. Unless, you can create a brand new document in the target format and copy the objects from the source into the new document. Worth trying.