Live demos

Enable JavaScript to use the live demos.

Your browser is too old for this page. Please use the latest Chrome, Edge, Firefox, or Safari.

Browse the sample list on the left and preview layouts plus sample code on the right. Run a demo to print silently or preview PDF via web-print-pdf and the local client. Install and launch the client first.

Client

If results look wrong, install the latest Web Print Expert client from our site first (older builds may cause layout drift).

Layout

Preview and print follow standard HTML/CSS only—no hidden tricks. What you style is what you get.

94 - Base64 PDF

printPdfByBase64 prints server-encoded PDF payloads without a download URL.

Sample code

// 业务中通常由服务端直接返回 PDF Base64;此处从演示地址拉取并编码
const res = await fetch('https://webprintpdf.com/api/fileCenter/webPrintExpert/fileCenterFileDownload/printTest.pdf');
const bytes = new Uint8Array(await res.arrayBuffer());
let binary = '';
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
const pdfBase64 = btoa(binary);

await webPrintPdf.printPdfByBase64(
  pdfBase64,
  { paperFormat: 'A4' },
  {
    // 实际打印时,须指定当前打印机上支持此尺寸的纸张名称(名称以 getPrinterPapers 返回为准),如果指定的纸张不符合此尺寸,效果是不对的。也可以不传递此参数,而是通过在当前软件打印机这个栏目的操作列,预先设置好 “打印首选纸张” 这个弹窗里的参数达到同样的效果
    paperFormat: 'A4',
    copies: 1,
    sharp: false /* 如果是热敏打印机,开启 sharp 抗锯齿,否则 false 即可 */
  }
);

Result

  • If printing fails or the client cannot connect, see Local print works—production does not? (common on HTTP deployments).
  • The client’s built-in Run examples page has more editable demos; this page complements it.
  • Utility demos (connection, printer list) return JSON only—no print job.
Download client free View npm package