Closed steren closed 2 months ago
@ccxvii What do you think? Is it possible to expose such an API?
When we update the core to fix the bug with DocumentWriter you can use that API to create an SVG document.
var buf = new mupdf.Buffer()
var wri = new mupdf.DocumentWriter(buf, "svg", "")
var dev = wri.beginPage(page.getBounds())
page.run(dev, [1, 0, 0, 1, 0, 0])
wri.endPage()
wri.close()
// buf now contains SVG data for the page graphics
@steren This should now be available with the latest release of mupdf.js (0.2.1) on NPM - https://www.npmjs.com/package/mupdf , please confirm!
Thanks, I confirm it works, here is my code:
function renderPage(pdf, i) {
const page = pdf.loadPage(i)
const buf = new mupdf.Buffer()
const wri = new mupdf.DocumentWriter(buf, "svg", "")
const dev = wri.beginPage(page.getBounds())
page.run(dev, [1, 0, 0, 1, 0, 0])
wri.endPage()
wri.close()
const svgString = buf.asString();
const svg = new Blob([svgString], { type: "image/svg+xml" });
const img = new Image();
img.src = URL.createObjectURL(svg);
img.onload = function () {
document.getElementById("render").appendChild(img);
}
}
I would recommend:
Page.toSVG()
)
Page.toPixmap()
allows exporting the page to a raster image.I am looking for an API to export as SVG.
I see
mutool draw
has the ability to export assvg
. It also seems that another Wasm port of MuPDF has support for drawing as SVG. So I assume MuPDF has this capability, and it only needs to be exposed as an API in the JS library.