use of com.itextpdf.html2pdf.ConverterProperties in project MessdienerPlanErsteller by Aclrian.
the class FinishController method toPDF.
@FXML
public void toPDF(ActionEvent actionEvent) {
if (LocalOfficeUtils.getDefaultOfficeHome() != null) {
Log.getLogger().info("Converting HTML to PDF with JODConverter");
convert(actionEvent, false);
}
Log.getLogger().info("Converting HTML to PDF with iText");
ConverterProperties converterProperties = new ConverterProperties();
converterProperties.setCharset("UTF-8");
try {
File out = new File(Log.getWorkingDir().getAbsolutePath(), titel + ".pdf");
HtmlConverter.convertToPdf(new ByteArrayInputStream(editor.getHtmlText().replace("<p></p>", "<br>").replace("\u2003", " ").getBytes(StandardCharsets.UTF_8)), new FileOutputStream(out), converterProperties);
pdfgen = out;
if (actionEvent != null) {
Desktop.getDesktop().open(out);
}
} catch (IOException e) {
Dialogs.getDialogs().error(e, "Konnte den Messdienerplan nicht zu PDF konvertieren.");
}
}
use of com.itextpdf.html2pdf.ConverterProperties in project axelor-open-suite by axelor.
the class PrintServiceImpl method generatePDF.
@Override
@Transactional
public Map<String, Object> generatePDF(Print print) throws AxelorException {
try {
print = printRepo.find(print.getId());
String html = generateHtml(print);
ByteArrayOutputStream pdfOutputStream = new ByteArrayOutputStream();
try (PdfDocument pdfDoc = new PdfDocument(new PdfWriter(pdfOutputStream))) {
pdfDoc.setDefaultPageSize(print.getDisplayTypeSelect() == PrintRepository.DISPLAY_TYPE_LANDSCAPE ? PageSize.A4.rotate() : PageSize.A4);
if (print.getPrintPdfFooter() != null && !print.getHidePrintSettings()) {
com.itextpdf.layout.Document doc = new com.itextpdf.layout.Document(pdfDoc);
pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE, new TableFooterEventHandler(doc, print));
}
ConverterProperties converterProperties = new ConverterProperties();
converterProperties.setBaseUri(attachmentPath);
HtmlConverter.convertToPdf(html, pdfDoc, converterProperties);
}
String documentName = (StringUtils.notEmpty(print.getDocumentName()) ? print.getDocumentName() : "") + "-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + FILE_EXTENSION_PDF;
InputStream pdfInputStream = new ByteArrayInputStream(pdfOutputStream.toByteArray());
MetaFile metaFile = metaFiles.upload(pdfInputStream, documentName);
File file = MetaFiles.getPath(metaFile).toFile();
String fileLink = PdfTool.getFileLinkFromPdfFile(PdfTool.printCopiesToFile(file, 1), metaFile.getFileName());
if (ObjectUtils.notEmpty(file) && file.exists() && (print.getAttach() || StringUtils.notEmpty(print.getMetaFileField()))) {
Class<? extends Model> modelClass = (Class<? extends Model>) Class.forName(print.getMetaModel().getFullName());
Model objectModel = JPA.find(modelClass, print.getObjectId());
if (ObjectUtils.notEmpty(objectModel)) {
if (print.getAttach()) {
metaFiles.attach(metaFile, documentName, objectModel);
}
if (StringUtils.notEmpty(print.getMetaFileField())) {
saveMetaFileInModel(modelClass, objectModel, metaFile, print.getMetaFileField());
}
}
}
if (CollectionUtils.isNotEmpty(print.getPrintSet())) {
for (Print subPrint : print.getPrintSet()) {
generatePDF(subPrint);
}
}
return ActionView.define(documentName).add("html", fileLink).map();
} catch (IOException | ClassNotFoundException e) {
throw new AxelorException(e, TraceBackRepository.CATEGORY_INCONSISTENCY);
}
}
use of com.itextpdf.html2pdf.ConverterProperties in project mycore by MyCoRe-Org.
the class MCRXHTML2PDFTransformer method transform.
@Override
public MCRContent transform(MCRContent source) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String s = source.asString();
// required because some data is not normalized
s = Normalizer.normalize(s, Normalizer.Form.NFC);
// required because itext cant handle these
s = s.replace(" ", "");
ConverterProperties converterProperties = new ConverterProperties();
converterProperties.setFontProvider(lazyInitFontProvider());
HtmlConverter.convertToPdf(s, baos, converterProperties);
return new MCRByteContent(baos.toByteArray());
}
use of com.itextpdf.html2pdf.ConverterProperties in project commons by mosip.
the class PDFGeneratorImpl method generate.
/*
* (non-Javadoc)
*
* @see io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#generate(java.io.
* InputStream, java.lang.String)
*/
@Override
public OutputStream generate(InputStream is, String resourceLoc) throws IOException {
isValidInputStream(is);
OutputStream os = new ByteArrayOutputStream();
PdfWriter pdfWriter = new PdfWriter(os);
PdfDocument pdfDoc = new PdfDocument(pdfWriter);
ConverterProperties converterProperties = new ConverterProperties();
pdfDoc.setTagged();
PageSize pageSize = PageSize.A4.rotate();
pdfDoc.setDefaultPageSize(pageSize);
float screenWidth = CssUtils.parseAbsoluteLength("" + pageSize.getWidth());
MediaDeviceDescription mediaDescription = new MediaDeviceDescription(MediaType.SCREEN);
mediaDescription.setWidth(screenWidth);
DefaultFontProvider dfp = new DefaultFontProvider(true, true, false);
converterProperties.setMediaDeviceDescription(mediaDescription);
converterProperties.setFontProvider(dfp);
converterProperties.setBaseUri(resourceLoc);
converterProperties.setCreateAcroForm(true);
try {
HtmlConverter.convertToPdf(is, pdfDoc, converterProperties);
} catch (Exception e) {
throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), e.getMessage());
}
return os;
}
use of com.itextpdf.html2pdf.ConverterProperties in project Rolls-Royce by EntryDSM.
the class ConverterPropertiesCreator method createConverterProperties.
public ConverterProperties createConverterProperties() {
ConverterProperties properties = new ConverterProperties();
FontProvider fontProvider = new DefaultFontProvider(false, false, false);
fonts.forEach(font -> {
try {
FontProgram fontProgram = FontProgramFactory.createFont(fontPath + font);
fontProvider.addFont(fontProgram);
} catch (IOException e) {
e.printStackTrace();
}
});
properties.setFontProvider(fontProvider);
return properties;
}
Aggregations