@@ -292,10 +292,16 @@ public static float getTextSize(String[] lines, int texttype) throws IOException
292292 FontAndSize fontandsize = getFontAndSize (texttype );
293293 float maxwidth = 0f ;
294294 for (int i = 0 ; i < lines .length ; i ++) {
295- float thiswidth = fontandsize .getFont ().getStringWidth (lines [i ]) / (MM_TO_POINT * 1000 )
295+ try {
296+ float thiswidth = fontandsize .getFont ().getStringWidth (lines [i ]) / (MM_TO_POINT * 1000 )
296297 * fontandsize .getFontsize ();
297- if (thiswidth > maxwidth )
298- maxwidth = thiswidth ;
298+ if (thiswidth > maxwidth )
299+ maxwidth = thiswidth ;
300+ } catch (Exception e ) {
301+ String message = "Invalid text for PDF printing '" +lines [i ]+"' originmessage " +e .getMessage ()+"-" +e .getClass ().getName ();
302+ logger .severe (message );
303+ throw new RuntimeException (message );
304+ }
299305 }
300306 return maxwidth ;
301307 }
@@ -1110,6 +1116,8 @@ public static BoxTextContent calculateBoxAndMaybeWriteText(float left, float top
11101116 return calculateBoxAndMaybeWriteText (left , top , right , text , write , false , 0 , page , texttype , false );
11111117 }
11121118
1119+
1120+
11131121 /**
11141122 * @param left left of the printing zone in mm
11151123 * @param top top of the prining zone in mm
@@ -1135,7 +1143,7 @@ public static BoxTextContent calculateBoxAndMaybeWriteText(float left, float top
11351143 throw new RuntimeException ("For write mode, specifying a PDFPage is compulsory" );
11361144 String [] paragraphs ;
11371145 if (text != null ) {
1138- paragraphs = text .split ("\n " );
1146+ paragraphs = text .split ("\\ R " );
11391147 } else {
11401148 paragraphs = new String [0 ];
11411149 }
@@ -1156,15 +1164,17 @@ public static BoxTextContent calculateBoxAndMaybeWriteText(float left, float top
11561164 if (i > 0 )
11571165 currentsplitparagraph = false ;
11581166 String paragraphtext = paragraphs [i ];
1167+ logger .severe ("audit on line " +paragraphtext );
11591168 ArrayList <String > paragraphlines = new ArrayList <String >();
11601169 int lastspace = -1 ;
1170+ // in this version, tab is treated as any other space
1171+ paragraphtext = paragraphtext .replace ('\u00A0' , ' ' ).replace ('\u0009' , ' ' );
11611172 while (paragraphtext .length () > 0 ) {
11621173 int spaceIndex = paragraphtext .indexOf (' ' , lastspace + 1 );
11631174 if (spaceIndex < 0 )
11641175 spaceIndex = paragraphtext .length ();
11651176 String subString = paragraphtext .substring (0 , spaceIndex );
11661177 float sizeinmm = PDFPage .getTextSize (new String [] { subString }, texttype );
1167-
11681178 if (sizeinmm > boxwidthinmm ) {
11691179 if (lastspace < 0 )
11701180 lastspace = spaceIndex ;
0 commit comments