Skip to content

Tichkuly pre-renders invoice PDFs for sharing

Published

On 2026-11-21, the developer of the Tichkuly invoicing app published the browser-side path it uses to turn an invoice into a PDF and send that file through a phone’s share sheet. The Next.js app renders its existing invoice HTML with html2canvas-pro, writes the image into an A4 document with jsPDF, and passes the resulting File to navigator.share(). The implementation prepares and caches the PDF after the invoice settles because a long render performed after the tap can outlive the user activation required by Web Share (Sending an invoice PDF to WhatsApp from a web app, dev.to).

Tichkuly serves small businesses that commonly send invoices through WhatsApp instead of email. Its Send on WhatsApp action sends a PDF file; a link alone would not provide the attachment described by the developer. The product is a Next.js web app that is also wrapped for Android, and the reported generation and sharing path runs in the browser (Sending an invoice PDF to WhatsApp from a web app, dev.to).

A share action that stays inside the activation window

Section titled “A share action that stays inside the activation window”

The important boundary is the call to navigator.share(). MDN documents that share() requires transient activation and must be triggered by a UI event such as a button click. It also returns a promise and can reject with NotAllowedError when transient activation is missing. Rendering a canvas and assembling a PDF are therefore poor fits for the click handler when they delay the share call (Navigator: share() method, developer.mozilla.org).

Tichkuly moves that work earlier. A React effect waits 600 milliseconds after the invoice is enabled, then calls the PDF builder. The source keeps a version string that changes with invoice content, and the builder returns the cached file when that version still matches. The share button consequently receives a prepared File; an edit changes the version and causes a new file to be prepared (Sending an invoice PDF to WhatsApp from a web app, dev.to).

The original report says rendering took from half a second to a couple of seconds on a cheap Android phone and that delaying share() produced NotAllowedError. Those timings apply only to the author’s app and device class. The API defines the actionable requirement. Invoke share() while transient activation is still available (Sending an invoice PDF to WhatsApp from a web app, dev.to; navigator.share() method, developer.mozilla.org).

The invoice already exists as an A4-shaped HTML element measuring 794 by 1123 CSS pixels in the reported implementation. Its PDF helper dynamically imports html2canvas-pro and jsPDF, captures the element at scale 2 on a white background, adds a JPEG to an A4 jsPDF page, and returns pdf.output("blob") inside a File whose MIME type is application/pdf (Sending an invoice PDF to WhatsApp from a web app, dev.to).

The two libraries load only when the app makes a PDF. The helper reads the A4 page width from jsPDF, calculates the image height from the canvas aspect ratio, and places the JPEG at the top-left corner across the page width. It then creates the File with its filename and application/pdf type, so the later capability check receives the same file intended for the system share sheet (Sending an invoice PDF to WhatsApp from a web app, dev.to).

async function renderPdf(element: HTMLElement, filename: string): Promise<File> {
const [{ default: html2canvas }, { jsPDF }] = await Promise.all([
import("html2canvas-pro"),
import("jspdf"),
]);
const canvas = await html2canvas(element, {
scale: 2,
useCORS: true,
backgroundColor: "#ffffff",
});
const pdf = new jsPDF({ unit: "pt", format: "a4", compress: true });
const width = pdf.internal.pageSize.getWidth();
const imageHeight = (canvas.height * width) / canvas.width;
pdf.addImage(
canvas.toDataURL("image/jpeg", 0.5),
"JPEG",
0,
0,
width,
imageHeight,
undefined,
"FAST",
);
return new File([pdf.output("blob")], filename, {
type: "application/pdf",
});
}

The html2canvas configuration reference defines scale as the scale used for rendering, backgroundColor as the canvas background, and useCORS as the switch that attempts to load images from another origin using CORS. Those settings do not make cross-origin images readable by themselves; the remote resource still has to be available under the applicable CORS rules (Configuration options, html2canvas.hertzen.com).

The report chose html2canvas-pro because its Tailwind v4 invoice used oklch() colors and the author found the original library threw on them. It used JPEG quality 0.5 and reported a page around one third of the size produced at 0.92 while keeping text sharp at scale 2. These are project observations, so test the same settings against your own typography, logos, and invoice data before treating them as production defaults (Sending an invoice PDF to WhatsApp from a web app, dev.to).

