I have a pdf built with LiveCycle Designer, I am easily able to update all TextFields using iText 5.4.3. My issue is how do I update the existing ImageField and access a Table object?
I have obtained the position of the image field and am able to add the image onto the form, then remove the image field.
Rectangle rect = acroFields.getFieldPositions("TopmostSubform[0].Page5[0].processFlowImage[0]")
.get(0).position;
String realPath = FacesContext.getCurrentInstance()
.getExternalContext().getRealPath("/");
Image img = Image.getInstance(realPath + wsSelected.getImage());
// use scalePercent as images are process flow diagrams and image
// ratios are not consistent and making them absolute causes distortion
img.scalePercent((float) 47.0);
img.setAbsolutePosition(rect.getLeft(), rect.getBottom());
stamper.getOverContent(5).addImage(img);
While this works, I would think there would, or should, be the ability to get the image field and populate with an InputStream or file.
Another issue is when working with Pre-defined tables on the form. I can get the field names and update the appropriate cells.
However, I have not been able to find any examples of obtaining the table, as a table object, and adding new rows. I can obtain the location, create a new PdfPTable and stamp it onto the form with the data. This will not work. The table will have a dynamic number of rows, based on db data. It is in a flowable layout, between pre-defined text and headers. The form (template) is pre-built and provided as a template. The form is populated with DB values and some user input from a JSF application, and presented back to the user as a finished interface agreement.
My thought is, if I can't access the table object and it's attributes (rows, columns, cells) I would need to read the form, effectively line by line, create and insert the dynamic tables to the output stream when and where they need to be, then continue reading the form and stamping the end result to a new form.
Related
I have a requirement where I need to generate a PDF document in Java using iText.
The ask is to use a PDF template, and inject the data values in a user designed PDF template to produce the desired output PDF.
The documentation on the iText site is not clear/or I didnt search them completely, so asking for support or article regarding this,
Our use case is to generate a table from a PDF template, where the number of rows is determined by the data (i.e. in here JSON). I should be able to dynamically scale the number of rows in a PDF template based on the data size.
Is this possible?
I was referring to this article:
https://github.com/koendehaen/itext_summit_pdf_templates
In the above GITHUB example, the rows were prepopulated in the PDF template, I want something like the below screenshot, similar to how Handlebars provide, where a for loop on a hbs template, and I can inject data.
Example:
Suppose I have a table like below
But here the row count is dynamic based on data set, how to scale the table dynamically
Note:
I cant create the template in HTML, like handlebars, etc...
Since business people with little to no technical background will be the users who will be generating the PDF template.
You can search the all key values of your JSON, and before insert this value in PdFTable. In my case, i get the lastCellNum:
Row row = rowIterator.next();
PdfPTable table = new PdfPTable(row.getLastCellNum());
Iterator<Cell> cellRow = row.iterator();
while(cellRow.hasNext()) {
Cell cell = cellRow.next();
I am working with BIRT(4.6) and Eclipse mars2(4.5).
I am creating a report using EngineConfig object and creating the report in HTML, PDF and EXCEL formats.
The number of the tables and data inside the table I am filling dynamically.
I am creating the CellHandle for each column in my report and adding the LabelHandle inside it. I was setting the width of a LabelHandle based on the size of the String that I am going to set it and All three reports(PDF, HTML and EXCEL) were displaying properly. But setting the LabelHandle width based string size, is not a good practice and sometimes data is missing in the reports.
So Tried with 'canShrink' property on LabelHandle as shown below.
labelHandleObj.setProperty("canShrink", "True");
The above statement automatically adjust LableHandle width based on the String size and this avoids me to set the LableHandle size manually based string size.
With the canShrink property my HTML report is generating properly with no data loss and No extract space/padding in cell. This is the way I want the report.
But when it comes to PDF and EXCEL, Tables are not displaying properly and all columns are shirked and data is not displaying properly. You can see the PDF Report by clicking the below link.
PDF Report after setting the canShrink property on LableHandle
Can any one kindly suggest me, how to get the data properly in PDF and Excel Report. But I want to use the CanShrink property, because it is creating the proper HTML report.I tried with both True and False value for CanShrink but no use with PDF and EXCEL.
Is there any way to get the three reports properly without using CanShrink.
Thanks in Advance.
When something like this happens you should try copy your table and insert it under original table, then hide original table from PDF using the visibility tab, then hide the copy from everything but PDF. I've done this a lot of times and it really solves the problem, but major disadvantage of this is that if you want to change something you have to do in two tables. Example report:
How can I create a drop list in excel like drop list in html with the inbuilt "value" like attribute?
My Requirement is: I want to show the description which is not stored in database, but the code for description.
Ex: I have a subject list in an excel cell, for Science the description is "Science", but I want to store the code "SCI" in the Database.
You could use an ActiveX ComboBox in a worksheet, available from the Developers tab.
Enter both columns of data into the worksheet - you can hide the columns. Then set properties of the combobox:
ColumnCount 2
BoundColumn 1
ColumnWidths 0 pt; 20 pt
Set the ListFillRange and LinkedCell.
I understand there used to be issues with distributing workbooks containing ActiveX controls. I am not sure if this is still an issue, particularly when used a common (standard) control.
Of course, Excel is not designed to be a front-end to a database, so you'll need to write all the code to keep everything in-sync.
You could use the simpler Form Control/ComboBox. This will only store the index number in a cell - it does not have any events that you can use. You could use a formula based on the linked cell, that stores the description in another cell. When the user (presumably) clicks a button to submit the data, you would retrieve and store the description from this cell.
Hmm I can see many placeholder occurs all around the web related to java poi... but it seems there is no solution for your question. The only way I found to manage this is to set the cell value with my default text - the first value!
I am generating a PDF comprised of multiple tables and I want to know if there is a certain way by which I can get to know if the table size will exceed the PDF page size or not. I am using the information to decide wether I will generate the PDF in portrait or landscape mode. Would it be possible to get this size?
know if the table size will exceed the PDF page size
The table size is determined from your XHTML Table Content (rows, columns, headers, footers, etc), plus your CSS doc(s) (width, height and border properties).
The rendering engine (ITextRenderer) only knows your table size, and whether it will fit within a page after it's applied CSS, as part of the process of converting XHTML to rendered output.
So, if you were to query ITextRenderer for this information, you would need to:
Create an ITextRenderer instance, pass your Document in via renderer.setDocument(), and then apply the CSS via renderer.layout(), causing all of the layout calculations to occur based upon the original page orientation
Query somehow to determine if the table fits on the page
If it doesn't, switch between portrait/landscape. But this means changing to a new CSS, setup for a different page shape:
Pick a new CSS, appropriate for the new page orientation and set it within your document
Create a new ITextRenderer instance, pass your Document in via renderer.setDocument(), and then apply the CSS via renderer.layout(), causing all of the layout calculations to occur based upon the new page orientation.
Create PDF output via renderer.createPDF().
Problems:
This is inefficient and inelegant processing.
This is doing things the wrong way around. Controlling page layout should be part of the design process, and should be reflected in (a) the content generated (XHTML) and (b) the formatting (CSS). If that's done correctly, there should be no need to do render-time magic to reformat the entire page.
At step (2), there's no simple query interface that will simply tell you if your table fits within a page. Instead, you have to query the formatted output blocks, and try to work out for yourself where your table is and whether it fits in a page. E.g.:
BlockBox root = renderer.getRootBox();
List pageList = root.getLayer().getPages()
PageBox page = (PageBox)pageList.get(2);
List childBoxList = page.getChildren();
Box childBox = (Box)childBoxList.get(0);
// etc... until you locate your table
At step (4), ITextRenderer expects your CSS to be linked from within your XHTML document. That means you first need to modify your XHTML source, then you need to resubmit it to ITextRenderer.
Suggested Alternative:
Do a wireframe/sketch design with 2 scenarios - one for portrait & one for landscape
Determine the size of elements/rows/columns under the 2 scenarios
Determine the condition logic under which you would use each scenario, portrait v landscape. E.g. if I the number of rows is X and the number of columns is Y - then use landscape, ...
Now create the two CSS files
Now, when you generate your XHTML, use the condition logic to link to the correct CSS
Im completely new to Java web stuff, but here goes my question:
1) How can I add new controls to a JSF page (webuijsf) in the prerender() function?
2) How can I change the position of elements already added using the visual designer? Also in prerender().
I have a number of input fields + labels to show, coming from a database. So I imagine I read from the database and add the appropriate number of controls during prerender. There's also a grid below these dynamically added controls, which I'd like to move further down at the same time.
Thanks!
You would need to write your own component if you wished to render forms based on database data. You should position your grid using standard html techniques or writing your own custom grid component.