MCPcopy Create free account
hub / github.com/PCGen/pcgen / exportPartyToPDF

Method exportPartyToPDF

code/src/java/pcgen/system/BatchExporter.java:323–363  ·  view source on GitHub ↗

Write a PDF party sheet for the characters in the party to the output file. The party sheet will be built according to the template file. If the output file exists it will be overwritten. @param party The already loaded party of characters to be output. @param outFile The file to which the party sh

(PartyFacade party, File outFile, File templateFile)

Source from the content-addressed store, hash-verified

321 * @return true if the export was successful, false if it failed in some way.
322 */
323 public static boolean exportPartyToPDF(PartyFacade party, File outFile, File templateFile)
324 {
325 // We want the non pdf extension here for the intermediate file.
326 String templateExtension = ExportUtilities.getOutputExtension(templateFile.getName(), false);
327 boolean isTransformTemplate =
328 "xslt".equalsIgnoreCase(templateExtension) || "xsl".equalsIgnoreCase(templateExtension);
329
330 boolean useTempFile =
331 PCGenSettings.OPTIONS_CONTEXT.initBoolean(PCGenSettings.OPTION_GENERATE_TEMP_FILE_WITH_PDF, false);
332 String outFileName = FilenameUtils.removeExtension(outFile.getAbsolutePath());
333 File tempFile = new File(outFileName + (isTransformTemplate ? ".xml" : ".fo"));
334 try (BufferedOutputStream fileStream = new BufferedOutputStream(new FileOutputStream(outFile));
335 ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
336 OutputStream exportOutput = useTempFile
337 //Output to both the byte stream and to the temp file.
338 ? new TeeOutputStream(byteOutputStream, new FileOutputStream(tempFile)) : byteOutputStream)
339 {
340 FopTask task;
341 if (isTransformTemplate)
342 {
343 exportParty(party, exportOutput);
344 ByteArrayInputStream inputStream = new ByteArrayInputStream(byteOutputStream.toByteArray());
345 task = FopTask.newFopTask(inputStream, templateFile, fileStream);
346 }
347 else
348 {
349 SettingsHandler.setSelectedPartyPDFOutputSheet(templateFile.getAbsolutePath());
350
351 exportParty(party, templateFile, exportOutput);
352 ByteArrayInputStream inputStream = new ByteArrayInputStream(byteOutputStream.toByteArray());
353 task = FopTask.newFopTask(inputStream, null, fileStream);
354 }
355 task.run();
356 }
357 catch (final IOException | ExportException e)
358 {
359 Logging.errorPrint("BatchExporter.exportPartyToPDF failed", e);
360 return false;
361 }
362 return true;
363 }
364
365 /**
366 * Write a non PDF (e.g. html, text) party sheet for the characters in the

Callers 2

exportPartyMethod · 0.95
doExportEntirePartyMethod · 0.95

Calls 9

getOutputExtensionMethod · 0.95
exportPartyMethod · 0.95
newFopTaskMethod · 0.95
runMethod · 0.95
errorPrintMethod · 0.95
equalsIgnoreCaseMethod · 0.80
initBooleanMethod · 0.80
getNameMethod · 0.65

Tested by

no test coverage detected