We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert XML to PDF using XSL

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:

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);

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"/>
                    <img src="logo.jpg"></img>
                <h3 class="blue">title</h3>

Can you please help me to understand how to have the css and image files included in the pdf?
Thank you


Could you please share the sample XML and referenced CSS file for our reference so that we can further test the scenario in our environment and address it accordingly?

Thanks for your reply.
Hereby the 3 files:

Let me know if you need something else.

Thanks for your help.


We tested the scenario in our environment. We changed the CSS file path in XSL file to make it complete and tried another way, but did not get success:

Document pdf = new Document();

pdf.bindXml(dataDir + "xmlContent.xml", dataDir + "archiving.xsl");
pdf.Save(dataDir + "SampleOut.pdf");

An issue as PDFJAVA-41151 has been logged in our issue tracking system for the sake of correction. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.