I have a java spring boot project with several modules.
In one of the modules I have to convert an XML to a PDF using a XLS. In the XLS I want to use an external css and image file.
I am able to convert the XML and I have the PDF as output but with no images and css/styling.
Into this module I provide the XLS as a resource:
@Value(“classpath:archiving/archiving.xsl”)
private Resource archivingXsl;
Then I convert in this way:
String xmlContent = "xml file content";
InputStream targetStream = new ByteArrayInputStream(xmlContent.getBytes());
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(archivingXsl.getInputStream()));
StreamSource xmlSource = new StreamSource(targetStream);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamResult output = new StreamResult(baos);
transformer.transform(xmlSource, output);
HtmlLoadOptions options = new HtmlLoadOptions();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
Document pdfDocument = new Document(bais, options);
pdfDocument.save("data_xml.pdf");
The xsl file includes the css file like the following:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<link rel="stylesheet" type="text/css" href="archiving.css"/>
<html>
<body>
<center>
<img src="logo.jpg"></img>
</center>
<h3 class="blue">title</h3>
<br></br>
Can you please help me to understand how to have the css and image files included in the pdf?
Thank you