iText 7 signature field alignment - vb.net

I'm trying to make a signature field in iText, but the name is not getting aligned with the underline.
Left underline needs to be centralized with left name, and same in other side... And they have to be side by side
How can I do that?
Code:
Paragrafo.Add(New iText.Layout.Element.Paragraph().AddTabStops(New iText.Layout.Element.TabStop(400, TabAlignment.RIGHT)).Add("_____________________________ ").Add(New iText.Layout.Element.Tab()).Add("_____________________________"))
Paragrafo.Add(New iText.Layout.Element.Paragraph().AddTabStops(New iText.Layout.Element.TabStop(400, TabAlignment.RIGHT)).Add("MICHEL SANTOS DO NASCIMENTO").Add(New iText.Layout.Element.Tab()).Add("CLEDOMIR JOSE BERLATTO"))
document.Add(Paragrafo.SetFontSize(12).SetTextAlignment(TextAlignment.LEFT))
Result of code:

There are nicer ways to add the signature lines into your PDF - you can add tab stops and tab leaders instead of adding dashes. Then you can use central alignment for tab stops to make sure your text is aligned as you want.
Example code (it's in Java, but you can easily convert it yo VB.NET similarly to how I converted your VB.NET code into Java):
// Tab stops represent left and right coordinates for two lines
java.util.List<TabStop> tabStopsLines = Arrays.<TabStop>asList(new TabStop(50),
new TabStop(250, TabAlignment.LEFT, new SolidLine()),
new TabStop(300), new TabStop(500, TabAlignment.LEFT, new SolidLine()));
document.add(new Paragraph().addTabStops(tabStopsLines).add(new Tab()).add(new Tab()).add(new Tab()).add(new Tab()));
// Tab stops represent centers of the lines
java.util.List<TabStop> tabStopsText = Arrays.<TabStop>asList(new TabStop(150, TabAlignment.CENTER),
new TabStop(400, TabAlignment.CENTER));
document.add(new Paragraph().addTabStops(tabStopsText).add(new Tab()).add("MICHEL SANTOS DO NASCIMENTO").add(new Tab()).add("CLEDOMIR JOSE BERLATTO"));
Visual result:

Related

Birt export in pdf does not wordwrap long lines

My reports preview is ok.
But now, I need to export to pdf...and I've got an issue : the content of some cells are truncated to the witdh of the column.
For instance, 1 cell should display "BASELINE"...in the preview it's ok...but in pdf, it displays "BASEL".
I've been looking for a solution the whole day and did not find anything...
Of course : I don't want to fit the width of the column on the length of this word "BASELINE" because the content is dynamic...
Instead, I want to fix the column width and then, the cell should display something like that :
BASEL
INE
Any idea ?
Thanks in advance (am a little bit desperated...)
The solution is trivial in BIRT v4.9 if you've integrated the engine into your java code. Just set the PDF rendering options.
RenderOption options = new PDFRenderOption();
options.setOutputStream(out);
options.setOutputFormat("pdf");
options.setOption(PDFRenderOption.PDF_WORDBREAK, true);
options.setOption(PDFRenderOption.PDF_TEXT_WRAPPING, true);
task.setRenderOption(options);
You have to set a special PDF emitter option:
PDFRenderOption options = new PDFRenderOption();
options.setOption(PDFRenderOption.PDF_HYPHENATION, true);
This is if you integrated BIRT into your Java program.
For the viewer servlet, it is possible to set such options, too, AFAIK, but I don't know how; maybe on the URL or using environment variables.
I had the same issue. I found a very good topic about that : http://developer.actuate.com/community/forum/index.php?/topic/19827-how-do-i-use-word-wrap-in-report-design/?s=173b4ad992e47395e2c8b9070c2d3cce
This will split the string in the given number of character you want :
The function to add in a functions.js (for example). To let you know, I create some folder in my report project : one for the reports, one for the template, one for the libraries, another for the resources, I added this js file in the resources folder.
/**
* Format a long String to be smaller and be entirely showed
*
*#param longStr
* the String to split
*#param width
* the character number that the string should be
*
*#returns the string splited
*/
function wrap(longStr,width){
length = longStr.length;
if(length <= width)
return longStr;
return (longStr.substring(0, width) + "\n" + wrap(longStr.substring(width, length), width));
}
You will have to add this js file in the reports : in the properties -> Resources -> Javascript files
This is working for me.
Note: you can add this function in your data directly if you need only once...
The disadvantage of this : you will have to specify a max length for your character, you can have blank spaces in the column if you specify a number to small to fill the column.
But, this is the best way I found. Let me know if you find something else and if it's working.

PDFBox: Fill out a PDF with adding repeatively a one-page template containing a form

Following SO question Java pdfBox: Fill out pdf form, append it to pddocument, and repeat I had trouble appending a cloned page to a new PDF.
Code from this page seemed really interesting, but didn't work for me.
Actually, the answer doesn't work because this is the same PDField you always modify and add to the list. So the next time you call 'getField' with initial name, it won't find it and you get an NPE. I tried with the same pdfbox version used (1.8.12) in the nice github project, but can't understand how he gets this working.
I had the same issue today trying to append a form on pages with different values in it. I was wondering if the solution was not to duplicate field, but can't succeed to do it properly. I always end with a PDF containing same values for each form.
(I provided a link to the template document for Mkl, but now I removed it because it doesn't belong to me)
Edit: Following Mkl's advices, I figured it out what I was missing, but performances are really bad with duplicating every pages. File size isn't satisfying. Maybe there's a way to optimize this, reusing similar parts in the PDF.
Finally I got it working without reloading the template each time. So the resulting file is as I wanted: not too big (4Mb for 164 pages).
I think I did 2 mistakes before: one on page creation, and probably one on field duplication.
So here is the working code, if someone happens to be stuck on the same problem.
Form creation:
PDAcroForm finalForm = new PDAcroForm(finalDoc, new COSDictionary());
finalForm.setDefaultResources(originForm.getDefaultResources())
Page creation:
PDPage clonedPage = templateDocument.getPage(0);
COSDictionary clonedDict = new COSDictionary(clonedPage.getCOSObject());
clonedDict.removeItem(COSName.ANNOTS);
clonedPage = new PDPage(clonedDict);
finalDoc.addPage(clonedPage);
Field duplication: (rename field to become unique and set value)
PDTextField field = (PDTextField) originForm.getField(fieldName);
PDPage page = finalDoc.getPages().get(nPage);
PDTextField clonedField = new PDTextField(finalForm);
List<PDAnnotationWidget> widgetList = new ArrayList<>();
for (PDAnnotationWidget paw : field.getWidgets()) {
PDAnnotationWidget newWidget = new PDAnnotationWidget();
newWidget.getCOSObject().setString(COSName.DA, paw.getCOSObject().getString(COSName.DA));
newWidget.setRectangle(paw.getRectangle());
widgetList.add(newWidget);
}
clonedField.setQ(field.getQ()); // To get text centered
clonedField.setWidgets(widgetList);
clonedField.setValue(value);
clonedField.setPartialName(fieldName + cnt++);
fields.add(clonedField);
page.getAnnotations().addAll(clonedField.getWidgets());
And at the end of the process:
finalDoc.getDocumentCatalog().setAcroForm(finalForm);
finalForm.setFields(fields);
finalForm.flatten();

MPAndroidChart: Multi-line chart with filled area issue

I am now using the MPAndroidChart to draw line chartmy chart
As you can see from the above screenshot, the color specified by me(showed in legend) is not the same as the finally filled in below the chart, is there any way to make sure that the different color will not mixed together?
Below is the code I used to draw two of the lines
LineDataSet vlfDs = new LineDataSet(vlfValues, "VLF");
vlfDs.setMode(LineDataSet.Mode.CUBIC_BEZIER);
vlfDs.setCubicIntensity(0.2f);
vlfDs.setDrawFilled(true);
vlfDs.setDrawCircles(false);
vlfDs.setLineWidth(0);
vlfDs.setCircleRadius(4f);
vlfDs.setColor(Color.YELLOW);
vlfDs.setFillColor(Color.YELLOW);
vlfDs.setFillAlpha(100);
LineDataSet lfDs = new LineDataSet(lfValues, "LF");
lfDs.setCubicIntensity(0.2f);
lfDs.setDrawFilled(true);
lfDs.setDrawCircles(false);
lfDs.setLineWidth(0);
lfDs.setCircleRadius(4f);
lfDs.setCircleColor(Color.WHITE);
lfDs.setColor(Color.GREEN);
lfDs.setFillColor(Color.GREEN);
lfDs.setFillAlpha(100);
hrvLineData = new LineData(hfDs,lfDs,vlfDs, hrDs);
hrvLineData.setValueTextSize(0);
hrvLineData.setDrawValues(false);
hrvChartView.setData(hrvLineData);
hrvChartView.invalidate();
It's turned out that I need to use setFillAlpha(255) instead of setFillAlpha(100)
You can also use something similar to the following solution which overrides the default LineChartRenderer and a uses a custom implementation of IFillFormatter to fill only the areas between the datasets.
Android - Fill the color between two lines using MPAndroidChart

Docx4J: Vertical text frame not exported to PDF

I'm using Docx4J to make an invoice model.
In the left-side of the page, it's usual to show a legal sentence as: Registered company in ... Book ... Page ...
I have inserted this in my template with a Word text frame.
Well, my issue is: when exporting to .docx, this legal text is shown perfect, but when exporting to .pdf, it's shown as an horizontal table under the other data.
The code to export to PDF is:
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setFoDumpFile(foDumpFile);
foSettings.setWmlPackage(template);
fos = new FileOutputStream(new File("/C:/mypath/prueba_OUT.pdf"));
Docx4J.toFO(foSettings, fos, Docx4J.FLAG_EXPORT_PREFER_XSL);
Any help would be very appreciated.
Thanks.
You'd need to extend the PDF via FO code; see further How to correctly position a header image with docx4j?
Float left may or may not be easy; similarly the rotated text.
In general, the way to work on this is to take the FO generated by docx4j, then hand edit it to something which FOP can convert to a PDF you are happy with. If you can do that, then its a matter of modifying docx4j to generate that FO.

Can you insert blank lines in an already transformed PDF?

I have a situation where I need to increase the space between a table and the header on a PDF that has already been transformed from an XSL template.
I need to insert an address in the newly created space. This part is easy enough and I can do that using a stamper and a new table.
However, I am struggling to find a solution to move the grid down to make the space.
Basically I am using FOP to create the PDF from an XSL template using code similar to the following:
OutputStream out = new java.io.FileOutputStream(pdf);
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
driver.setOutputStream(out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xsl));
StringReader xmlStream = new StringReader(xmlData);
Source xmlSource = new StreamSource(xmlStream);
Result res = new SAXResult(driver.getContentHandler());
transformer.transform(xmlSource, res);
Is it even possible to access the PDF in a way to add the new space? If so, what are my options? I should mention that I don’t know at the time the transformation is happening that I will need the extra space. I only know I need it once I get a page count of the PDF.
Any help is greatly appreciated!
It's not possible to add "new space" per se, but it is possible to get the co-ordinates of an object on the page and then re-draw that object somewhere else. Unfortunately there's no quick and easy solution and you will need a third-party SDK to do this.
PDF isn't a word processor format, so it's not possible to simply add a couple of carriage returns, as you might in MS Word.
Try iText, it's written in Java and has a decent amount of functionality for manipulating PDFs.
It seems it is not possible (at least from everything I have tried and read) to move transformed objects around once the PDF has already been generated.
Since I was already using iText and the PdfStamper class I was able to insert a new page and insert a new table with the current address info. I did this with the following code:
//add new page
PdfStamper stamper = new PdfStamper(reader,new FileOutputStream(file);
stamper.insertPage(pageNumber,reader.getPageSizeWithRotation(1));
//add new table with data
BaseFont base = BaseFont.createFont(BaseFont.HELVETICA,"",BaseFont.NOT_EMBEDDED);
over.setFontAndSize(base,fontSize);
PdfPTable table = new PdfPTable(1);
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
table.addCell(data);
table.setTotalWidth(150f);
table.writeSelectedRows(0, -1, 73, 650, over);
This is not the answer to my question by a viable solution I thought I would share in case others get hung up on the same issue.