[{"data":1,"prerenderedAt":155},["Reactive",2],{"/guides/node/node-fetch/generate-a-document-with-full-height":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":150,"_id":151,"_source":152,"_file":153,"_extension":154},"/guides/node/node-fetch/generate-a-document-with-full-height","node-fetch",false,"","Generate a document with full height","Learn to generate full-height documents dynamically with our step-by-step guide. This will allow you to create documents with a dynamic height, based on the content of the document. This guide provides Node code samples using the NodeFetch library to help you generate full-height documents with PDFShift's API.","Node","NodeFetch","format","pdf",{"type":15,"children":16,"toc":147},"root",[17,25,46,58,63,74,95,100,111],{"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 generate a document with full height dynamically 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,38,44],{"type":23,"value":29},"When you're converting a document, you might want to generate a document with full height dynamically. 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 and passing it a custom \"auto\" value for the ",{"type":18,"tag":31,"props":39,"children":41},{"className":40},[],[42],{"type":23,"value":43},"{height}",{"type":23,"value":45}," part.",{"type":18,"tag":47,"props":48,"children":53},"pre",{"className":49,"code":51,"language":52,"meta":7},[50],"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://www.example.com',\n    format: '1280xauto'\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",[54],{"type":18,"tag":31,"props":55,"children":56},{"__ignoreMap":7},[57],{"type":23,"value":51},{"type":18,"tag":19,"props":59,"children":60},{},[61],{"type":23,"value":62},"The format parameter can accept various values, such as 'Letter', 'Legal', 'Tabloid', 'Ledger', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5'.",{"type":18,"tag":19,"props":64,"children":65},{},[66,68],{"type":23,"value":67},"But it can also accept a custom values that is defined per the width and height as follow: ",{"type":18,"tag":31,"props":69,"children":71},{"className":70},[],[72],{"type":23,"value":73},"{width}x{height}",{"type":18,"tag":19,"props":75,"children":76},{},[77,79,85,87,93],{"type":23,"value":78},"Both ",{"type":18,"tag":31,"props":80,"children":82},{"className":81},[],[83],{"type":23,"value":84},"width",{"type":23,"value":86}," and ",{"type":18,"tag":31,"props":88,"children":90},{"className":89},[],[91],{"type":23,"value":92},"height",{"type":23,"value":94}," are pixel value by default, but if you precise the unit (in \"cm\", \"mm\", \"in\" or \"pt\"). That unit will be used instead.",{"type":18,"tag":19,"props":96,"children":97},{},[98],{"type":23,"value":99},"For instance, you can set a format of:",{"type":18,"tag":47,"props":101,"children":106},{"className":102,"code":104,"language":105,"meta":7},[103],"language-json","{\n    \"source\": \"https://www.example.com\",\n    \"format\": \"21cmx29,7cm\"\n}\n","json",[107],{"type":18,"tag":31,"props":108,"children":109},{"__ignoreMap":7},[110],{"type":23,"value":104},{"type":18,"tag":19,"props":112,"children":113},{},[114,116,121,123,129,131,137,139,145],{"type":23,"value":115},"Now, if you want a \"liquid\" height, which will analyze the height of the page and use it as your format, you can set the ",{"type":18,"tag":31,"props":117,"children":119},{"className":118},[],[120],{"type":23,"value":43},{"type":23,"value":122}," value to ",{"type":18,"tag":31,"props":124,"children":126},{"className":125},[],[127],{"type":23,"value":128},"auto",{"type":23,"value":130},".\nSo, instead of setting a fixed height such as ",{"type":18,"tag":31,"props":132,"children":134},{"className":133},[],[135],{"type":23,"value":136},"format: '1280x1024'",{"type":23,"value":138},", you can set ",{"type":18,"tag":31,"props":140,"children":142},{"className":141},[],[143],{"type":23,"value":144},"format: '1280xauto'",{"type":23,"value":146}," and the height will be calculated based on the content of the page.",{"title":7,"searchDepth":148,"depth":148,"links":149},2,[],"markdown","content:guides:node:node-fetch:generate-a-document-with-full-height.md","content","guides/node/node-fetch/generate-a-document-with-full-height.md","md",1785426830690]