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.
Related
I have a requirement where I need to put signature, name and job title to PDFs. The position of this data to be placed varies from PDF to PDF. For example for a PDF it might be at certain x,y and say page no 5 whilst for other PDF it might be in page no 8.
For now I have done the implementation for a specific PDF type by choosing the page number and the x,y location of the signature.
Is there a way we can add some placeholder or some identifier in the PDF so that in my iText code I can search for that placeholder, gets its x,y and then insert my signature data at that location.
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.
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.
community!
My project is simple: I have a link to a website that has multiple information on different chemical substances and I want to extract some data and put in into pdf. Thing is that I want to keep the formatting of the original HTML (using it's css, of course).
Example of substance: http://www.molbase.com/en/msds_1659-31-0-moldata-2.html#tabs
I used jsoup to read the HTML of the table on the bottom of the page, the MSDS one, containing multiple sections with different information about the substance, but I really don't know how to save the exact HTML format into my pdf file. I have tried with iText too, but it gives me "missing ending tag" error, and if it worked, it would print the full page, not only that msds table.
Here is what I have tried to do, but ain't effective:
Document docu = Jsoup.connect(urlbun).get();
Element tableHeader = docu.select("div[class=\"msds\"]")
.first();
String[] finSyn = tableHeader.text().split(" ");
String moreText =" ";
I tried to split the text that the webpage has under that div ("class = "msds"") but I cannot find a way to split it the good way.
Please, could you please give me a hint on what to do? Even if the formating is not the same, I would like to be able to display the information in the same way, with indentation and such.
Thank you!
You can put the content that you want to convert to PDF inside a CSS ID (such as a DIV) and then use the PDFmyURL API to convert only that section to PDF.
Please refer to this on our website about how to select pieces from a page to convert to PDF
Disclosure: I work for the company that owns this site
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.