Using transformToFragment, by passing XSLT and XML document, I am able to achieve the PDF For another request, I have XSL FO. Can we use XSL FO and XML document to generate the pdf? Please advice
Using transformToFragment, by passing XSLT and XML document, I am able to achieve the PDF
For another request, I have XSL FO. Can we use XSL FO and XML document to generate the pdf?
Below is the code
var AppModule = function AppModule() {}; AppModule.prototype.transformUBLAndInsertIntoFrame = function (UBL, XSLT) {
let ublStr = b64DecodeUnicode(UBL?.replaceAll("\r\n", ""));
let xsltStylesheet = b64DecodeUnicode(XSLT?.replaceAll("\r\n", ""));
const parser = new DOMParser();
let xmlDoc = parser.parseFromString(ublStr, "text/xml");
let resultDocument = document.implementation.createHTMLDocument("PDF Preview");
let xsltDoc = parser.parseFromString(xsltStylesheet, "application/xml");
console.log("Serialize:" + new XMLSerializer().serializeToString(xsltDoc));
let xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsltDoc);
resultDocument = xsltProcessor.transformToFragment(xmlDoc, resultDocument);
resultDocument = new XMLSerializer().serializeToString(resultDocument)
.replaceAll('&', '&')
.replaceAll('<', '<') .replaceAll('>','>' ) .replaceAll('"','"' ) .replaceAll(''',"'" ); return resultDocument; };
Here is all the Java code you need for transforming XML to PDF, using XSL-FO with the free implementation Apache FOP.