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.
Related
I have a requirement to add few lines at the top of an existing PDF.
I have done this using a PdfReader and a PdfStamper.
In order to have more space in the page header area, i need to move down the current contents by 1 or 2 lines.
Below is from the forum. but it doesn't solve the issue.
How to insert content in the middle of a page in a PDF using IText
Any suggestions?
-i can not upload the pdf or the image of the pdf because am a new user
Do I interpret your question correctly if I assume that you really want to move down everything on the page and add some lines above?
You can do that by changing the media box (and crop box and what other boxes might be explicitly defined for your page) and then add the few lines on top the same way you already do it now.
You can access those boxes in the respective page dictionary which you can retrieve via the PdfReader. Look up the PDF specification for details on those boxes.
Or do I interpret you incorrectly and you only want to move down some text while keeping existing headers and footers in place? In that case Alexis' answer to the other question you refer to still holds.
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 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.
How can I add text to a pdf document, which is not visible?
The document manipulation should be done in java. The usecase is to add further metadata to a document (in a proprietary format, about 40kb), before the document is signed and archived.
I tried:
annotation field with size 0,0
.txt file attachment
but, this annoys readers of the PDF, because they see a difference (comment / attachment bar).
Is there a comment object or a syntax to comment out lines in a PDF document?
EDIT:
I've tried adding text between PDF objects. This works, the problem is: acrobat reader asks to resave the file when closing window.
Adding the text after %EOF is not a solution, because signing is not applied to the metadata, which is a needed feature.
The proper way to add metadata to a PDF would be through XMP. It allows you to add arbitrary metadata and allows defining the metadata types inside of the same PDF file (which you really should do if you're archiving and which is a requirement in archival standards such as PDF/A).
XMP data can be extracted by readers who don't understand the PDF format using a simple text scanning algorithm yet at the same time it will be inside of the document so will be protected by the digital signature you apply.
You can read more about it here: http://www.adobe.com/products/xmp/
I have seen PDF's who had a bunch of metadata in the footer, just in color white while the background was also white, so normally you wouldn't recognize it when you're looking at the PDF. But that's quite nasty..
I have a requirement to convert a PDF from HTML using itext lib in java.
My input HTML page has a tabular structure and it has separate header and footer. I've converted this page to PDF , however as my HTML page has a footer associated with it, I'm trying to relocate footer of my generated PDF to location where actual data of a particular page ends(i.e if a page contains only 10 lines of data from header then I'm trying to add footer after 10th line). PDFEventHelper class helped me to add header and footer,but I'm getting struck with this relocation requirement.
Can anybody tell me how to deal with such scenarios??
does anyone knows how to read blank(unwritten) sectors on PDF page ??
Thanks in advance.
The Document passed into your onEndPage override is actually a PdfDocument.
Once you've cast the parameter to a PdfDocument, you can call PdfDocument.getVerticalPosition(true) to determine where the last Element was laid out and draw your footer accordingly. Note that this only gives the Y position, but that's all you really need for a footer.
The parameter passed to getVerticalPosition is called "ensureNewLine". I strongly suspect what you pass won't matter because this is the End Page Event, and any trailing lines will have already been written/finished/closed/whatever-its-called.