@@ -1188,48 +1188,73 @@ private void setTablesWidths(fontConfig fontcfg, XSLTconverter xsltConverter, Fi
1188
1188
debugSaveXML (xmlTablesOnly , pdf .getAbsolutePath () + ".tablesonly.xml" );
1189
1189
1190
1190
SourceXMLDocument sourceXMLDocumentTablesOnly = new SourceXMLDocument (xmlTablesOnly );
1191
- List <String > tablesIds = sourceXMLDocumentTablesOnly .readElementsIds ("//*[local-name() = 'table' or local-name() = 'dl']" );
1192
-
1193
- List <String > xmlTablesIF = new ArrayList <>();
1194
- // process each table separatery for memory consumption optimization
1195
- for (String tableId : tablesIds ) {
1196
-
1197
- logger .info ("[INFO] Generation of XSL-FO with information about the table widths with id " + tableId + " ..." );
1198
-
1199
- // process table with id=tableId only
1200
- xsltConverter .setParam ("table_only_with_id" , tableId );
1201
1191
1192
+ int countTableCells = sourceXMLDocumentTablesOnly .getCountTableCells ();
1193
+ if (countTableCells < 30000 ) {
1202
1194
// transform XML to XSL-FO (XML .fo file)
1203
1195
xsltConverter .transform (sourceXMLDocumentTablesOnly , false );
1204
1196
1205
1197
String xmlFO = sourceXMLDocumentTablesOnly .getXMLFO ();
1206
1198
1207
1199
//debug
1208
- debugSaveXML (xmlFO , pdf .getAbsolutePath () + "." + tableId + ". fo.tables.xml" );
1200
+ debugSaveXML (xmlFO , pdf .getAbsolutePath () + ".fo.tables.xml" );
1209
1201
1210
- fontcfg .outputFontManifestLog (Paths .get (pdf .getAbsolutePath () + "." + tableId + ". tables.fontmanifest.log.txt" ));
1202
+ fontcfg .outputFontManifestLog (Paths .get (pdf .getAbsolutePath () + ".tables.fontmanifest.log.txt" ));
1211
1203
1212
1204
fontcfg .setSourceDocumentFontList (sourceXMLDocumentTablesOnly .getDocumentFonts ());
1213
1205
1214
1206
Source sourceFO = new StreamSource (new StringReader (xmlFO ));
1215
1207
1216
- logger .info ("[INFO] Generation of Intermediate Format with information about the table's widths with id " + tableId + " ..." );
1217
- String xmlIF = generateFOPIntermediateFormat (sourceFO , fontcfg .getConfig (), pdf , true , "." + tableId + ". tables" );
1208
+ logger .info ("[INFO] Generation of Intermediate Format with information about the table's widths ..." );
1209
+ String xmlIF = generateFOPIntermediateFormat (sourceFO , fontcfg .getConfig (), pdf , true , ".tables" );
1218
1210
1219
1211
xmlTableIF = createTableIF (xmlIF );
1220
1212
1221
- debugSaveXML ( xmlTableIF , pdf . getAbsolutePath () + "." + tableId + ". tables.xml" );
1213
+ } else { // for large tables, or large number of tables
1222
1214
1223
- xmlTableIF = tableWidthsCleanup ( xmlTableIF );
1215
+ List < String > tablesIds = sourceXMLDocumentTablesOnly . readElementsIds ( "//*[local-name() = 'table' or local-name() = 'dl']" );
1224
1216
1225
- xmlTablesIF .add (xmlTableIF );
1226
- }
1217
+ List <String > xmlTablesIF = new ArrayList <>();
1218
+ // process each table separatery for memory consumption optimization
1219
+ int tableCounter = 0 ;
1220
+ int tableCount = tablesIds .size ();
1221
+ for (String tableId : tablesIds ) {
1222
+ tableCounter ++;
1223
+ logger .info ("[INFO] Generation of XSL-FO (" + tableCounter + "/" + tableCount + ") with information about the table widths with id='" + tableId + "'..." );
1227
1224
1225
+ // process table with id=tableId only
1226
+ xsltConverter .setParam ("table_only_with_id" , tableId );
1228
1227
1229
- xmlTableIF = tablesWidthsUnion (xmlTablesIF );
1230
- debugSaveXML (xmlTableIF , pdf .getAbsolutePath () + ".tables.xml" );
1228
+ // transform XML to XSL-FO (XML .fo file)
1229
+ xsltConverter .transform (sourceXMLDocumentTablesOnly , false );
1230
+
1231
+ String xmlFO = sourceXMLDocumentTablesOnly .getXMLFO ();
1232
+
1233
+ //debug
1234
+ debugSaveXML (xmlFO , pdf .getAbsolutePath () + "." + tableId + ".fo.tables.xml" );
1235
+
1236
+ fontcfg .outputFontManifestLog (Paths .get (pdf .getAbsolutePath () + "." + tableId + ".tables.fontmanifest.log.txt" ));
1237
+
1238
+ fontcfg .setSourceDocumentFontList (sourceXMLDocumentTablesOnly .getDocumentFonts ());
1231
1239
1232
- xsltConverter .setParam ("table_only_with_id" , "" ); // further process all tables
1240
+ Source sourceFO = new StreamSource (new StringReader (xmlFO ));
1241
+
1242
+ logger .info ("[INFO] Generation of Intermediate Format (" + tableCounter + "/" + tableCount + ") with information about the table's widths with id='" + tableId + "'..." );
1243
+ String xmlIF = generateFOPIntermediateFormat (sourceFO , fontcfg .getConfig (), pdf , true , "." + tableId + ".tables" );
1244
+
1245
+ xmlTableIF = createTableIF (xmlIF );
1246
+
1247
+ debugSaveXML (xmlTableIF , pdf .getAbsolutePath () + "." + tableId + ".tables.xml" );
1248
+
1249
+ xmlTableIF = tableWidthsCleanup (xmlTableIF );
1250
+
1251
+ xmlTablesIF .add (xmlTableIF );
1252
+ }
1253
+ xmlTableIF = tablesWidthsUnion (xmlTablesIF );
1254
+ xsltConverter .setParam ("table_only_with_id" , "" ); // further process all tables
1255
+ }
1256
+
1257
+ debugSaveXML (xmlTableIF , pdf .getAbsolutePath () + ".tables.xml" );
1233
1258
1234
1259
xsltConverter .setParam ("table_if" , "false" );
1235
1260
logger .info ("[INFO] Generated successfully!" );
0 commit comments