[{"data":1,"prerenderedAt":1101},["Reactive",2],{"/guides/batch-pdf-generation-webhooks":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"dateModified":11,"author":12,"faq":13,"body":26,"_type":1096,"_id":1097,"_source":1098,"_file":1099,"_extension":1100},"/guides/batch-pdf-generation-webhooks","guides",false,"","Batch PDF Generation API: Webhooks and Async Calls","We sent 40 invoices to PDFShift 10 at a time with webhooks: every PDF back in 6.3 s, against 108.8 s one at a time. Code to queue, match and receive them.","2026-11-30","2026-12-01","Cyril Nicodème",[14,17,20,23],{"question":15,"answer":16},"Does PDFShift have a batch endpoint?","Not a separate one. A batch is one request per document, and each request with a webhook is queued and handled on its own. On accounts with parallel conversions enabled, source can also be an array of documents.",{"question":18,"answer":19},"Can I use webhooks on the free plan?","Yes. Webhooks need an API key, and the free plan gives you one with 50 credits a month, no card.",{"question":21,"answer":22},"Can I get PNG, JPEG or WebP images in a batch the same way?","Yes. The /v3/convert/png, /jpeg and /webp endpoints take the same parameters as /v3/convert/pdf, webhook included.",{"question":24,"answer":25},"Can the PDFs go straight to my own S3 bucket?","Yes. Allow PDFShift to write to the bucket in its policy, then add s3_destination with a path like s3://your-bucket/invoices/INV-1000.pdf. With is_hipaa set to true, a webhook request needs s3_destination.",{"type":27,"children":28,"toc":1085},"root",[29,37,44,58,102,114,127,167,173,178,193,195,298,311,316,321,327,340,364,375,394,405,418,423,442,448,481,494,500,505,530,559,578,584,604,763,768,815,835,844,873,879,905,914,934,940,947,960,967,971,978,1013,1020,1072],{"type":30,"tag":31,"props":32,"children":33},"element","p",{},[34],{"type":35,"value":36},"text","For a batch, call PDFShift asynchronously: add a webhook URL to each request, the call answers \"queued\" at once, and PDFShift posts a link to each finished PDF to your server. In our test, 40 invoices sent 10 at a time with webhooks were all back in 6.3 seconds. Sending them one by one and waiting for each took 108.8 seconds.",{"type":30,"tag":38,"props":39,"children":41},"h2",{"id":40},"how-does-async-pdf-generation-with-a-webhook-callback-work",[42],{"type":35,"value":43},"How does async PDF generation with a webhook callback work?",{"type":30,"tag":31,"props":45,"children":46},{},[47,49,56],{"type":35,"value":48},"You send the same request you'd send for one PDF, plus a ",{"type":30,"tag":50,"props":51,"children":53},"code",{"className":52},[],[54],{"type":35,"value":55},"webhook",{"type":35,"value":57}," parameter. Three things happen:",{"type":30,"tag":59,"props":60,"children":61},"ol",{},[62,84,89],{"type":30,"tag":63,"props":64,"children":65},"li",{},[66,68,74,76,82],{"type":35,"value":67},"PDFShift answers ",{"type":30,"tag":50,"props":69,"children":71},{"className":70},[],[72],{"type":35,"value":73},"202",{"type":35,"value":75}," with ",{"type":30,"tag":50,"props":77,"children":79},{"className":78},[],[80],{"type":35,"value":81},"{\"success\": true, \"queued\": true}",{"type":35,"value":83},". In our test that took about half a second.",{"type":30,"tag":63,"props":85,"children":86},{},[87],{"type":35,"value":88},"PDFShift renders the page in Chromium, the same as a normal call.",{"type":30,"tag":63,"props":90,"children":91},{},[92,94,100],{"type":35,"value":93},"PDFShift sends a ",{"type":30,"tag":50,"props":95,"children":97},{"className":96},[],[98],{"type":35,"value":99},"POST",{"type":35,"value":101}," to your webhook URL with a JSON body like this one, from our test:",{"type":30,"tag":103,"props":104,"children":109},"pre",{"className":105,"code":107,"language":108,"meta":7},[106],"language-json","{\n  \"success\": true,\n  \"url\": \"https://pdfshift.s3.amazonaws.com/d/2/2026-11/a9d36db7f02846bead80bb3a69a78d1c/a19c3826-b61c-4f50-be1f-8fe992bb7e6c.pdf\",\n  \"filesize\": 20120,\n  \"duration\": 2043,\n  \"response\": { \"status-code\": 200, \"content-length\": 0, \"requests\": 0, \"duration\": 1992.71 },\n  \"executed\": \"2026-11-30T20:11:36.250014+00:00\",\n  \"pdf_pages\": 1\n}\n","json",[110],{"type":30,"tag":50,"props":111,"children":112},{"__ignoreMap":7},[113],{"type":35,"value":107},{"type":30,"tag":31,"props":115,"children":116},{},[117,119,125],{"type":35,"value":118},"The ",{"type":30,"tag":50,"props":120,"children":122},{"className":121},[],[123],{"type":35,"value":124},"url",{"type":35,"value":126}," points to the PDF on Amazon S3 in Paris, kept for 2 days and then deleted, so download it when the webhook arrives.",{"type":30,"tag":31,"props":128,"children":129},{},[130,135,137,142,144,150,151,157,159,165],{"type":30,"tag":50,"props":131,"children":133},{"className":132},[],[134],{"type":35,"value":55},{"type":35,"value":136}," takes either a URL string or an object with ",{"type":30,"tag":50,"props":138,"children":140},{"className":139},[],[141],{"type":35,"value":124},{"type":35,"value":143},", ",{"type":30,"tag":50,"props":145,"children":147},{"className":146},[],[148],{"type":35,"value":149},"method",{"type":35,"value":143},{"type":30,"tag":50,"props":152,"children":154},{"className":153},[],[155],{"type":35,"value":156},"auth",{"type":35,"value":158}," and ",{"type":30,"tag":50,"props":160,"children":162},{"className":161},[],[163],{"type":35,"value":164},"headers",{"type":35,"value":166},". For a batch, use the object.",{"type":30,"tag":38,"props":168,"children":170},{"id":169},"how-long-does-batch-pdf-generation-take-with-webhooks",[171],{"type":35,"value":172},"How long does batch PDF generation take with webhooks?",{"type":30,"tag":31,"props":174,"children":175},{},[176],{"type":35,"value":177},"We made 40 one-page invoices (a 30-row table, about 20 KB each as a PDF) and sent them to PDFShift three ways on November 30, 2026, from one machine:",{"type":30,"tag":179,"props":180,"children":182},"guide-figure",{"caption":181},"Invoice INV-1007, one of the 40, as the PDF PDFShift posted to our webhook. Our test, November 30, 2026.",[183],{"type":30,"tag":184,"props":185,"children":192},"img",{"src":186,"width":187,"height":188,"alt":189,"loading":190,"style":191},"/images/guides/batch-pdf-generation-webhooks-invoice.webp",720,1019,"Page 1 of invoice INV-1007: the title Invoice INV-1007, the line Bill to: Customer 7, a table of 30 rows of consulting hours with a quantity and a price on each row, and the line Total due in 30 days.","lazy","display:block;max-width:360px;width:100%;height:auto;margin:0 auto;border:1px solid #DBE4F2;border-radius:8px",[],{"type":35,"value":194},"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",{"type":30,"tag":196,"props":197,"children":198},"table",{},[199,223],{"type":30,"tag":200,"props":201,"children":202},"thead",{},[203],{"type":30,"tag":204,"props":205,"children":206},"tr",{},[207,213,218],{"type":30,"tag":208,"props":209,"children":210},"th",{},[211],{"type":35,"value":212},"How we sent 40 invoices",{"type":30,"tag":208,"props":214,"children":215},{},[216],{"type":35,"value":217},"All 40 PDFs back after",{"type":30,"tag":208,"props":219,"children":220},{},[221],{"type":35,"value":222},"Per call (median)",{"type":30,"tag":224,"props":225,"children":226},"tbody",{},[227,263,281],{"type":30,"tag":204,"props":228,"children":229},{},[230,240,248],{"type":30,"tag":231,"props":232,"children":233},"td",{},[234],{"type":30,"tag":235,"props":236,"children":237},"strong",{},[238],{"type":35,"value":239},"10 at a time, each with a webhook",{"type":30,"tag":231,"props":241,"children":242},{},[243],{"type":30,"tag":235,"props":244,"children":245},{},[246],{"type":35,"value":247},"6.3 s",{"type":30,"tag":231,"props":249,"children":250},{},[251],{"type":30,"tag":235,"props":252,"children":253},{},[254,256,261],{"type":35,"value":255},"0.48 s to get ",{"type":30,"tag":50,"props":257,"children":259},{"className":258},[],[260],{"type":35,"value":73},{"type":35,"value":262},"; 2.8 s from call to webhook",{"type":30,"tag":204,"props":264,"children":265},{},[266,271,276],{"type":30,"tag":231,"props":267,"children":268},{},[269],{"type":35,"value":270},"10 at a time, waiting for each PDF",{"type":30,"tag":231,"props":272,"children":273},{},[274],{"type":35,"value":275},"10.9 s",{"type":30,"tag":231,"props":277,"children":278},{},[279],{"type":35,"value":280},"2.69 s",{"type":30,"tag":204,"props":282,"children":283},{},[284,289,294],{"type":30,"tag":231,"props":285,"children":286},{},[287],{"type":35,"value":288},"One at a time, waiting for each PDF",{"type":30,"tag":231,"props":290,"children":291},{},[292],{"type":35,"value":293},"108.8 s",{"type":30,"tag":231,"props":295,"children":296},{},[297],{"type":35,"value":280},{"type":30,"tag":179,"props":299,"children":301},{"caption":300},"40 one-page invoices, one machine. Our test, November 30, 2026.",[302],{"type":30,"tag":303,"props":304,"children":310},"guide-bar-chart",{":max":305,":rows":306,"label":307,"title":308,"unit":309},"120","[{\"name\":\"Webhook, 10 calls at a time\",\"ours\":true,\"base\":6.3,\"barLabel\":\"6.3 s\",\"note\":\"All 40 calls answered \\\"queued\\\" within 2.1 s.\"},{\"name\":\"10 at a time, waiting for each PDF\",\"base\":10.9,\"barLabel\":\"10.9 s\",\"note\":\"Each call holds a connection open for about 2.7 s.\"},{\"name\":\"One at a time\",\"base\":108.8,\"barLabel\":\"108.8 s\",\"note\":\"40 renders in a row.\"}]","Seconds until all 40 invoice PDFs were back. With a webhook, 10 calls at a time: 6.3 seconds. 10 at a time, waiting for each PDF: 10.9 seconds. One at a time: 108.8 seconds.","Seconds until all 40 PDFs were back","s",[],{"type":30,"tag":31,"props":312,"children":313},{},[314],{"type":35,"value":315},"The render didn't get faster: each invoice took about 2.1 seconds of PDFShift's time in every run. What changed is who waits. When you wait for each PDF, your 10 connections set the pace. With a webhook, our script was done in seconds and PDFShift rendered many invoices at once.",{"type":30,"tag":31,"props":317,"children":318},{},[319],{"type":35,"value":320},"Use webhooks for any batch that starts from a web request, a serverless function or a no-code step with a 30-second limit. It hands off the whole batch and returns, and Chromium stays on our servers, where we've run it at scale since 2018.",{"type":30,"tag":38,"props":322,"children":324},{"id":323},"how-do-i-send-a-large-batch-of-pdf-requests-asynchronously",[325],{"type":35,"value":326},"How do I send a large batch of PDF requests asynchronously?",{"type":30,"tag":31,"props":328,"children":329},{},[330,332,338],{"type":35,"value":331},"PDFShift runs up to 50 conversions at once on every plan and takes up to 250 documents a minute. At about 2.7 seconds a call, 50 at once could start roughly 1,100 a minute, so plan around the 250. Past it, PDFShift answers ",{"type":30,"tag":50,"props":333,"children":335},{"className":334},[],[336],{"type":35,"value":337},"429",{"type":35,"value":339},".",{"type":30,"tag":31,"props":341,"children":342},{},[343,345,351,353,362],{"type":35,"value":344},"So pace the sends instead of firing them all. This sender starts one call every 250 ms, which is 240 a minute, and puts your invoice ID in the webhook's headers. It needs Node 18 or later for the built-in ",{"type":30,"tag":50,"props":346,"children":348},{"className":347},[],[349],{"type":35,"value":350},"fetch",{"type":35,"value":352},", and it follows the ",{"type":30,"tag":354,"props":355,"children":359},"a",{"href":356,"rel":357},"https://docs.pdfshift.io/api-reference/convert-to-pdf",[358],"nofollow",[360],{"type":35,"value":361},"convert reference",{"type":35,"value":363}," for API v3:",{"type":30,"tag":103,"props":365,"children":370},{"className":366,"code":368,"language":369,"meta":7},[367],"language-javascript","const API_KEY = process.env.PDFSHIFT_API_KEY;\nconst WEBHOOK_URL = 'https://example.com/pdfshift-webhook';\n\nconst sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));\n\nasync function queuePdf(invoice) {\n  while (true) {\n    const res = await fetch('https://api.pdfshift.io/v3/convert/pdf', {\n      method: 'POST',\n      headers: { 'X-API-Key': API_KEY, 'Content-Type': 'application/json' },\n      body: JSON.stringify({\n        source: invoice.html,\n        webhook: {\n          url: WEBHOOK_URL,\n          headers: { 'X-Invoice-Id': invoice.id },\n        },\n      }),\n    });\n    if (res.status === 202) return; // queued: the PDF will be POSTed to WEBHOOK_URL\n    if (res.status === 429) { await sleep(60_000); continue; } // over 250 a minute: wait, then resend\n    throw new Error(`${invoice.id}: ${res.status} ${await res.text()}`);\n  }\n}\n\nexport async function sendBatch(invoices) {\n  const calls = [];\n  for (const invoice of invoices) {\n    calls.push(queuePdf(invoice));\n    await sleep(250); // 4 a second = 240 a minute, under the 250 limit\n  }\n  const results = await Promise.allSettled(calls);\n  return results.filter((r) => r.status === 'rejected').map((r) => r.reason.message);\n}\n","javascript",[371],{"type":30,"tag":50,"props":372,"children":373},{"__ignoreMap":7},[374],{"type":35,"value":368},{"type":30,"tag":31,"props":376,"children":377},{},[378,384,386,392],{"type":30,"tag":50,"props":379,"children":381},{"className":380},[],[382],{"type":35,"value":383},"sendBatch",{"type":35,"value":385}," returns the invoices that failed to queue, with the API's answer, so you can fix and resend just those. The same sender in Python 3.9 or later, with ",{"type":30,"tag":50,"props":387,"children":389},{"className":388},[],[390],{"type":35,"value":391},"requests",{"type":35,"value":393},":",{"type":30,"tag":103,"props":395,"children":400},{"className":396,"code":398,"language":399,"meta":7},[397],"language-python","import os\nimport time\nfrom concurrent.futures import ThreadPoolExecutor\n\nimport requests\n\nAPI_KEY = os.environ[\"PDFSHIFT_API_KEY\"]\nWEBHOOK_URL = \"https://example.com/pdfshift-webhook\"\n\n\ndef queue_pdf(invoice):\n    while True:\n        r = requests.post(\n            \"https://api.pdfshift.io/v3/convert/pdf\",\n            headers={\"X-API-Key\": API_KEY},\n            json={\n                \"source\": invoice[\"html\"],\n                \"webhook\": {\n                    \"url\": WEBHOOK_URL,\n                    \"headers\": {\"X-Invoice-Id\": invoice[\"id\"]},\n                },\n            },\n            timeout=30,\n        )\n        if r.status_code == 202:  # queued: the PDF will be POSTed to WEBHOOK_URL\n            return\n        if r.status_code == 429:  # over 250 a minute: wait, then resend\n            time.sleep(60)\n            continue\n        r.raise_for_status()\n\n\ndef send_batch(invoices):\n    with ThreadPoolExecutor(max_workers=10) as pool:\n        calls = []\n        for invoice in invoices:\n            calls.append(pool.submit(queue_pdf, invoice))\n            time.sleep(0.25)  # 4 a second = 240 a minute, under the 250 limit\n        return [c.exception() for c in calls if c.exception()]\n","python",[401],{"type":30,"tag":50,"props":402,"children":403},{"__ignoreMap":7},[404],{"type":35,"value":398},{"type":30,"tag":31,"props":406,"children":407},{},[408,410,416],{"type":35,"value":409},"If your invoices already sit in a job queue (BullMQ, SQS, Celery), set its worker to the same rate, 4 jobs a second, and call ",{"type":30,"tag":50,"props":411,"children":413},{"className":412},[],[414],{"type":35,"value":415},"queuePdf",{"type":35,"value":417}," from the job.",{"type":30,"tag":31,"props":419,"children":420},{},[421],{"type":35,"value":422},"Here's a month-end run of 10,000 one-page invoices, worked through:",{"type":30,"tag":424,"props":425,"children":426},"ul",{},[427,432,437],{"type":30,"tag":63,"props":428,"children":429},{},[430],{"type":35,"value":431},"At 240 a minute, sending takes about 42 minutes.",{"type":30,"tag":63,"props":433,"children":434},{},[435],{"type":35,"value":436},"The PDFs arrive as you go, a few seconds after each call (5.8 seconds at most in our test).",{"type":30,"tag":63,"props":438,"children":439},{},[440],{"type":35,"value":441},"Each of our one-page invoices cost 1 credit, so the run needs 10,000 credits. The $99 plan has 25,000 a month.",{"type":30,"tag":38,"props":443,"children":445},{"id":444},"how-do-i-match-each-webhook-callback-to-its-pdf-job",[446],{"type":35,"value":447},"How do I match each webhook callback to its PDF job?",{"type":30,"tag":31,"props":449,"children":450},{},[451,453,458,460,465,467,472,474,480],{"type":35,"value":452},"Put your own ID in the webhook's ",{"type":30,"tag":50,"props":454,"children":456},{"className":455},[],[457],{"type":35,"value":164},{"type":35,"value":459},". The body PDFShift posts has the file's URL, size and timings, but no request ID and nothing of yours, and the webhooks don't come back in the order you sent them. The headers you set on the ",{"type":30,"tag":50,"props":461,"children":463},{"className":462},[],[464],{"type":35,"value":55},{"type":35,"value":466}," object come back on the ",{"type":30,"tag":50,"props":468,"children":470},{"className":469},[],[471],{"type":35,"value":99},{"type":35,"value":473},": in our runs, all 80 webhooks carried the right ",{"type":30,"tag":50,"props":475,"children":477},{"className":476},[],[478],{"type":35,"value":479},"X-Invoice-Id",{"type":35,"value":339},{"type":30,"tag":31,"props":482,"children":483},{},[484,486,492],{"type":35,"value":485},"If your endpoint can't read headers, put the ID in the URL's query string (",{"type":30,"tag":50,"props":487,"children":489},{"className":488},[],[490],{"type":35,"value":491},"?invoice=INV-1000",{"type":35,"value":493},").",{"type":30,"tag":38,"props":495,"children":497},{"id":496},"how-do-i-verify-that-a-webhook-came-from-pdfshift",[498],{"type":35,"value":499},"How do I verify that a webhook came from PDFShift?",{"type":30,"tag":31,"props":501,"children":502},{},[503],{"type":35,"value":504},"Check the signature. Every webhook PDFShift sends carries two headers of its own:",{"type":30,"tag":424,"props":506,"children":507},{},[508,519],{"type":30,"tag":63,"props":509,"children":510},{},[511,517],{"type":30,"tag":50,"props":512,"children":514},{"className":513},[],[515],{"type":35,"value":516},"X-PDFShift-Timestamp",{"type":35,"value":518},": when the webhook was sent, in Unix seconds.",{"type":30,"tag":63,"props":520,"children":521},{},[522,528],{"type":30,"tag":50,"props":523,"children":525},{"className":524},[],[526],{"type":35,"value":527},"X-PDFShift-Signature",{"type":35,"value":529},": an HMAC-SHA256 in hex, with your API key as the key, of the timestamp followed by your API key.",{"type":30,"tag":31,"props":531,"children":532},{},[533,535,541,543,549,551,557],{"type":35,"value":534},"So with the key ",{"type":30,"tag":50,"props":536,"children":538},{"className":537},[],[539],{"type":35,"value":540},"sk_abcde",{"type":35,"value":542}," and the timestamp ",{"type":30,"tag":50,"props":544,"children":546},{"className":545},[],[547],{"type":35,"value":548},"1796133034",{"type":35,"value":550},", the signature is the HMAC of ",{"type":30,"tag":50,"props":552,"children":554},{"className":553},[],[555],{"type":35,"value":556},"1796133034sk_abcde",{"type":35,"value":558},". Work it out on your server and compare. Also refuse a timestamp more than 5 minutes old, so a webhook someone copied can't be sent to you again later. Retries are safe: in our test, each new try came with a new timestamp and signature.",{"type":30,"tag":31,"props":560,"children":561},{},[562,564,569,571,576],{"type":35,"value":563},"The signature covers the timestamp, not the body, so keep the endpoint on HTTPS. To add basic auth as well, the ",{"type":30,"tag":50,"props":565,"children":567},{"className":566},[],[568],{"type":35,"value":55},{"type":35,"value":570}," object takes ",{"type":30,"tag":50,"props":572,"children":574},{"className":573},[],[575],{"type":35,"value":156},{"type":35,"value":577}," with a username and password.",{"type":30,"tag":38,"props":579,"children":581},{"id":580},"what-happens-when-the-webhook-callback-fails",[582],{"type":35,"value":583},"What happens when the webhook callback fails?",{"type":30,"tag":31,"props":585,"children":586},{},[587,589,595,597,602],{"type":35,"value":588},"We pointed one webhook at an endpoint that always answered ",{"type":30,"tag":50,"props":590,"children":592},{"className":591},[],[593],{"type":35,"value":594},"500",{"type":35,"value":596},". PDFShift sent the same ",{"type":30,"tag":50,"props":598,"children":600},{"className":599},[],[601],{"type":35,"value":99},{"type":35,"value":603},", with the same file URL, 4 times: once, then again 30, 60 and 90 seconds later. After that it stopped. We watched for 5 minutes.",{"type":30,"tag":179,"props":605,"children":607},{"caption":606},"One webhook to an endpoint that answered 500 every time. Our test, November 30, 2026.",[608],{"type":30,"tag":609,"props":610,"children":618},"svg",{"viewBox":611,"xmlns":612,"role":184,"ariaLabelledBy":613,"style":616,"fontFamily":617},"0 0 360 168","http://www.w3.org/2000/svg",[614,615],"bpw-retry-title","bpw-retry-desc","max-width:360px;display:block;margin:0 auto","DM Sans, sans-serif",[619,625,631,640,648,656,666,674,696,718],{"type":30,"tag":620,"props":621,"children":622},"title",{"id":614},[623],{"type":35,"value":624},"PDFShift delivered the same webhook 4 times, 30 seconds apart, then stopped",{"type":30,"tag":626,"props":627,"children":628},"desc",{"id":615},[629],{"type":35,"value":630},"Timeline from 0 to 300 seconds after the PDF was ready. Deliveries 1 to 4 at 0, 30, 60 and 90 seconds, each answered 500 by our endpoint. No delivery from 90 to 300 seconds.",{"type":30,"tag":35,"props":632,"children":637},{"x":633,"y":634,"style":635,"fill":636},"16","22","font-size:13px;font-weight:600","#0A0C3D",[638],{"type":35,"value":639},"4 deliveries, 30 s apart",{"type":30,"tag":35,"props":641,"children":645},{"x":633,"y":642,"style":643,"fill":644},"42","font-size:13px","#FF9D28",[646],{"type":35,"value":647},"Each answered 500",{"type":30,"tag":649,"props":650,"children":655},"line",{"x1":633,"y1":651,"x2":652,"y2":651,"stroke":653,"strokeWidth":654},"100","344","#4C556D","2",[],{"type":30,"tag":657,"props":658,"children":665},"rect",{"x":659,"y":660,"width":661,"height":662,"rx":663,"fill":664},"126","86","218","28","4","#DBE4F2",[],{"type":30,"tag":35,"props":667,"children":671},{"x":668,"y":669,"textAnchor":670,"style":643,"fill":636},"235","105","middle",[672],{"type":35,"value":673},"None in the next 3.5 minutes",{"type":30,"tag":675,"props":676,"children":678},"g",{"fill":677},"#6C47FF",[679,684,688,692],{"type":30,"tag":680,"props":681,"children":683},"circle",{"cx":633,"cy":651,"r":682},"7",[],{"type":30,"tag":680,"props":685,"children":687},{"cx":686,"cy":651,"r":682},"49",[],{"type":30,"tag":680,"props":689,"children":691},{"cx":690,"cy":651,"r":682},"82",[],{"type":30,"tag":680,"props":693,"children":695},{"cx":694,"cy":651,"r":682},"114",[],{"type":30,"tag":675,"props":697,"children":698},{"style":635,"fill":636},[699,705,709,714],{"type":30,"tag":35,"props":700,"children":702},{"x":633,"y":701,"textAnchor":670},"80",[703],{"type":35,"value":704},"1",{"type":30,"tag":35,"props":706,"children":707},{"x":686,"y":701,"textAnchor":670},[708],{"type":35,"value":654},{"type":30,"tag":35,"props":710,"children":711},{"x":690,"y":701,"textAnchor":670},[712],{"type":35,"value":713},"3",{"type":30,"tag":35,"props":715,"children":716},{"x":694,"y":701,"textAnchor":670},[717],{"type":35,"value":663},{"type":30,"tag":675,"props":719,"children":720},{"style":643,"fill":653},[721,728,733,739,745,751,757],{"type":30,"tag":35,"props":722,"children":725},{"x":633,"y":723,"textAnchor":724},"134","start",[726],{"type":35,"value":727},"0 s",{"type":30,"tag":35,"props":729,"children":730},{"x":690,"y":723,"textAnchor":670},[731],{"type":35,"value":732},"60 s",{"type":30,"tag":35,"props":734,"children":736},{"x":735,"y":723,"textAnchor":670},"147",[737],{"type":35,"value":738},"120 s",{"type":30,"tag":35,"props":740,"children":742},{"x":741,"y":723,"textAnchor":670},"213",[743],{"type":35,"value":744},"180 s",{"type":30,"tag":35,"props":746,"children":748},{"x":747,"y":723,"textAnchor":670},"278",[749],{"type":35,"value":750},"240 s",{"type":30,"tag":35,"props":752,"children":754},{"x":652,"y":723,"textAnchor":753},"end",[755],{"type":35,"value":756},"300 s",{"type":30,"tag":35,"props":758,"children":760},{"x":633,"y":759},"160",[761],{"type":35,"value":762},"Seconds after the PDF was ready",{"type":30,"tag":31,"props":764,"children":765},{},[766],{"type":35,"value":767},"So the receiver has three jobs:",{"type":30,"tag":424,"props":769,"children":770},{},[771,781,799],{"type":30,"tag":63,"props":772,"children":773},{},[774,779],{"type":30,"tag":235,"props":775,"children":776},{},[777],{"type":35,"value":778},"Save each PDF once.",{"type":35,"value":780}," An error answer gets the same PDF sent again, so saving it must be safe to repeat.",{"type":30,"tag":63,"props":782,"children":783},{},[784,789,791,797],{"type":30,"tag":235,"props":785,"children":786},{},[787],{"type":35,"value":788},"Answer first.",{"type":35,"value":790}," Reply ",{"type":30,"tag":50,"props":792,"children":794},{"className":793},[],[795],{"type":35,"value":796},"200",{"type":35,"value":798}," before you download and store the file, so a slow download or a storage error never turns into an error answer.",{"type":30,"tag":63,"props":800,"children":801},{},[802,807,809,814],{"type":30,"tag":235,"props":803,"children":804},{},[805],{"type":35,"value":806},"Chase the PDFs that never arrive.",{"type":35,"value":808}," If your server is down for longer than those 90 seconds, don't count on another delivery. Keep the ID as pending until the file is saved, and every few minutes resend the invoices still pending after 10 minutes, with the same ",{"type":30,"tag":50,"props":810,"children":812},{"className":811},[],[813],{"type":35,"value":383},{"type":35,"value":339},{"type":30,"tag":31,"props":816,"children":817},{},[818,820,826,827,833],{"type":35,"value":819},"Here's a receiver in Express 4 that handles all three and checks the signature first. ",{"type":30,"tag":50,"props":821,"children":823},{"className":822},[],[824],{"type":35,"value":825},"db",{"type":35,"value":158},{"type":30,"tag":50,"props":828,"children":830},{"className":829},[],[831],{"type":35,"value":832},"storage",{"type":35,"value":834}," stand for your own database and file storage:",{"type":30,"tag":103,"props":836,"children":839},{"className":837,"code":838,"language":369,"meta":7},[367],"import crypto from 'node:crypto';\nimport express from 'express';\nimport { db, storage } from './your-app.mjs'; // your own database and file storage\n\nconst API_KEY = process.env.PDFSHIFT_API_KEY;\n\nfunction fromPdfshift(req) {\n  const timestamp = req.get('X-PDFShift-Timestamp') ?? '';\n  const signature = req.get('X-PDFShift-Signature') ?? '';\n  const expected = crypto.createHmac('sha256', API_KEY).update(timestamp + API_KEY).digest('hex');\n  const recent = Math.abs(Date.now() / 1000 - Number(timestamp)) \u003C 300; // sent in the last 5 minutes\n  return recent && signature.length === expected.length &&\n    crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));\n}\n\nconst app = express();\napp.use(express.json());\n\napp.post('/pdfshift-webhook', async (req, res) => {\n  if (!fromPdfshift(req)) return res.sendStatus(401);\n  res.sendStatus(200); // answer at once: an error answer gets the same PDF sent again\n\n  const invoiceId = req.get('X-Invoice-Id');\n  if (await db.isDone(invoiceId)) return; // a repeat delivery of a PDF we already saved\n  if (req.body.error) return db.markFailed(invoiceId, req.body.error.error);\n\n  const pdf = Buffer.from(await (await fetch(req.body.url)).arrayBuffer()); // the link expires after 2 days\n  await storage.save(`invoices/${invoiceId}.pdf`, pdf);\n  await db.markDone(invoiceId);\n});\n\napp.listen(3000);\n",[840],{"type":30,"tag":50,"props":841,"children":842},{"__ignoreMap":7},[843],{"type":35,"value":838},{"type":30,"tag":31,"props":845,"children":846},{},[847,849,854,856,862,864,871],{"type":35,"value":848},"We tested it with real webhooks on December 1, 2026: a fresh one got ",{"type":30,"tag":50,"props":850,"children":852},{"className":851},[],[853],{"type":35,"value":796},{"type":35,"value":855},", a wrong or missing signature and a webhook from the day before got ",{"type":30,"tag":50,"props":857,"children":859},{"className":858},[],[860],{"type":35,"value":861},"401",{"type":35,"value":863},", the PDF was saved once, the repeat delivery was skipped, and an error body marked the invoice as failed. This follows the ",{"type":30,"tag":354,"props":865,"children":868},{"href":866,"rel":867},"https://docs.pdfshift.io/docs/webhook-events",[358],[869],{"type":35,"value":870},"webhook events",{"type":35,"value":872}," page for API v3.",{"type":30,"tag":38,"props":874,"children":876},{"id":875},"what-does-a-failed-async-conversion-send-to-the-webhook",[877],{"type":35,"value":878},"What does a failed async conversion send to the webhook?",{"type":30,"tag":31,"props":880,"children":881},{},[882,884,889,891,897,899,904],{"type":35,"value":883},"When a conversion fails, the webhook still gets a ",{"type":30,"tag":50,"props":885,"children":887},{"className":886},[],[888],{"type":35,"value":99},{"type":35,"value":890},", with an ",{"type":30,"tag":50,"props":892,"children":894},{"className":893},[],[895],{"type":35,"value":896},"error",{"type":35,"value":898}," key in place of ",{"type":30,"tag":50,"props":900,"children":902},{"className":901},[],[903],{"type":35,"value":124},{"type":35,"value":393},{"type":30,"tag":103,"props":906,"children":909},{"className":907,"code":908,"language":108,"meta":7},[106],"{\n  \"error\": {\n    \"code\": 400,\n    \"error\": \"The requested page took too long to load.\",\n    \"identifier\": \"A74\",\n    \"success\": false\n  }\n}\n",[910],{"type":30,"tag":50,"props":911,"children":912},{"__ignoreMap":7},[913],{"type":35,"value":908},{"type":30,"tag":31,"props":915,"children":916},{},[917,919,924,926,932],{"type":35,"value":918},"Check for ",{"type":30,"tag":50,"props":920,"children":922},{"className":921},[],[923],{"type":35,"value":896},{"type":35,"value":925}," before anything else. Mark the invoice as failed with the message, fix the cause (a page that loads too slowly, for example), and resend only that invoice. If you send a URL as the source, add ",{"type":30,"tag":50,"props":927,"children":929},{"className":928},[],[930],{"type":35,"value":931},"\"raise_for_status\": true",{"type":35,"value":933}," so a page that answers 404 or 500 isn't turned into a PDF of the error page.",{"type":30,"tag":38,"props":935,"children":937},{"id":936},"frequently-asked-questions",[938],{"type":35,"value":939},"Frequently asked questions",{"type":30,"tag":31,"props":941,"children":942},{},[943],{"type":30,"tag":235,"props":944,"children":945},{},[946],{"type":35,"value":15},{"type":30,"tag":31,"props":948,"children":949},{},[950,952,958],{"type":35,"value":951},"Not a separate one. A batch is one request per document, and each request with a webhook is queued and handled on its own. On accounts with parallel conversions enabled, ",{"type":30,"tag":50,"props":953,"children":955},{"className":954},[],[956],{"type":35,"value":957},"source",{"type":35,"value":959}," can also be an array of documents.",{"type":30,"tag":31,"props":961,"children":962},{},[963],{"type":30,"tag":235,"props":964,"children":965},{},[966],{"type":35,"value":18},{"type":30,"tag":31,"props":968,"children":969},{},[970],{"type":35,"value":19},{"type":30,"tag":31,"props":972,"children":973},{},[974],{"type":30,"tag":235,"props":975,"children":976},{},[977],{"type":35,"value":21},{"type":30,"tag":31,"props":979,"children":980},{},[981,983,989,990,996,997,1003,1005,1011],{"type":35,"value":982},"Yes. The ",{"type":30,"tag":50,"props":984,"children":986},{"className":985},[],[987],{"type":35,"value":988},"/v3/convert/png",{"type":35,"value":143},{"type":30,"tag":50,"props":991,"children":993},{"className":992},[],[994],{"type":35,"value":995},"/jpeg",{"type":35,"value":158},{"type":30,"tag":50,"props":998,"children":1000},{"className":999},[],[1001],{"type":35,"value":1002},"/webp",{"type":35,"value":1004}," endpoints take the same parameters as ",{"type":30,"tag":50,"props":1006,"children":1008},{"className":1007},[],[1009],{"type":35,"value":1010},"/v3/convert/pdf",{"type":35,"value":1012},", webhook included.",{"type":30,"tag":31,"props":1014,"children":1015},{},[1016],{"type":30,"tag":235,"props":1017,"children":1018},{},[1019],{"type":35,"value":24},{"type":30,"tag":31,"props":1021,"children":1022},{},[1023,1025,1032,1034,1040,1042,1048,1050,1056,1058,1064,1066,1071],{"type":35,"value":1024},"Yes. Allow PDFShift to write to the bucket in its policy (the ",{"type":30,"tag":354,"props":1026,"children":1029},{"href":1027,"rel":1028},"https://docs.pdfshift.io/docs/saving/to-s3",[358],[1030],{"type":35,"value":1031},"S3 setup",{"type":35,"value":1033}," shows it), then add ",{"type":30,"tag":50,"props":1035,"children":1037},{"className":1036},[],[1038],{"type":35,"value":1039},"s3_destination",{"type":35,"value":1041}," with a path like ",{"type":30,"tag":50,"props":1043,"children":1045},{"className":1044},[],[1046],{"type":35,"value":1047},"s3://your-bucket/invoices/INV-1000.pdf",{"type":35,"value":1049},". With ",{"type":30,"tag":50,"props":1051,"children":1053},{"className":1052},[],[1054],{"type":35,"value":1055},"is_hipaa",{"type":35,"value":1057}," set to ",{"type":30,"tag":50,"props":1059,"children":1061},{"className":1060},[],[1062],{"type":35,"value":1063},"true",{"type":35,"value":1065},", a webhook request needs ",{"type":30,"tag":50,"props":1067,"children":1069},{"className":1068},[],[1070],{"type":35,"value":1039},{"type":35,"value":339},{"type":30,"tag":31,"props":1073,"children":1074},{},[1075,1077,1083],{"type":35,"value":1076},"To try the whole flow, ",{"type":30,"tag":354,"props":1078,"children":1080},{"href":1079},"/register/",[1081],{"type":35,"value":1082},"create a free account",{"type":35,"value":1084}," and push 5 invoices through the sender and your receiver before the month-end run.",{"title":7,"searchDepth":1086,"depth":1086,"links":1087},2,[1088,1089,1090,1091,1092,1093,1094,1095],{"id":40,"depth":1086,"text":43},{"id":169,"depth":1086,"text":172},{"id":323,"depth":1086,"text":326},{"id":444,"depth":1086,"text":447},{"id":496,"depth":1086,"text":499},{"id":580,"depth":1086,"text":583},{"id":875,"depth":1086,"text":878},{"id":936,"depth":1086,"text":939},"markdown","content:guides:batch-pdf-generation-webhooks.md","content","guides/batch-pdf-generation-webhooks.md","md",1796403668672]