Tab character in itext - java

I have write the code to create the report using itext.For that,i have to add the header
which is like
BSJ Economy Report Date:31/12/10
For that i need to put the tab character(\t) between the above strings.But i can't find out the tab character in itext.I have used "\t" and "\t".This was not working.Please help me to resolve this issue.

There isn't one.
Sounds like a job for a 3-column table. Or perhaps a ColumnText drawing into the same rectangle with three different alignments?
Lots of options.

to put tab caracter. We do like that
p = new Paragraph();
p.setTabSettings(new TabSettings(56f));
p.add(Chunk.TABBING);
p.add(new Chunk("Hello World with tab."));

Related

How to add image next to the title text of an Expandable composite?

I am working on modifying EGit for an use case. The current state looks like the following:
I now want to add an image next to the title text of the unstaged section i.e. next to "Unstaged Changes (0)". Check the following for reference:
I am not looing to add image to the toolbar, but next to the text.
Check the following code for the current unstaged section:
Section unstagedSection;
FormToolkit toolkit = new FormToolkit(parent.getDisplay());
unstagedSection = toolkit.createSection(parent, ExpandableComposite.SHORT_TITLE_BAR);
unstagedSection.setText("Unstaged Changes" + " (0)"); //$NON-NLS-1$
unstagedSection.clientVerticalSpacing = 0;
GridDataFactory.fillDefaults().grab(true, false).applyTo(unstagedSection);
Composite unstagedComposite = toolkit.createComposite(unstagedSection);
toolkit.paintBordersFor(unstagedComposite);
GridLayoutFactory.fillDefaults().applyTo(unstagedComposite);
unstagedSection.setClient(unstagedComposite);
I want to know if it is possible to add the image next to the title text of the Section and how?.
Any kind of help will be appreciated. Thanks.
Edit 1:
I have reached till this point. The only thing I need to know is how to put it right after the text.

JasperReports export to Excel uses only last set background color

Im pretty pretty new to Dynamic-Jasper, but due to work i had to add a new feature to our already implemented solution.
My Problem
The Goal is to add a Column to a report that consists only out of a background-color based on some Information. I managed to do that, but while testing I stumbled upon a Problem. While all my Columns in the html and pdf view had the right color, the Excel one only colored the fields in the last Color.
While debugging i noticed, that the same colored Fields had the same templateId, but while all Views run through mostly the same Code the Excel one showed different behavior and had the same ID in all fields.
My Code where I manipulate the template
for(JRPrintElement elemt : jasperPrint.getPages().get(0).getElements()) {
if(elemt instanceof JRTemplatePrintText) {
JRTemplatePrintText text = (JRTemplatePrintText) elemt;
(...)
if (text.getFullText().startsWith("COLOR_IDENTIFIER")) {
String marker = text.getFullText().substring(text.getFullText().indexOf('#') + 1);
text.setText("ID = " + ((JRTemplatePrintText) elemt).getTemplate().getId());
int rgb = TypeConverter.string2int(Integer.parseInt(marker, 16) + "", 0);
((JRTemplatePrintText) elemt).getTemplate().setBackcolor(new Color(rgb));
}
}
}
The html view
The Excel view
Temporary Conclusion
The same styles uses the same Objects in the background and the JR-Excel export messes something up by assigning the same Object to all the Fields that I manipulated there. If anyone knows of a misstake by me or potential Solutions to change something different to result the same thing please let me know.
Something different I tried earlier, was trying to set the field in an evaluate Method that was called by Jasper. In that method we assign the textvalue of each field. It contained a map with JRFillFields, but unfortunatelly the Map-Implementation denied access to them and just retuned the Value of those. The map was provided by dj and couldn't be switched with a different one.
Edit
We are using JasperReports 6.7.1
I found a Solution, where I replaced each template with a new one that was supposed to look exactly alike. That way every Field has its own ID guaranteed and its not up to chance, how JasperReports handles its Data internaly.
JRTemplateElement custom =
new JRTemplateText(((JRTemplatePrintText) elemt).getTemplate().getOrigin(),
((JRTemplatePrintText) elemt).getTemplate().getDefaultStyleProvider());
custom.setBackcolor(new Color(rgb));
custom.setStyle(((JRTemplatePrintText) elemt).getTemplate().getStyle());
((JRTemplatePrintText) elemt).setTemplate(custom);

Best Vaadin component for a list of String

