java - Table/Report Format Using PDFBox -


I am formulating issues with the PDF box. My goal is to print the PDF in table style format as a report. Content format will be similar to

  name code description value   

, Retrieve the result set and I have a list of Java objects. I extract the required information and format them as the list of stars in the form below. I create circles through objects, construct a string and add them to an arrayList that I have to implement the formatting in PDF I am making a list of exact same length / style strings. (MyObject obj: dbresults) {// format as below and add to list} StringBuilder sb = new stringbilder ();

Formatter Format = New Formatter (SB); Formatter.format ("% - 25.25s", "It has some text with more than 25 characters."); Formatter.format ("% - 25.25s", "some text with less."); Formatter.format ("% - 25.25s", "some other text."); Println (formatter.toString ());

Output:

  | This is some text with Mo. At least text. | Some other lesson.   

I print this list several times on screen :) And through the System.out format, I hope the format of the logger, even the block too.

However, when I send the PDF box to print to format, it gets 'corrupted' and 'Table format' is not respected. I pass X, Y coordes as 100 and 700.

  Private zero print multiline (PDPageContentStream content stream, list & lt; string & gt; line, float x, float y) throws IOException {if (lines.size () == 0) {Return; } Last integer numberof lines = lines.size (); Last float fonthite = fsfhite (); ContentStream.beginText (); ContentStream.appendRawCommands (fontHyight + "TL \ n"); ContentStream.moveTextPositionByAmount (X, Y); (Int i = 0; i & lt; numofile; i ++) for {contentStream.drawString (lines.get (i)); If (i & lt; numberofline - 1) {contentStream.appendRawCommands ("T * \ n"); }} ContentStream.endText (); }   

You can use this command to get the height of fonts:

  fontHeight = font.getFontDescriptor (). GetFontBoundingBox () GetHeight () / 1000 * fontSize;   

Sample list for printing: When using the Java Formater class while printing on screen it looks like, all look good, but when I print the PDFBox the format is honored Tom Thumso 555-Deed Good 23 Tom Thumbs 666-GGG Good 45 Charles Dickens 777 -Jayge Good 32 Charles Dickens 666-HHH Bad 11th Imt 888-HH OK 12R Valley 444-999 awesome 44

The output of the pdf output Tom Thumb 555-Deed Good 23 Tom Thumbs 666-GGG Good 45 Charles Dickens 777 -Jezze Good 32 Charles Dickens 666-HHH Bad 11 W Immat's 888-HH OK 12R Valley 444 - 999 Awesome 44

Any help much appreciated!

Do you use monospad fonts in PDF (as a courier)? It explains that you get good output in the console and a bad

in PDF

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -