[{"data":1,"prerenderedAt":122},["Reactive",2],{"/guides/node/node-fetch/exporting-only-a-specific-set-of-pages":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":11,"property":12,"output":13,"default":6,"body":14,"_type":117,"_id":118,"_source":119,"_file":120,"_extension":121},"/guides/node/node-fetch/exporting-only-a-specific-set-of-pages","node-fetch",false,"","Exporting only a specific set of pages","Learn how to export only a specific set of pages from a document using Node and the NodeFetch library. This guide offers detailed steps with code samples in Node and the NodeFetch library, highlighting how you can export only a specific set of pages from a document using PDFShift's API.","Node","NodeFetch","pages","pdf",{"type":15,"children":16,"toc":114},"root",[17,25,38,43,48,92,97,102],{"type":18,"tag":19,"props":20,"children":21},"element","p",{},[22],{"type":23,"value":24},"text","In this guide, we'll show you how to export only a specific set of pages from a document using Node and the NodeFetch library to convert them to PDF using PDFShift's API.",{"type":18,"tag":19,"props":26,"children":27},{},[28,30,36],{"type":23,"value":29},"When you're converting a document, you might want to export only a specific set of pages from a document. This can be done by setting the ",{"type":18,"tag":31,"props":32,"children":34},"code",{"className":33},[],[35],{"type":23,"value":12},{"type":23,"value":37}," parameter to the request.",{"type":18,"tag":19,"props":39,"children":40},{},[41],{"type":23,"value":42},"It behaves exactly like the page parameter you can see when you print a document from your browser.",{"type":18,"tag":19,"props":44,"children":45},{},[46],{"type":23,"value":47},"It accepts the following pattern:",{"type":18,"tag":49,"props":50,"children":51},"ul",{},[52,66,79],{"type":18,"tag":53,"props":54,"children":55},"li",{},[56,58,64],{"type":23,"value":57},"A number, such as ",{"type":18,"tag":31,"props":59,"children":61},{"className":60},[],[62],{"type":23,"value":63},"2",{"type":23,"value":65},". This will print the page 2",{"type":18,"tag":53,"props":67,"children":68},{},[69,71,77],{"type":23,"value":70},"A range, such as ",{"type":18,"tag":31,"props":72,"children":74},{"className":73},[],[75],{"type":23,"value":76},"2-4",{"type":23,"value":78},". This will print the pages 2 to 4 (2, 3 and 4)",{"type":18,"tag":53,"props":80,"children":81},{},[82,84,90],{"type":23,"value":83},"A list, such as ",{"type":18,"tag":31,"props":85,"children":87},{"className":86},[],[88],{"type":23,"value":89},"2,4,5,9",{"type":23,"value":91},". This will print the pages 2, 4, 5 and 9",{"type":18,"tag":19,"props":93,"children":94},{},[95],{"type":23,"value":96},"This way, you can only export the pages that you really need and get immediately the result you want in the PDF, without having to edit it.",{"type":18,"tag":19,"props":98,"children":99},{},[100],{"type":23,"value":101},"Here's an example:",{"type":18,"tag":103,"props":104,"children":109},"pre",{"className":105,"code":107,"language":108,"meta":7},[106],"language-javascript","const fetch = require('node-fetch');\nconst fs = require('fs');\n\n// You can get an API key at https://pdfshift.io\napi_key = 'sk_xxxxxxxxxxxx'\n\nparams = {\n    source: 'https://en.wikipedia.org/wiki/PDF',\n    pages: '2-4'\n}\n\nconst response = await fetch('https://api.pdfshift.io/v3/convert/pdf', {\n    method: 'post',\n    headers: {\n        'X-API-Key': api_key,\n        'Content-Type': 'application/json'\n    },\n    body: JSON.stringify(params)\n});\n\nif (!response.ok) {\n    throw new Error(`HTTP error! status: ${response.status}`);\n}\n\nfs.writeFileSync('result.pdf', response.buffer());\n\nconsole.log('The PDF document was generated and saved to result.pdf');\n","javascript",[110],{"type":18,"tag":31,"props":111,"children":112},{"__ignoreMap":7},[113],{"type":23,"value":107},{"title":7,"searchDepth":115,"depth":115,"links":116},2,[],"markdown","content:guides:node:node-fetch:exporting-only-a-specific-set-of-pages.md","content","guides/node/node-fetch/exporting-only-a-specific-set-of-pages.md","md",1785426830674]