[{"data":1,"prerenderedAt":154},["Reactive",2],{"/guides/python/urllib3/generate-a-document-with-full-height":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":5,"property":11,"output":12,"default":6,"body":13,"_type":149,"_id":150,"_source":151,"_file":152,"_extension":153},"/guides/python/urllib3/generate-a-document-with-full-height","urllib3",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 Python code samples using the urllib3 library to help you generate full-height documents with PDFShift's API.","Python","format","pdf",{"type":14,"children":15,"toc":146},"root",[16,24,45,57,62,73,94,99,110],{"type":17,"tag":18,"props":19,"children":20},"element","p",{},[21],{"type":22,"value":23},"text","In this guide, we'll show you how to generate a document with full height dynamically using Python and the urllib3 library to convert them to PDF using PDFShift's API.",{"type":17,"tag":18,"props":25,"children":26},{},[27,29,35,37,43],{"type":22,"value":28},"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":17,"tag":30,"props":31,"children":33},"code",{"className":32},[],[34],{"type":22,"value":11},{"type":22,"value":36}," parameter to the request and passing it a custom \"auto\" value for the ",{"type":17,"tag":30,"props":38,"children":40},{"className":39},[],[41],{"type":22,"value":42},"{height}",{"type":22,"value":44}," part.",{"type":17,"tag":46,"props":47,"children":52},"pre",{"className":48,"code":50,"language":51,"meta":7},[49],"language-python","import urllib3, json, base64\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\nhttp = urllib3.PoolManager()\nresponse = http.request(\n    'POST',\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    },\n    body=json.dumps(params).encode('utf-8')\n)\n\nif response.status != 200:\n    raise ValueError(f\"Request failed with status code {response.status}: {response.data.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(response.content)\n\nprint('The PDF document was generated and saved to result.pdf')\n","python",[53],{"type":17,"tag":30,"props":54,"children":55},{"__ignoreMap":7},[56],{"type":22,"value":50},{"type":17,"tag":18,"props":58,"children":59},{},[60],{"type":22,"value":61},"The format parameter can accept various values, such as 'Letter', 'Legal', 'Tabloid', 'Ledger', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5'.",{"type":17,"tag":18,"props":63,"children":64},{},[65,67],{"type":22,"value":66},"But it can also accept a custom values that is defined per the width and height as follow: ",{"type":17,"tag":30,"props":68,"children":70},{"className":69},[],[71],{"type":22,"value":72},"{width}x{height}",{"type":17,"tag":18,"props":74,"children":75},{},[76,78,84,86,92],{"type":22,"value":77},"Both ",{"type":17,"tag":30,"props":79,"children":81},{"className":80},[],[82],{"type":22,"value":83},"width",{"type":22,"value":85}," and ",{"type":17,"tag":30,"props":87,"children":89},{"className":88},[],[90],{"type":22,"value":91},"height",{"type":22,"value":93}," are pixel value by default, but if you precise the unit (in \"cm\", \"mm\", \"in\" or \"pt\"). That unit will be used instead.",{"type":17,"tag":18,"props":95,"children":96},{},[97],{"type":22,"value":98},"For instance, you can set a format of:",{"type":17,"tag":46,"props":100,"children":105},{"className":101,"code":103,"language":104,"meta":7},[102],"language-json","{\n    \"source\": \"https://www.example.com\",\n    \"format\": \"21cmx29,7cm\"\n}\n","json",[106],{"type":17,"tag":30,"props":107,"children":108},{"__ignoreMap":7},[109],{"type":22,"value":103},{"type":17,"tag":18,"props":111,"children":112},{},[113,115,120,122,128,130,136,138,144],{"type":22,"value":114},"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":17,"tag":30,"props":116,"children":118},{"className":117},[],[119],{"type":22,"value":42},{"type":22,"value":121}," value to ",{"type":17,"tag":30,"props":123,"children":125},{"className":124},[],[126],{"type":22,"value":127},"auto",{"type":22,"value":129},".\nSo, instead of setting a fixed height such as ",{"type":17,"tag":30,"props":131,"children":133},{"className":132},[],[134],{"type":22,"value":135},"'format': '1280x1024'",{"type":22,"value":137},", you can set ",{"type":17,"tag":30,"props":139,"children":141},{"className":140},[],[142],{"type":22,"value":143},"'format': '1280xauto'",{"type":22,"value":145}," and the height will be calculated based on the content of the page.",{"title":7,"searchDepth":147,"depth":147,"links":148},2,[],"markdown","content:guides:python:urllib3:generate-a-document-with-full-height.md","content","guides/python/urllib3/generate-a-document-with-full-height.md","md",1785426833932]