Canvas capture rasterizes the invoice. Tichkuly accepts that its resulting text cannot be selected or searched for its one-page phone delivery case. The author points readers who need selectable text toward jsPDF’s text API or pdf-lib, and says the app lays longer documents out as separate A4 elements before rendering so a table row is not split between pages (Sending an invoice PDF to WhatsApp from a web app, dev.to).

Keep the render function separate from the click handler. The source schedules make() after the page settles and cancels the timer when the effect is cleaned up. Its enabled guard represents conditions such as unsaved changes, while version invalidates the prepared file when invoice content changes (Sending an invoice PDF to WhatsApp from a web app, dev.to).

useEffect(() => {
if (!enabled) return;
const timer = setTimeout(() => make().catch(() => {}), 600);
return () => clearTimeout(timer);
}, [enabled, version]);

Do not interpret the swallowed preparation error as a complete recovery path. Preserve the error state or attempt a fresh render when the user asks to download, then expose the generated blob through a local download if file sharing is unavailable. Tichkuly’s published share helper calls downloadPdf(file) when navigator.canShare({ files: [file] }) is false, which gives the user a file that can be attached manually (Sending an invoice PDF to WhatsApp from a web app, dev.to).

Checking file sharing before opening the sheet

Section titled “Checking file sharing before opening the sheet”

MDN recommends calling navigator.canShare() before share() when the payload contains files. canShare() returns true when the given data can be shared and false when it cannot, including cases where the data has no recognized properties or file sharing is unsupported. MDN also notes that the Web Share API is available only in secure contexts (navigator.canShare() method, developer.mozilla.org; Web Share API, developer.mozilla.org).

The original report lists WhatsApp, WhatsApp Business, and Gmail among the targets in a phone’s share sheet. Web Share passes the file and message text into that system sheet, where the user chooses a target. When the file-sharing check fails, the report’s desktop fallback saves the PDF for the user to attach manually (Sending an invoice PDF to WhatsApp from a web app, dev.to).

export async function sharePdf(file: File, text: string) {
if (!navigator.canShare?.({ files: [file] })) {
downloadPdf(file);
return false;
}
try {
await navigator.share({ files: [file], title: file.name, text });
} catch (error) {
if ((error as { name?: string }).name !== "AbortError") throw error;
}
return true;
}

The optional call protects browsers that expose no canShare method. Passing the actual PDF File to the check also tests the payload that will be handed to share(), instead of using the existence of navigator.share as a proxy for file support.

Treat AbortError as a user cancellation, as the source helper does. Other rejections need visible recovery because MDN lists several failure conditions, including blocked use under the web-share permissions policy, invalid share data, missing transient activation, and a share operation that fails to start. A download control remains useful after any non-cancellation failure (Navigator: share() method, developer.mozilla.org).

You can verify the fallback without assuming a particular desktop browser. Serve the app over HTTPS, prepare one PDF, and inspect navigator.canShare?.({ files: [file] }). When it is false or absent, activate the same UI control and confirm that a PDF download begins. When it is true, activate the control and confirm that a share sheet opens before selecting or dismissing a target. These observations test the helper’s two branches against the API contract (navigator.canShare() method, developer.mozilla.org; navigator.share() method, developer.mozilla.org).

Tichkuly also uploads a copy under the document’s private share token and includes a link shaped like https://.../i/<token> so the recipient can open it later. The upload begins after the PDF is made, does not block the share, and records the online version so an older upload that finishes later does not replace a newer one. The separate public invoice generator described by the author generates its PDF on the device and does not upload it (Sending an invoice PDF to WhatsApp from a web app, dev.to).

That separation gives the tap one job: hand an existing file and message to Web Share. If upload state is part of your product, keep its version check independent from the prepared local file, and do not make a successful upload a prerequisite for opening the share sheet. This is the ordering reported by the Tichkuly implementation (Sending an invoice PDF to WhatsApp from a web app, dev.to).

  • Capabilities: follow this entry for the capability catalog and its documented interfaces.
  • Performance: follow this entry for performance topics and diagnostic guidance.
  • Storage: follow this entry for browser storage mechanisms and their documented constraints.

Whether the reported 600-millisecond preparation delay is sufficient for invoices with different fonts, image origins, or page counts remains unverified. The maximum PDF size accepted by each installed share target is also unverified. Test preparation time, output readability, CORS-dependent assets, cancellation, and the download branch on the devices and share targets you support before shipping.