Skip to content

k.utils.converter

Call Kooboo conversion services (HTML/PDF, Office, GIF, etc.)

Overview

k.utils.converter processes documents through the Kooboo cloud conversion service, which relies on the UrlSetting.Converter service being available.

htmlToPdf()

Convert HTML to PDF byte array; optional appendTexts header and footer configuration.

ParameterTypeRequiredDescription
htmlcodestringYesHTML string to convert
appendTextsAppendText[]NoHeader, footer, or other appended text configuration

Returns: number[], PDF file bytes.

ts
const pdf = k.utils.converter.htmlToPdf("<div>Hello</div>")
k.file.writeBinary("out/report.pdf", pdf)

gifToWebp()

GIF to WebP, parameter is GIF byte array.

ParameterTypeRequiredDescription
gifnumber[]YesGIF image bytes

Returns: number[], WebP image bytes.

ts
const gif = k.file.readBinary("media/banner.gif")
const webp = k.utils.converter.gifToWebp(gif)

k.file.writeBinary("media/banner.webp", webp)
return k.file.get("media/banner.webp")

officeToHTML()

Upload Office file bytes and return HTML string; associated resources will be synchronized into the site database.

ParameterTypeRequiredDescription
officebytesnumber[]YesOffice file bytes
filenamestringYesOriginal file name, including extension

Returns: string, converted HTML.

ts
const html = k.utils.converter.officeToHTML(file.bytes, file.fileName)

officeToCleanHTML()

Similar to officeToHTML, outputs sanitized HTML (specific rules are subject to runtime).

ParameterTypeRequiredDescription
officebytesnumber[]YesOffice file bytes
filenamestringYesOriginal file name, including extension

Returns: string, converted and cleaned HTML.

ts
const file = k.request.files[0]
const cleanHtml = k.utils.converter.officeToCleanHTML(file.bytes, file.fileName)

k.file.write("imports/imported-document.html", cleanHtml)