My issue is I have a simple List of Strings say
List<String> names = List.of("Frank","Joe","Eva");
All I want is display it on the UI. With some simple code like
ListComponent lc = new ListComponent.setItems(names);
I have tried it with Table which seems to work but code behind it is a bit boilerplate for this simple task(7-8 line of code).
I have tried also the Grid component and it works well when I want to bind a POJO to it , but with String.class type its a nightmare.
Grid<String> listGrid= new Grid<>(String.class) ;
listGrid.setItems(names);
it doesnt work because I have to provide getters for the column, which String.class doesnt have for the value. So I did this:
Grid<String> listGrid= new Grid<>(String.class) ;
listGrid.setItems(names);
listGrid.addColumn(String::toString).setCaption("name");
It works! However unspecified columns also appear in the grid, so now I have 3 columns Byte,Empty,name. And I dont know why. Where are these comes from?
What are the requirements for displaying them? Just to get them on the screen? Is Label enough?
for(String name: names) {
mylayout.addComponent(new Label(name))
}
If you need selection, then maybe ListSelect or ComboBox are the go-to’s.
If you want to avoid the additional columns, one way is to do as was pointed out in a comment, i.e. do removeAllColumns() before you go on creating your own columns.
Another approach would be to do new Grid<>() instead of new Grid<>(String.class). The main difference is that the second constructor uses reflection on the provided class and automatically configures columns for anything that looks like regular Java bean properties.
I would highly prefer to use grid.removeColumnByKey rather than removeAllColumns()
You can also use grid.setColumns to specify order of columns.
I will add link to vaadin documentantion for grid with java examples which is realy helpfull. enter link description here
I did something similar to adding the Strings in TextAreas. Because I needed some formatting, I added the text using StringBuilder.
List<String> details = getDetails();
StringBuilder builder = new StringBuilder();
for (String detail : details) {
TextArea ta = new TextArea();
ta.setSizeFull();
ta.setMaxHeight("100px");
ta.setValue(builder.append(detail).toString());
((Span) content).add(ta);
((Span) content).add(new Hr());
}
The result is like this:
Try out this
final Grid<String> grid = new Grid<>();
grid.setItems(new ArrayList<String>());
grid.addColumn(item -> item).setHeader("Value");

Is it possible to add 'Open a web link action' action to acroform field programmatically using iText?

In Adobe Acrobat there is a possibility to add 'Open a web link action' to acroform. Is it possible to do so with iText usind already existing acroform?
I was unable to find any mention about it at iText docs and therefore tried to create new acrofield programmatically and add this action to it, but without success. Here's my code:
PdfReader pdfReader = new PdfReader(templateStream);
PdfStamper stamper = new PdfStamper(pdfReader, new FileOutputStream("delivery.pdf"));
stamper.setFormFlattening(true);
stamper.getAcroFields().setField("package", packages);
stamper.getAcroFields().setField("purchase_id", purchaseId);
stamper.getAcroFields().setField("activation_code", activationCode);
if (partner != "") {
PdfFormField field = PdfFormField.createTextField(stamper.getWriter(), false,
false, 100);
field.setFieldName("partner");
PdfAction action = new PdfAction(partner);
field.setAction(action);
field.setColor(new BaseColor(0,0,255));
PdfAppearance appearance = stamper.getUnderContent(1).
createAppearance(200, 20);
appearance.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED), 12f);
appearance.setColorFill(BaseColor.BLUE);
field.setAppearance(PdfAnnotation.APPEARANCE_DOWN, appearance);
field.setDefaultAppearanceString(appearance);
stamper.getAcroFields().setField("partner", "Click here to show partner's web site");
}
The resulting PDF document is shown without partner field. Please point me to some docs or to mistake at my code.
You are trying to add interactivity to a form. However, you are also throwing away all interactivity by using this line:
stamper.setFormFlattening(true);
You also claim that you are adding an extra field. As far as I can see, that claim is false. You create a field name field (and you create it the hard way; I would expect you to use the TextField class instead). However, I don't see you adding that field anywhere. I miss the following line:
stamper.addAnnotation(field, 1);
Note that this line doesn't make sense:
stamper.getAcroFields().setField("partner", "Click here to show partner's web site");
Why would you create a field first (and possibly add a caption) and then change it immediately afterwards? Why not create the field correctly from the start?
Finally, it seems that you want to create a button that can be clicked by people. Then why are you creating a text field? Wouldn't it make more sense to create a push button?
This is an example of a question to which a machine would respond: Too many errors... Maybe you should consider reading the documentation before trying to fix your code.

Libgdx Table too small, does not fill viewport

I'm trying to use a Table to create a menu with lined-up Buttons and Labels. I'm using the latest nightly builds of libgdx, which changed the Table API (amongst other things).
Here's the code in my Screen constructor:
this.mStage = new Stage();
this.mTable = new Table();
this.mTable.setFillParent(true);
this.mTable.debugTable();
this.mStage.addActor(this.mTable);
// now I add some stuff to the table
// ...
My resize function looks like this:
this.mStage.setViewport(width, height, true);
this.mTable.setFillParent(true);
this.mTable.invalidate();
My render function has the following:
System.out.println("Table size is " +
this.mTable.getWidth() + " by " +
this.mTable.getHeight());
this.mStage.draw();
Table.drawDebug();
Although my console shows the correct size:
Table size is 480.0 by 640.0
the Table size is shrink-wrapped around its children, and does not extend to the correct size of 480x640.
Any ideas?
Answering my own question for the benefit of others. The way I was adding widgets to the table was incorrect:
this.mTable.row();
this.mTable.add(button).fillX();
I needed to call the fillX() method of the row():
this.mTable.row().fillX();
this.mTable.add(button);
Hope this helps someone.
To add to the above answers, it may be helpful to know that you can make these setting defaults for the table like so:
this.mTable.defaults().expandX().fillX();
The settings will apply uniformly to all rows and cells.
Your incorrect version of adding widget to the table can be easily
corrected by expanding a cell first using .expandX() method and then
by filling that cell with a widget by calling fillX().
so your initial code:
this.mTable.row();
this.mTable.add(button).fillX();
should be corrected to the following version:
this.mTable.row();
this.mTable.add(button).expandX().fillX();
these 2 lines can be shorten to one:
this.mTable.add(button).expandX().fillX().row();

Categories