Easily use markdown2pdf.ai to convert markdown (.md) to high-quality and impactful PDF in your Typescript-based agentic workflows using our Typescript software development kit (SDK).
node test.ts
) and see a warning like Module type of file is not specified and it doesn’t parse as CommonJS, you can add a "type": "module"
(or "type": "commonjs"
) in your package.json
(or rename your file to .mjs
) to remove the warning.onPaymentRequest
callback (here our pay
function) so that you can handle the payment (for example, by printing the invoice and waiting for manual confirmation). You can also integrate with services like fewsats.com or albyhub for automatic payments.
onPaymentRequest
callback.convertMarkdownToPdf
function.markdown
: The markdown content to convertoptions
: An optional object containing configuration parameters for the conversion processonPaymentRequest
callback so that you can handle the payment. If onPaymentRequest
is omitted and a payment is required, a PaymentRequiredError
is thrown.downloadPath
or returning it as a Buffer
if returnBytes
is true
.
Parameters:
offer
object containing payment details. This parameter is required because the service uses the L402 protocol, which requires a payment to be made before generating the PDF.true
, the method will return the PDF content as a Buffer. If set to false
, it will save the PDF to the specified downloadPath
or return the URL if no path is provided.For example:undefined
or omitted.Condition | Resolves to | Type |
---|---|---|
downloadPath is provided and returnBytes is false | The value of downloadPath | string |
returnBytes is true | The PDF as a Buffer | Buffer |
Neither downloadPath nor returnBytes is provided/true | The final download URL | string |
An error occurs (network, timeout, or payment required and no callback) | Rejects with error | Markdown2PdfError or PaymentRequiredError |
Promise
that resolves or rejects as described above.