[{"data":1,"prerenderedAt":7030},["Reactive",2],{"/guides/python/httplib2":3},[4,66,309,472,582,649,680,773,829,926,1056,1099,1143,1185,1231,1400,1498,1588,1697,1734,1835,2003,2042,2235,2370,2469,2524,2551,2630,2676,2758,2866,2903,2944,2981,3022,3167,3250,3326,3419,3450,3536,3678,3718,3911,4046,4145,4200,4228,4307,4353,4435,4543,4580,4621,4658,4699,4844,4927,5003,5096,5127,5213,5355,5394,5587,5722,5821,5876,5903,5982,6028,6110,6218,6255,6296,6333,6374,6519,6602,6678,6771,6802,6888],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":10,"language":11,"library":6,"property":12,"output":13,"related":14,"default":7,"body":17,"_type":61,"_id":62,"_source":63,"_file":64,"_extension":65},"/guides/python/aiohttp/accessing-secured-pages","aiohttp",false,"","Accessing secured pages","Learn how to access secured pages using Python and the aiohttp library. This guide offers detailed steps with code samples in Python and the aiohttp library, highlighting how you can acces page protected by basic authentication to convert them to PDF using PDFShift's API.","Python","auth","pdf",[15,16],"send-custom-http-headers","using-cookies",{"type":18,"children":19,"toc":58},"root",[20,28,41,53],{"type":21,"tag":22,"props":23,"children":24},"element","p",{},[25],{"type":26,"value":27},"text","In this guide, we'll show you how to access secured page (protected by basic authentication) using Python and the aiohttp library to convert them to PDF using PDFShift's API.",{"type":21,"tag":22,"props":29,"children":30},{},[31,33,39],{"type":26,"value":32},"When you're converting a document, you might want to access a secured page (protected by basic authentication) to convert it to PDF. This can be done by setting the ",{"type":21,"tag":34,"props":35,"children":37},"code",{"className":36},[],[38],{"type":26,"value":12},{"type":26,"value":40}," parameter to the request.",{"type":21,"tag":42,"props":43,"children":48},"pre",{"className":44,"code":46,"language":47,"meta":8},[45],"language-python","import aiohttp, asyncio, json\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    # You can set a basic authentication by passing the \"auth\" property which contains a username and password\n    'auth': {\n        'username': 'user',\n        'password': 'password'\n    }\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n","python",[49],{"type":21,"tag":34,"props":50,"children":51},{"__ignoreMap":8},[52],{"type":26,"value":46},{"type":21,"tag":22,"props":54,"children":55},{},[56],{"type":26,"value":57},"This allows you to protect your documents from any visitors while allowing PDFShift to access the page and convert it to PDF.",{"title":8,"searchDepth":59,"depth":59,"links":60},2,[],"markdown","content:guides:python:aiohttp:accessing-secured-pages.md","content","guides/python/aiohttp/accessing-secured-pages.md","md",{"_path":67,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":68,"description":69,"language":11,"library":6,"property":70,"output":13,"related":71,"default":7,"body":76,"_type":61,"_id":307,"_source":63,"_file":308,"_extension":65},"/guides/python/aiohttp/adding-a-custom-header-or-footer","Adding a custom header or footer","Discover how to add custom headers or footers to a PDF using Python and the aiohttp library. This in-depth guide includes Python codes that you can easily follow and quickly generate documents with PDFShift's API.","header",[72,73,74,75],"loading-css-from-a-string","loading-css-from-a-url","loading-javascript-from-a-string","loading-javascript-from-a-url",{"type":18,"children":77,"toc":305},[78,83,111,123,193,204,209,218,229,234,300],{"type":21,"tag":22,"props":79,"children":80},{},[81],{"type":26,"value":82},"In this guide, we'll show you how to add custom headers or footers to a PDF using Python and the aiohttp library.",{"type":21,"tag":22,"props":84,"children":85},{},[86,88,93,95,101,103,109],{"type":26,"value":87},"We'll focus this guide on the ",{"type":21,"tag":34,"props":89,"children":91},{"className":90},[],[92],{"type":26,"value":70},{"type":26,"value":94}," parameter, but know that the ",{"type":21,"tag":34,"props":96,"children":98},{"className":97},[],[99],{"type":26,"value":100},"footer",{"type":26,"value":102}," parameter works ",{"type":21,"tag":104,"props":105,"children":106},"em",{},[107],{"type":26,"value":108},"exactly",{"type":26,"value":110}," the same way.",{"type":21,"tag":22,"props":112,"children":113},{},[114,116,121],{"type":26,"value":115},"The ",{"type":21,"tag":34,"props":117,"children":119},{"className":118},[],[120],{"type":26,"value":70},{"type":26,"value":122}," parameter is an object that accepts the following parameters:",{"type":21,"tag":124,"props":125,"children":126},"ul",{},[127,139,182],{"type":21,"tag":128,"props":129,"children":130},"li",{},[131,137],{"type":21,"tag":34,"props":132,"children":134},{"className":133},[],[135],{"type":26,"value":136},"source",{"type":26,"value":138},": The source of the header. It can be a URL or a raw HTML document. You can also provide some variables that we'll explain at the bottom of this guide.",{"type":21,"tag":128,"props":140,"children":141},{},[142,148,150,156,158,164,166,172,174,180],{"type":21,"tag":34,"props":143,"children":145},{"className":144},[],[146],{"type":26,"value":147},"height",{"type":26,"value":149},": The height of the header. By default, the height is in pixels, but you can also use ",{"type":21,"tag":34,"props":151,"children":153},{"className":152},[],[154],{"type":26,"value":155},"mm",{"type":26,"value":157},", ",{"type":21,"tag":34,"props":159,"children":161},{"className":160},[],[162],{"type":26,"value":163},"cm",{"type":26,"value":165}," or ",{"type":21,"tag":34,"props":167,"children":169},{"className":168},[],[170],{"type":26,"value":171},"in",{"type":26,"value":173}," as units, like ",{"type":21,"tag":34,"props":175,"children":177},{"className":176},[],[178],{"type":26,"value":179},"10mm",{"type":26,"value":181},".",{"type":21,"tag":128,"props":183,"children":184},{},[185,191],{"type":21,"tag":34,"props":186,"children":188},{"className":187},[],[189],{"type":26,"value":190},"start_at",{"type":26,"value":192},": The page number where the header should start. By default, the header will start at the first page.",{"type":21,"tag":22,"props":194,"children":195},{},[196,202],{"type":21,"tag":197,"props":198,"children":199},"strong",{},[200],{"type":26,"value":201},"NOTE",{"type":26,"value":203},": You must provide the full data in the header/footer, and not via a network request. Loading files such as external CSS, Js or Fonts won't work in the header or footer.\nInstead, we recommend you to embed them in Base64.",{"type":21,"tag":22,"props":205,"children":206},{},[207],{"type":26,"value":208},"Here's an example:",{"type":21,"tag":42,"props":210,"children":213},{"className":211,"code":212,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'header': {\n        'source': '\u003Cdiv>Page {{ page }} over a total of {{ total }}. Made on {{ date }}\u003C/div>',\n        'height': 150,\n        'start_at': 2\n    }\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[214],{"type":21,"tag":34,"props":215,"children":216},{"__ignoreMap":8},[217],{"type":26,"value":212},{"type":21,"tag":22,"props":219,"children":220},{},[221,222,227],{"type":26,"value":115},{"type":21,"tag":34,"props":223,"children":225},{"className":224},[],[226],{"type":26,"value":136},{"type":26,"value":228}," parameter present in the header/footer accepts a set of variables that will be translated when converting the document.",{"type":21,"tag":22,"props":230,"children":231},{},[232],{"type":26,"value":233},"Here are the properties you can use:",{"type":21,"tag":124,"props":235,"children":236},{},[237,248,259,270,281],{"type":21,"tag":128,"props":238,"children":239},{},[240,246],{"type":21,"tag":34,"props":241,"children":243},{"className":242},[],[244],{"type":26,"value":245},"{{ title }}",{"type":26,"value":247},": The title of the document.",{"type":21,"tag":128,"props":249,"children":250},{},[251,257],{"type":21,"tag":34,"props":252,"children":254},{"className":253},[],[255],{"type":26,"value":256},"{{ url }}",{"type":26,"value":258},": The URL of the document.",{"type":21,"tag":128,"props":260,"children":261},{},[262,268],{"type":21,"tag":34,"props":263,"children":265},{"className":264},[],[266],{"type":26,"value":267},"{{ page }}",{"type":26,"value":269},": The current page number.",{"type":21,"tag":128,"props":271,"children":272},{},[273,279],{"type":21,"tag":34,"props":274,"children":276},{"className":275},[],[277],{"type":26,"value":278},"{{ total }}",{"type":26,"value":280},": The total number of pages in the document.",{"type":21,"tag":128,"props":282,"children":283},{},[284,290,292,298],{"type":21,"tag":34,"props":285,"children":287},{"className":286},[],[288],{"type":26,"value":289},"{{ date }}",{"type":26,"value":291},": The current date in the format ",{"type":21,"tag":34,"props":293,"children":295},{"className":294},[],[296],{"type":26,"value":297},"M/D/YY-H:MM am/pm",{"type":26,"value":299}," such as \"3/16/24, 2:04 PM\".",{"type":21,"tag":22,"props":301,"children":302},{},[303],{"type":26,"value":304},"This will allow you to generate a document that looks more like a printable version of a website, with page number and customized header and footer.",{"title":8,"searchDepth":59,"depth":59,"links":306},[],"content:guides:python:aiohttp:adding-a-custom-header-or-footer.md","guides/python/aiohttp/adding-a-custom-header-or-footer.md",{"_path":310,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":311,"description":312,"language":11,"library":6,"property":313,"output":13,"related":314,"default":7,"body":317,"_type":61,"_id":470,"_source":63,"_file":471,"_extension":65},"/guides/python/aiohttp/adding-a-text-watermark","Adding a text watermark","Learn how to add text watermarks to your generated PDF document using Python and the aiohttp library. With this guide, you'll be able to add watermarks on top of your generated PDFs easily with a quick request to PDFShift's API.","watermark",[315,316],"adding-an-image-watermark","protecting-the-generated-pdf",{"type":18,"children":318,"toc":468},[319,324,336,345,350,419,424,449,454,459],{"type":21,"tag":22,"props":320,"children":321},{},[322],{"type":26,"value":323},"In this guide, we'll walk you through the process of adding text watermarks to your PDF files, using PDFShift's API.",{"type":21,"tag":22,"props":325,"children":326},{},[327,329,334],{"type":26,"value":328},"Adding a watermark to your PDF can be done by adding the ",{"type":21,"tag":34,"props":330,"children":332},{"className":331},[],[333],{"type":26,"value":313},{"type":26,"value":335}," object to your query. Adding a text allows you to customize its content and PDFShift's API provides a few properties to help you customize the visual aspect, such as the font size, color, and position.",{"type":21,"tag":42,"props":337,"children":340},{"className":338,"code":339,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'watermark': {\n        'text': 'PROTECTED DOCUMENT',\n        'offset_x': 'center',\n        'offset_top': 'top'\n    }\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[341],{"type":21,"tag":34,"props":342,"children":343},{"__ignoreMap":8},[344],{"type":26,"value":339},{"type":21,"tag":22,"props":346,"children":347},{},[348],{"type":26,"value":349},"You can customize the text watermark by applying the following properties:",{"type":21,"tag":124,"props":351,"children":352},{},[353,364,375,386,397,408],{"type":21,"tag":128,"props":354,"children":355},{},[356,362],{"type":21,"tag":34,"props":357,"children":359},{"className":358},[],[360],{"type":26,"value":361},"font_size",{"type":26,"value":363},": The size of the text. An integer value in pixels. Defaults to 16.",{"type":21,"tag":128,"props":365,"children":366},{},[367,373],{"type":21,"tag":34,"props":368,"children":370},{"className":369},[],[371],{"type":26,"value":372},"font_family",{"type":26,"value":374}," : The font family to be used. Defaults to Helvetica.",{"type":21,"tag":128,"props":376,"children":377},{},[378,384],{"type":21,"tag":34,"props":379,"children":381},{"className":380},[],[382],{"type":26,"value":383},"font_color",{"type":26,"value":385}," : The color of the text. A hexadecimal color value. Defaults to '000000'.",{"type":21,"tag":128,"props":387,"children":388},{},[389,395],{"type":21,"tag":34,"props":390,"children":392},{"className":391},[],[393],{"type":26,"value":394},"font_opacity",{"type":26,"value":396}," : The opacity of the text. A float value between 0 and 100. Defaults to 100.",{"type":21,"tag":128,"props":398,"children":399},{},[400,406],{"type":21,"tag":34,"props":401,"children":403},{"className":402},[],[404],{"type":26,"value":405},"font_bold",{"type":26,"value":407},": A boolean to set the text as bold. Defaults to false.",{"type":21,"tag":128,"props":409,"children":410},{},[411,417],{"type":21,"tag":34,"props":412,"children":414},{"className":413},[],[415],{"type":26,"value":416},"font_italic",{"type":26,"value":418},": A boolean to set the text as italic. Defaults to false.",{"type":21,"tag":22,"props":420,"children":421},{},[422],{"type":26,"value":423},"You can also customize the position of the text watermark by applying the following properties:",{"type":21,"tag":124,"props":425,"children":426},{},[427,438],{"type":21,"tag":128,"props":428,"children":429},{},[430,436],{"type":21,"tag":34,"props":431,"children":433},{"className":432},[],[434],{"type":26,"value":435},"offset_x",{"type":26,"value":437},": The horizontal position of the text. Can be 'left', 'center', 'right', or a specific value in pixels. Defaults to 'center'.",{"type":21,"tag":128,"props":439,"children":440},{},[441,447],{"type":21,"tag":34,"props":442,"children":444},{"className":443},[],[445],{"type":26,"value":446},"offset_y",{"type":26,"value":448},": The vertical position of the text. Can be 'top', 'middle', 'bottom', or a specific value in pixels. Defaults to 'center'.",{"type":21,"tag":22,"props":450,"children":451},{},[452],{"type":26,"value":453},"For the offset positions, we accept a value in integer which will be translated to pixels, but you can also pass a unit such as 'px', 'in', 'cm', 'mm', 'pt'.",{"type":21,"tag":22,"props":455,"children":456},{},[457],{"type":26,"value":458},"For example:",{"type":21,"tag":42,"props":460,"children":463},{"className":461,"code":462,"language":47,"meta":8},[45],"params = {\n    \"source\": \"https://www.example.com\",\n    \"watermark\": {\n        \"text\": \"PROTECTED DOCUMENT\",\n        \"offset_x\": \"5cm\",\n        \"offset_top\": \"15mm\"\n    }\n}\n",[464],{"type":21,"tag":34,"props":465,"children":466},{"__ignoreMap":8},[467],{"type":26,"value":462},{"title":8,"searchDepth":59,"depth":59,"links":469},[],"content:guides:python:aiohttp:adding-a-text-watermark.md","guides/python/aiohttp/adding-a-text-watermark.md",{"_path":473,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":474,"description":475,"language":11,"library":6,"property":313,"output":13,"related":476,"default":7,"body":478,"_type":61,"_id":580,"_source":63,"_file":581,"_extension":65},"/guides/python/aiohttp/adding-an-image-watermark","Adding an image watermark","Discover how to effortlessly add image watermarks to PDFs using Python and the aiohttp library. Our guide shows you how to add images on top of your PDF to protect your document easily. This is easily done with a simple request to PDFShift's API.",[316,477],"adding-a-text-watermark",{"type":18,"children":479,"toc":578},[480,484,495,504,509,522,535,539,560,564,568],{"type":21,"tag":22,"props":481,"children":482},{},[483],{"type":26,"value":323},{"type":21,"tag":22,"props":485,"children":486},{},[487,488,493],{"type":26,"value":328},{"type":21,"tag":34,"props":489,"children":491},{"className":490},[],[492],{"type":26,"value":313},{"type":26,"value":494}," object to your query.\nThe advantage of providing an image is that you can add a visual stamp on top of each of your pages that are generated through PDFShift.",{"type":21,"tag":42,"props":496,"children":499},{"className":497,"code":498,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'watermark': {\n        'image': 'https://placekitten.com/200/300',\n        'offset_x': 'center',\n        'offset_top': 'top'\n    }\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[500],{"type":21,"tag":34,"props":501,"children":502},{"__ignoreMap":8},[503],{"type":26,"value":498},{"type":21,"tag":22,"props":505,"children":506},{},[507],{"type":26,"value":508},"The \"image\" parameter for the watermark can be used in two different values:",{"type":21,"tag":124,"props":510,"children":511},{},[512,517],{"type":21,"tag":128,"props":513,"children":514},{},[515],{"type":26,"value":516},"URL : A full URL to an image that will be used as the watermark.",{"type":21,"tag":128,"props":518,"children":519},{},[520],{"type":26,"value":521},"Base64 : A base64 encoded image that will be used as the watermark.",{"type":21,"tag":22,"props":523,"children":524},{},[525,527,533],{"type":26,"value":526},"Note that you can also rotate the image by passing the ",{"type":21,"tag":34,"props":528,"children":530},{"className":529},[],[531],{"type":26,"value":532},"rotate",{"type":26,"value":534}," parameter as a degree (or negative degree)",{"type":21,"tag":22,"props":536,"children":537},{},[538],{"type":26,"value":423},{"type":21,"tag":124,"props":540,"children":541},{},[542,551],{"type":21,"tag":128,"props":543,"children":544},{},[545,550],{"type":21,"tag":34,"props":546,"children":548},{"className":547},[],[549],{"type":26,"value":435},{"type":26,"value":437},{"type":21,"tag":128,"props":552,"children":553},{},[554,559],{"type":21,"tag":34,"props":555,"children":557},{"className":556},[],[558],{"type":26,"value":446},{"type":26,"value":448},{"type":21,"tag":22,"props":561,"children":562},{},[563],{"type":26,"value":453},{"type":21,"tag":22,"props":565,"children":566},{},[567],{"type":26,"value":458},{"type":21,"tag":42,"props":569,"children":573},{"className":570,"code":462,"language":572,"meta":8},[571],"language-json","json",[574],{"type":21,"tag":34,"props":575,"children":576},{"__ignoreMap":8},[577],{"type":26,"value":462},{"title":8,"searchDepth":59,"depth":59,"links":579},[],"content:guides:python:aiohttp:adding-an-image-watermark.md","guides/python/aiohttp/adding-an-image-watermark.md",{"_path":583,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":584,"description":585,"language":11,"library":6,"property":586,"output":13,"related":587,"default":7,"body":589,"_type":61,"_id":647,"_source":63,"_file":648,"_extension":65},"/guides/python/aiohttp/avoid-conversion-on-error","Avoid the conversion on error when loading the document","Learn how to avoid the conversion on error when loading the document using Python and the aiohttp library and relies on the PDFShift's API.","raise_for_status",[588],"convert-html-to-pdf-from-raw-html",{"type":18,"children":590,"toc":645},[591,596,616,625],{"type":21,"tag":22,"props":592,"children":593},{},[594],{"type":26,"value":595},"In this guide, we'll show you how to abort the conversion when loading the distant source does not return a 2XX response.",{"type":21,"tag":22,"props":597,"children":598},{},[599,601,606,608,614],{"type":26,"value":600},"When you're converting a document, you might want to avoid the conversion on error when loading the document. This can be done by setting the ",{"type":21,"tag":34,"props":602,"children":604},{"className":603},[],[605],{"type":26,"value":586},{"type":26,"value":607}," parameter to ",{"type":21,"tag":34,"props":609,"children":611},{"className":610},[],[612],{"type":26,"value":613},"True",{"type":26,"value":615}," in the request.",{"type":21,"tag":42,"props":617,"children":620},{"className":618,"code":619,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\n\n# You can get an API key at https://pdfshift.io\napi_key = 'sk_xxxxxxxxxxxx'\n\nparams = {\n    'source': 'https://www.httpstat.us/404',\n    'raise_for_status': True\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[621],{"type":21,"tag":34,"props":622,"children":623},{"__ignoreMap":8},[624],{"type":26,"value":619},{"type":21,"tag":22,"props":626,"children":627},{},[628,630,635,637,643],{"type":26,"value":629},"Passing ",{"type":21,"tag":34,"props":631,"children":633},{"className":632},[],[634],{"type":26,"value":586},{"type":26,"value":636}," to ",{"type":21,"tag":34,"props":638,"children":640},{"className":639},[],[641],{"type":26,"value":642},"true",{"type":26,"value":644}," will ensure that if PDFShift can not load your document, the conversion will fail with an error.",{"title":8,"searchDepth":59,"depth":59,"links":646},[],"content:guides:python:aiohttp:avoid-conversion-on-error.md","guides/python/aiohttp/avoid-conversion-on-error.md",{"_path":650,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":651,"description":652,"language":11,"library":6,"property":136,"output":13,"related":653,"default":7,"body":655,"_type":61,"_id":678,"_source":63,"_file":679,"_extension":65},"/guides/python/aiohttp/convert-html-to-pdf-from-a-url","Convert an HTML document to PDF from a URL","Learn how to easily convert HTML documents to PDF from a URL using Python and the aiohttp library. This how-to guide offers clear Python code examples that show developers how to implement this using the PDFShift API.",[588,654],"avoid-conversion-on-error",{"type":18,"children":656,"toc":676},[657,662,671],{"type":21,"tag":22,"props":658,"children":659},{},[660],{"type":26,"value":661},"In this guide, we'll show you how to convert HTML documents to PDFs using PDFShift's API. This is a straightforward process that can be accomplished with just a few lines of Python code.",{"type":21,"tag":42,"props":663,"children":666},{"className":664,"code":665,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[667],{"type":21,"tag":34,"props":668,"children":669},{"__ignoreMap":8},[670],{"type":26,"value":665},{"type":21,"tag":22,"props":672,"children":673},{},[674],{"type":26,"value":675},"With this Python script, you can effortlessly convert HTML documents from a URL to PDF files using PDFShift's API. Happy coding!",{"title":8,"searchDepth":59,"depth":59,"links":677},[],"content:guides:python:aiohttp:convert-html-to-pdf-from-a-url.md","guides/python/aiohttp/convert-html-to-pdf-from-a-url.md",{"_path":681,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":682,"description":683,"language":11,"library":6,"output":13,"related":684,"default":7,"body":686,"_type":61,"_id":771,"_source":63,"_file":772,"_extension":65},"/guides/python/aiohttp/convert-html-to-pdf-from-raw-html","Convert an HTML document to PDF from raw HTML","Learn how to to convert raw HTML document to PDF using Python and the aiohttp library. Our guide will explain you how to quickly convert documents with PDFShift's API.",[685],"convert-html-to-pdf-from-a-url",{"type":18,"children":687,"toc":769},[688,693,711,732,744,748,757],{"type":21,"tag":22,"props":689,"children":690},{},[691],{"type":26,"value":692},"In this guide, we'll show you how to convert an HTML document to PDF using Python and the aiohttp library.\nProviding the HTML document as raw as a lot of great advantages :",{"type":21,"tag":124,"props":694,"children":695},{},[696,701,706],{"type":21,"tag":128,"props":697,"children":698},{},[699],{"type":26,"value":700},"It avoids PDFShift to make a network request to fetch the HTML document.",{"type":21,"tag":128,"props":702,"children":703},{},[704],{"type":26,"value":705},"It allows you to convert HTML documents that are not publicly accessible.",{"type":21,"tag":128,"props":707,"children":708},{},[709],{"type":26,"value":710},"It improves the speed of the conversion",{"type":21,"tag":22,"props":712,"children":713},{},[714,716,722,724,730],{"type":26,"value":715},"If, on top of that, you can provide the styles and javascript also inline in the document (",{"type":21,"tag":34,"props":717,"children":719},{"className":718},[],[720],{"type":26,"value":721},"\u003Cstyle>",{"type":26,"value":723}," and ",{"type":21,"tag":34,"props":725,"children":727},{"className":726},[],[728],{"type":26,"value":729},"\u003Cscript>",{"type":26,"value":731}," tags), it will also drastically reduce the duration of the conversion.",{"type":21,"tag":22,"props":733,"children":734},{},[735,737,742],{"type":26,"value":736},"For converting a raw document, we use the same parameter as for the URL, which is the ",{"type":21,"tag":34,"props":738,"children":740},{"className":739},[],[741],{"type":26,"value":136},{"type":26,"value":743}," parameter.\nAll you have to do is provide an HTML document.",{"type":21,"tag":22,"props":745,"children":746},{},[747],{"type":26,"value":208},{"type":21,"tag":42,"props":749,"children":752},{"className":750,"code":751,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\n\n# You can get an API key at https://pdfshift.io\napi_key = 'sk_xxxxxxxxxxxx'\n\nparams = {\n    'source': '\u003Chtml>\u003Cbody>\u003Ch1>This will be a PDF document\u003C/h1>\u003Cp>This will generate a basic PDF to show how you can add raw HTML\u003C/body>\u003C/html>',\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[753],{"type":21,"tag":34,"props":754,"children":755},{"__ignoreMap":8},[756],{"type":26,"value":751},{"type":21,"tag":22,"props":758,"children":759},{},[760,762,767],{"type":26,"value":761},"Providing the ",{"type":21,"tag":34,"props":763,"children":765},{"className":764},[],[766],{"type":26,"value":136},{"type":26,"value":768}," parameter as a raw HTML document is by far the best recommended method to convert HTML documents in PDFShift as it reduce the amount of network requests, loading time of each documents (image, css, javascript, etc) and thus improve the conversion time.",{"title":8,"searchDepth":59,"depth":59,"links":770},[],"content:guides:python:aiohttp:convert-html-to-pdf-from-raw-html.md","guides/python/aiohttp/convert-html-to-pdf-from-raw-html.md",{"_path":774,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":775,"description":776,"language":11,"library":6,"property":777,"output":13,"related":778,"default":7,"body":780,"_type":61,"_id":827,"_source":63,"_file":828,"_extension":65},"/guides/python/aiohttp/define-a-time-limit","Define a time limit","Learn how to set a conversion time limit at PDFShift. This will allow you to define a maximum time for the conversion process to complete, and if the process takes longer than the defined time, the conversion will be aborted. This guides explains you how to achieve it using Python and the aiohttp library.","timeout",[779],"waiting-for-a-custom-element-to-be-ready",{"type":18,"children":781,"toc":825},[782,787,792,811,820],{"type":21,"tag":22,"props":783,"children":784},{},[785],{"type":26,"value":786},"In this guide, we'll show you how you can set a conversion time limit at PDFShift. This will allow you to define a maximum time for the conversion process to complete, and if the process takes longer than the defined time, the conversion will be aborted.",{"type":21,"tag":22,"props":788,"children":789},{},[790],{"type":26,"value":791},"In some cases, this can be useful if you want the request to not be too long and then handle failure on your end depending on the result.",{"type":21,"tag":22,"props":793,"children":794},{},[795,797,802,804,809],{"type":26,"value":796},"To do so, we use the ",{"type":21,"tag":34,"props":798,"children":800},{"className":799},[],[801],{"type":26,"value":777},{"type":26,"value":803}," property, which is the maximum time in ",{"type":21,"tag":197,"props":805,"children":806},{},[807],{"type":26,"value":808},"seconds",{"type":26,"value":810}," that the request is allowed to take. If the request takes longer than the defined time, the conversion will be aborted.",{"type":21,"tag":42,"props":812,"children":815},{"className":813,"code":814,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'timeout': 10\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[816],{"type":21,"tag":34,"props":817,"children":818},{"__ignoreMap":8},[819],{"type":26,"value":814},{"type":21,"tag":22,"props":821,"children":822},{},[823],{"type":26,"value":824},"In the above example, the conversion could fail if the conversion takes longer than 10 seconds.",{"title":8,"searchDepth":59,"depth":59,"links":826},[],"content:guides:python:aiohttp:define-a-time-limit.md","guides/python/aiohttp/define-a-time-limit.md",{"_path":830,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":831,"description":832,"language":11,"library":6,"property":833,"output":13,"default":7,"body":834,"_type":61,"_id":924,"_source":63,"_file":925,"_extension":65},"/guides/python/aiohttp/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","Learn how to export only a specific set of pages from a document using Python and the aiohttp library. This guide offers detailed steps with code samples in Python and the aiohttp library, highlighting how you can export only a specific set of pages from a document using PDFShift's API.","pages",{"type":18,"children":835,"toc":922},[836,841,852,857,862,904,909,913],{"type":21,"tag":22,"props":837,"children":838},{},[839],{"type":26,"value":840},"In this guide, we'll show you how to export only a specific set of pages from a document using Python and the aiohttp library to convert them to PDF using PDFShift's API.",{"type":21,"tag":22,"props":842,"children":843},{},[844,846,851],{"type":26,"value":845},"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":21,"tag":34,"props":847,"children":849},{"className":848},[],[850],{"type":26,"value":833},{"type":26,"value":40},{"type":21,"tag":22,"props":853,"children":854},{},[855],{"type":26,"value":856},"It behaves exactly like the page parameter you can see when you print a document from your browser.",{"type":21,"tag":22,"props":858,"children":859},{},[860],{"type":26,"value":861},"It accepts the following pattern:",{"type":21,"tag":124,"props":863,"children":864},{},[865,878,891],{"type":21,"tag":128,"props":866,"children":867},{},[868,870,876],{"type":26,"value":869},"A number, such as ",{"type":21,"tag":34,"props":871,"children":873},{"className":872},[],[874],{"type":26,"value":875},"2",{"type":26,"value":877},". This will print the page 2",{"type":21,"tag":128,"props":879,"children":880},{},[881,883,889],{"type":26,"value":882},"A range, such as ",{"type":21,"tag":34,"props":884,"children":886},{"className":885},[],[887],{"type":26,"value":888},"2-4",{"type":26,"value":890},". This will print the pages 2 to 4 (2, 3 and 4)",{"type":21,"tag":128,"props":892,"children":893},{},[894,896,902],{"type":26,"value":895},"A list, such as ",{"type":21,"tag":34,"props":897,"children":899},{"className":898},[],[900],{"type":26,"value":901},"2,4,5,9",{"type":26,"value":903},". This will print the pages 2, 4, 5 and 9",{"type":21,"tag":22,"props":905,"children":906},{},[907],{"type":26,"value":908},"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":21,"tag":22,"props":910,"children":911},{},[912],{"type":26,"value":208},{"type":21,"tag":42,"props":914,"children":917},{"className":915,"code":916,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[918],{"type":21,"tag":34,"props":919,"children":920},{"__ignoreMap":8},[921],{"type":26,"value":916},{"title":8,"searchDepth":59,"depth":59,"links":923},[],"content:guides:python:aiohttp:exporting-only-a-specific-set-of-pages.md","guides/python/aiohttp/exporting-only-a-specific-set-of-pages.md",{"_path":927,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":928,"description":929,"language":11,"library":6,"property":930,"output":13,"default":7,"body":931,"_type":61,"_id":1054,"_source":63,"_file":1055,"_extension":65},"/guides/python/aiohttp/generate-a-document-with-full-height","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 aiohttp library to help you generate full-height documents with PDFShift's API.","format",{"type":18,"children":932,"toc":1052},[933,938,958,967,972,983,1002,1007,1016],{"type":21,"tag":22,"props":934,"children":935},{},[936],{"type":26,"value":937},"In this guide, we'll show you how to generate a document with full height dynamically using Python and the aiohttp library to convert them to PDF using PDFShift's API.",{"type":21,"tag":22,"props":939,"children":940},{},[941,943,948,950,956],{"type":26,"value":942},"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":21,"tag":34,"props":944,"children":946},{"className":945},[],[947],{"type":26,"value":930},{"type":26,"value":949}," parameter to the request and passing it a custom \"auto\" value for the ",{"type":21,"tag":34,"props":951,"children":953},{"className":952},[],[954],{"type":26,"value":955},"{height}",{"type":26,"value":957}," part.",{"type":21,"tag":42,"props":959,"children":962},{"className":960,"code":961,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[963],{"type":21,"tag":34,"props":964,"children":965},{"__ignoreMap":8},[966],{"type":26,"value":961},{"type":21,"tag":22,"props":968,"children":969},{},[970],{"type":26,"value":971},"The format parameter can accept various values, such as 'Letter', 'Legal', 'Tabloid', 'Ledger', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5'.",{"type":21,"tag":22,"props":973,"children":974},{},[975,977],{"type":26,"value":976},"But it can also accept a custom values that is defined per the width and height as follow: ",{"type":21,"tag":34,"props":978,"children":980},{"className":979},[],[981],{"type":26,"value":982},"{width}x{height}",{"type":21,"tag":22,"props":984,"children":985},{},[986,988,994,995,1000],{"type":26,"value":987},"Both ",{"type":21,"tag":34,"props":989,"children":991},{"className":990},[],[992],{"type":26,"value":993},"width",{"type":26,"value":723},{"type":21,"tag":34,"props":996,"children":998},{"className":997},[],[999],{"type":26,"value":147},{"type":26,"value":1001}," are pixel value by default, but if you precise the unit (in \"cm\", \"mm\", \"in\" or \"pt\"). That unit will be used instead.",{"type":21,"tag":22,"props":1003,"children":1004},{},[1005],{"type":26,"value":1006},"For instance, you can set a format of:",{"type":21,"tag":42,"props":1008,"children":1011},{"className":1009,"code":1010,"language":572,"meta":8},[571],"{\n    \"source\": \"https://www.example.com\",\n    \"format\": \"21cmx29,7cm\"\n}\n",[1012],{"type":21,"tag":34,"props":1013,"children":1014},{"__ignoreMap":8},[1015],{"type":26,"value":1010},{"type":21,"tag":22,"props":1017,"children":1018},{},[1019,1021,1026,1028,1034,1036,1042,1044,1050],{"type":26,"value":1020},"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":21,"tag":34,"props":1022,"children":1024},{"className":1023},[],[1025],{"type":26,"value":955},{"type":26,"value":1027}," value to ",{"type":21,"tag":34,"props":1029,"children":1031},{"className":1030},[],[1032],{"type":26,"value":1033},"auto",{"type":26,"value":1035},".\nSo, instead of setting a fixed height such as ",{"type":21,"tag":34,"props":1037,"children":1039},{"className":1038},[],[1040],{"type":26,"value":1041},"'format': '1280x1024'",{"type":26,"value":1043},", you can set ",{"type":21,"tag":34,"props":1045,"children":1047},{"className":1046},[],[1048],{"type":26,"value":1049},"'format': '1280xauto'",{"type":26,"value":1051}," and the height will be calculated based on the content of the page.",{"title":8,"searchDepth":59,"depth":59,"links":1053},[],"content:guides:python:aiohttp:generate-a-document-with-full-height.md","guides/python/aiohttp/generate-a-document-with-full-height.md",{"_path":1057,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1058,"description":1059,"language":11,"library":6,"property":1060,"output":13,"related":1061,"default":7,"body":1063,"_type":61,"_id":1097,"_source":63,"_file":1098,"_extension":65},"/guides/python/aiohttp/loading-css-from-a-string","Loading CSS from a string","Follow this guide to load custom CSS as a given string when converting an HTML document to PDF with PDFShift's API. This guide provides Python code samples with the aiohttp library.","css",[1062,73,74,75],"adding-a-custom-header-or-footer",{"type":18,"children":1064,"toc":1095},[1065,1070,1075,1084],{"type":21,"tag":22,"props":1066,"children":1067},{},[1068],{"type":26,"value":1069},"In this guide, we'll show you how to load custom CSS as a given string when converting an HTML document to PDF using PDFShift's API. This allows you to add custom CSS to your page to customize the output of your generated PDF.",{"type":21,"tag":22,"props":1071,"children":1072},{},[1073],{"type":26,"value":1074},"It can be interesting to be able to set a custom CSS value to adjust the rendering of your page specifically when exporting the document to PDF.\nThis allows you to keep a standard look and feel to your users, but adjust some areas when sending that same document to PDFShift to get back a PDF.",{"type":21,"tag":42,"props":1076,"children":1079},{"className":1077,"code":1078,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'css': 'body { background-color: #f00; }'\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[1080],{"type":21,"tag":34,"props":1081,"children":1082},{"__ignoreMap":8},[1083],{"type":26,"value":1078},{"type":21,"tag":22,"props":1085,"children":1086},{},[1087,1088,1093],{"type":26,"value":115},{"type":21,"tag":34,"props":1089,"children":1091},{"className":1090},[],[1092],{"type":26,"value":1060},{"type":26,"value":1094}," parameter accepts either a string or a URL. It will be used as the CSS for the page when converting it to PDF. This allows you to set a custom CSS value to adjust the rendering of your page specifically when exporting the document to PDF.",{"title":8,"searchDepth":59,"depth":59,"links":1096},[],"content:guides:python:aiohttp:loading-css-from-a-string.md","guides/python/aiohttp/loading-css-from-a-string.md",{"_path":1100,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1101,"description":1102,"language":11,"library":6,"property":1060,"output":13,"related":1103,"default":7,"body":1104,"_type":61,"_id":1141,"_source":63,"_file":1142,"_extension":65},"/guides/python/aiohttp/loading-css-from-a-url","Loading CSS from a URL","This guides shows you how to add a custom CSS from an URL onto your document to customize the output of your generated PDF. Follow this guides to learn how to do it using Python and the aiohttp library and see how it can quickly be implemented using the PDFShift's API.",[1062,72,74,75],{"type":18,"children":1105,"toc":1139},[1106,1111,1115,1120,1129],{"type":21,"tag":22,"props":1107,"children":1108},{},[1109],{"type":26,"value":1110},"In this guide, we'll show you how to load custom CSS as a URL when converting an HTML document to PDF using PDFShift's API. This allows you to add custom CSS to your page to customize the output of your generated PDF.",{"type":21,"tag":22,"props":1112,"children":1113},{},[1114],{"type":26,"value":1074},{"type":21,"tag":22,"props":1116,"children":1117},{},[1118],{"type":26,"value":1119},"Moreover, adding a URL can be easier to do than passing the raw CSS content, as it allows you to later modify that CSS without having to modify the query made to PDFShift.",{"type":21,"tag":42,"props":1121,"children":1124},{"className":1122,"code":1123,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'css': \"https://www.example.com/public/style/print.css\"\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[1125],{"type":21,"tag":34,"props":1126,"children":1127},{"__ignoreMap":8},[1128],{"type":26,"value":1123},{"type":21,"tag":22,"props":1130,"children":1131},{},[1132,1133,1138],{"type":26,"value":115},{"type":21,"tag":34,"props":1134,"children":1136},{"className":1135},[],[1137],{"type":26,"value":1060},{"type":26,"value":1094},{"title":8,"searchDepth":59,"depth":59,"links":1140},[],"content:guides:python:aiohttp:loading-css-from-a-url.md","guides/python/aiohttp/loading-css-from-a-url.md",{"_path":1144,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1145,"description":1146,"language":11,"library":6,"property":1147,"output":13,"related":1148,"default":7,"body":1149,"_type":61,"_id":1183,"_source":63,"_file":1184,"_extension":65},"/guides/python/aiohttp/loading-javascript-from-a-string","Loading Javascript from a string","Follow this guide to learn how to add custom javascript to your page to customize the output of your generated PDF. This allows you to modify elements on the page, add or remove content, etc. This guide uses Python and the aiohttp library and relies on the PDFShift's API.","javascript",[1062,72,73,75],{"type":18,"children":1150,"toc":1181},[1151,1156,1161,1170],{"type":21,"tag":22,"props":1152,"children":1153},{},[1154],{"type":26,"value":1155},"In this guide, we'll show you how to load custom javascript code as a given string when converting an HTML document to PDF using PDFShift's API. This allows you to add custom JS to your page to customize the output of your generated PDF.",{"type":21,"tag":22,"props":1157,"children":1158},{},[1159],{"type":26,"value":1160},"It can be interesting to be able to set a custom JS value to adjust the rendering of your page specifically when exporting the document to PDF.\nThis allows you to keep a standard look and feel to your users, but adjust some areas when sending that same document to PDFShift to get back a PDF.",{"type":21,"tag":42,"props":1162,"children":1165},{"className":1163,"code":1164,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'javascript': 'document.querySelector(\"h1\").style.color = \"red\";'\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[1166],{"type":21,"tag":34,"props":1167,"children":1168},{"__ignoreMap":8},[1169],{"type":26,"value":1164},{"type":21,"tag":22,"props":1171,"children":1172},{},[1173,1174,1179],{"type":26,"value":115},{"type":21,"tag":34,"props":1175,"children":1177},{"className":1176},[],[1178],{"type":26,"value":1147},{"type":26,"value":1180}," parameter accepts either a string or a URL. It will be used as the javascript for the page when converting it to PDF. This allows you to set a custom JS value to adjust the rendering of your page specifically when exporting the document to PDF.",{"title":8,"searchDepth":59,"depth":59,"links":1182},[],"content:guides:python:aiohttp:loading-javascript-from-a-string.md","guides/python/aiohttp/loading-javascript-from-a-string.md",{"_path":1186,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1187,"description":1188,"language":11,"library":6,"property":1147,"output":13,"related":1189,"default":7,"body":1190,"_type":61,"_id":1229,"_source":63,"_file":1230,"_extension":65},"/guides/python/aiohttp/loading-javascript-from-a-url","Loading Javascript from a URL","Follow this guide to add custom javascript to your page before converting it to PDF. Using a URL allows you to later be able to change the content of the javascript without having to update the query made to PDFShift. Learn how you can implement this using Python and the aiohttp library to call the PDFShift's API.",[1062,72,73,74],{"type":18,"children":1191,"toc":1227},[1192,1197,1202,1207,1216],{"type":21,"tag":22,"props":1193,"children":1194},{},[1195],{"type":26,"value":1196},"In this guide, we'll show you how to load custom javascript as a URL when converting an HTML document to PDF using PDFShift's API. This allows you to add custom Js to your page to customize the output of your generated PDF.",{"type":21,"tag":22,"props":1198,"children":1199},{},[1200],{"type":26,"value":1201},"It can be interesting to be able to set a custom javascript value to adjust the rendering of your page specifically when exporting the document to PDF.\nThis allows you to keep a standard look and feel to your users, but adjust some areas when sending that same document to PDFShift to get back a PDF.",{"type":21,"tag":22,"props":1203,"children":1204},{},[1205],{"type":26,"value":1206},"Moreover, adding a URL can be easier to do than passing the raw javascript content, as it allows you to later modify that javascript without having to modify the query made to PDFShift.",{"type":21,"tag":42,"props":1208,"children":1211},{"className":1209,"code":1210,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'javascript': 'https://www.example.com/custom.js'\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[1212],{"type":21,"tag":34,"props":1213,"children":1214},{"__ignoreMap":8},[1215],{"type":26,"value":1210},{"type":21,"tag":22,"props":1217,"children":1218},{},[1219,1220,1225],{"type":26,"value":115},{"type":21,"tag":34,"props":1221,"children":1223},{"className":1222},[],[1224],{"type":26,"value":1147},{"type":26,"value":1226}," parameter accepts either a string or a URL. It will be used as the javascript for the page when converting it to PDF. This allows you to set a custom javascript value to adjust the rendering of your page specifically when exporting the document to PDF.",{"title":8,"searchDepth":59,"depth":59,"links":1228},[],"content:guides:python:aiohttp:loading-javascript-from-a-url.md","guides/python/aiohttp/loading-javascript-from-a-url.md",{"_path":1232,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1233,"description":1234,"language":11,"library":6,"property":1235,"output":13,"related":1236,"default":7,"body":1237,"_type":61,"_id":1398,"_source":63,"_file":1399,"_extension":65},"/guides/python/aiohttp/protecting-the-generated-pdf","Protecting the generated PDF","Learn how to protect your generated PDF with encryption for owner and user, and for choosing who can modify, print and/or copy the generated PDF. This guides explains you to do it using Python and the aiohttp library and relies on the PDFShift's API.","protection",[315,477],{"type":18,"children":1238,"toc":1396},[1239,1244,1249,1261,1266,1275,1287,1298,1386],{"type":21,"tag":22,"props":1240,"children":1241},{},[1242],{"type":26,"value":1243},"In this guide, we'll show you how you can protect your generated PDF with encryption for owner and user, and for choosing who can modify, print and/or copy the generated PDF. This guides explains you to do it using Python and the aiohttp library and relies on the PDFShift's API.",{"type":21,"tag":22,"props":1245,"children":1246},{},[1247],{"type":26,"value":1248},"One of the most useful feature here is the ability to set a password for the owner and the user of the PDF. This allows you to protect your document from anyone and restrict its access to only a few people.",{"type":21,"tag":22,"props":1250,"children":1251},{},[1252,1254,1259],{"type":26,"value":1253},"PDFShift allows you to do this easily by adding the ",{"type":21,"tag":34,"props":1255,"children":1257},{"className":1256},[],[1258],{"type":26,"value":1235},{"type":26,"value":1260}," object to your query.",{"type":21,"tag":22,"props":1262,"children":1263},{},[1264],{"type":26,"value":1265},"Here's a sample:",{"type":21,"tag":42,"props":1267,"children":1270},{"className":1268,"code":1269,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'protection': {\n        'owner_password': 'owner_password',\n        'user_password': 'user_password',\n        'no_print': True,\n        'no_modify': True\n    }\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[1271],{"type":21,"tag":34,"props":1272,"children":1273},{"__ignoreMap":8},[1274],{"type":26,"value":1269},{"type":21,"tag":22,"props":1276,"children":1277},{},[1278,1280,1285],{"type":26,"value":1279},"Adding the ",{"type":21,"tag":34,"props":1281,"children":1283},{"className":1282},[],[1284],{"type":26,"value":1235},{"type":26,"value":1286}," object to your query will tell PDFShift to generate a PDF that will be password protected.",{"type":21,"tag":22,"props":1288,"children":1289},{},[1290,1291,1296],{"type":26,"value":115},{"type":21,"tag":34,"props":1292,"children":1294},{"className":1293},[],[1295],{"type":26,"value":1235},{"type":26,"value":1297}," object accepts the following parameters:",{"type":21,"tag":124,"props":1299,"children":1300},{},[1301,1312,1323,1334,1352,1369],{"type":21,"tag":128,"props":1302,"children":1303},{},[1304,1310],{"type":21,"tag":34,"props":1305,"children":1307},{"className":1306},[],[1308],{"type":26,"value":1309},"author",{"type":26,"value":1311}," : The name of the author in the PDF metadata.",{"type":21,"tag":128,"props":1313,"children":1314},{},[1315,1321],{"type":21,"tag":34,"props":1316,"children":1318},{"className":1317},[],[1319],{"type":26,"value":1320},"owner_password",{"type":26,"value":1322},": The password set for the owner.",{"type":21,"tag":128,"props":1324,"children":1325},{},[1326,1332],{"type":21,"tag":34,"props":1327,"children":1329},{"className":1328},[],[1330],{"type":26,"value":1331},"user_password",{"type":26,"value":1333},": The password set for the user.",{"type":21,"tag":128,"props":1335,"children":1336},{},[1337,1343,1345,1350],{"type":21,"tag":34,"props":1338,"children":1340},{"className":1339},[],[1341],{"type":26,"value":1342},"no_print",{"type":26,"value":1344},": If set to ",{"type":21,"tag":34,"props":1346,"children":1348},{"className":1347},[],[1349],{"type":26,"value":613},{"type":26,"value":1351},", the user won't be able to print the PDF. (Only the owner)",{"type":21,"tag":128,"props":1353,"children":1354},{},[1355,1361,1362,1367],{"type":21,"tag":34,"props":1356,"children":1358},{"className":1357},[],[1359],{"type":26,"value":1360},"no_modify",{"type":26,"value":1344},{"type":21,"tag":34,"props":1363,"children":1365},{"className":1364},[],[1366],{"type":26,"value":613},{"type":26,"value":1368},", the user won't be able to modify the PDF. (Only the owner)",{"type":21,"tag":128,"props":1370,"children":1371},{},[1372,1378,1379,1384],{"type":21,"tag":34,"props":1373,"children":1375},{"className":1374},[],[1376],{"type":26,"value":1377},"no_copy",{"type":26,"value":1344},{"type":21,"tag":34,"props":1380,"children":1382},{"className":1381},[],[1383],{"type":26,"value":613},{"type":26,"value":1385},", the user won't be able to copy the content of the PDF. (Only the owner)",{"type":21,"tag":22,"props":1387,"children":1388},{},[1389,1394],{"type":21,"tag":197,"props":1390,"children":1391},{},[1392],{"type":26,"value":1393},"IMPORTANT",{"type":26,"value":1395},":\nIt is important to note that most PDF reader don't respect the protection parameter. For instance, if you set the user_password to none (allowing anyone to view the PDF) but set the owner_password and block the modify, print and copy, most PDF reader will still allow user (and not owners) to modify, print and copy the PDF. This is a limitation of the PDF format and not PDFShift.",{"title":8,"searchDepth":59,"depth":59,"links":1397},[],"content:guides:python:aiohttp:protecting-the-generated-pdf.md","guides/python/aiohttp/protecting-the-generated-pdf.md",{"_path":1401,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1402,"description":1403,"language":11,"library":6,"property":1404,"output":13,"related":1405,"default":7,"body":1408,"_type":61,"_id":1496,"_source":63,"_file":1497,"_extension":65},"/guides/python/aiohttp/receive-a-webhook-event","Receive a webhook event","Receive a notification via a POST request on your server once the conversion was done. This allows you to trigger a massive amount of conversion without having to wait on their results, and get notified once they are done. This guides will show you how to receive webhook events in Python and the aiohttp library to call the PDFShift's API.","webhook",[1406,1407],"save-your-pdf-online-and-get-back-a-url","save-your-pdf-to-your-amazon-s3-bucket",{"type":18,"children":1409,"toc":1494},[1410,1415,1420,1424,1433,1438,1443,1448,1457,1462,1471,1476,1481,1489],{"type":21,"tag":22,"props":1411,"children":1412},{},[1413],{"type":26,"value":1414},"In this guide, we'll show you how you can receive a notification via a POST request on your server once the conversion was done. This allows you to trigger a massive amount of conversion without having to wait on their results, and get notified once they are done.",{"type":21,"tag":22,"props":1416,"children":1417},{},[1418],{"type":26,"value":1419},"For this guide, we are going to use the \"webhook\" parameter when sending a request to PDFShift. It expects a URL to which the POST request will be sent once the conversion is done.",{"type":21,"tag":22,"props":1421,"children":1422},{},[1423],{"type":26,"value":1265},{"type":21,"tag":42,"props":1425,"children":1428},{"className":1426,"code":1427,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'webhook': 'https://enyygzdj8jy9b.x.pipedream.net/'\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            print('The PDF document was generated and you will receive an event on your webhook once it is done.')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[1429],{"type":21,"tag":34,"props":1430,"children":1431},{"__ignoreMap":8},[1432],{"type":26,"value":1427},{"type":21,"tag":22,"props":1434,"children":1435},{},[1436],{"type":26,"value":1437},"(Please note that the webhook requires a valid API key)",{"type":21,"tag":22,"props":1439,"children":1440},{},[1441],{"type":26,"value":1442},"We used Requestbin.com to generate a endpoint that will receive our POST event, but you can set your own endpoint with custom parameters.",{"type":21,"tag":22,"props":1444,"children":1445},{},[1446],{"type":26,"value":1447},"When sending the above request to PDFShift, the response will be immediate with a status code of 202 (Request accepted), with the following JSON body:",{"type":21,"tag":42,"props":1449,"children":1452},{"className":1450,"code":1451,"language":572,"meta":8},[571],"{\n    \"success\":true,\n    \"queued\":true\n}\n",[1453],{"type":21,"tag":34,"props":1454,"children":1455},{"__ignoreMap":8},[1456],{"type":26,"value":1451},{"type":21,"tag":22,"props":1458,"children":1459},{},[1460],{"type":26,"value":1461},"Once the conversion is actually done at PDFShift, you will receive a POST request containing the following JSON body:",{"type":21,"tag":42,"props":1463,"children":1466},{"className":1464,"code":1465,"language":572,"meta":8},[571],"{\n    \"success\": true,\n    \"url\": \"https://pdfshift.s3.amazonaws.com/d/2/2024-03/39775239d74d4accbabb709800f034d2/8a3ec881-fa69-4059-9c71-0f40c633317e.pdf\",\n    \"filesize\": 34980,\n    \"duration\": 1058,\n    \"response\": {\n        \"status-code\": 200,\n        \"content-length\": 0,\n        \"requests\": 0,\n        \"duration\": 934.5173301696777\n    },\n    \"executed\": \"2024-03-06T09:10:10.981098\",\n    \"pdf_pages\": 1\n}\n",[1467],{"type":21,"tag":34,"props":1468,"children":1469},{"__ignoreMap":8},[1470],{"type":26,"value":1465},{"type":21,"tag":22,"props":1472,"children":1473},{},[1474],{"type":26,"value":1475},"It might occur that the conversion fails, for instance if PDFShift can't access the page or if there is any parameter that cause the loading page to fail (page taking to long to load, etc).",{"type":21,"tag":22,"props":1477,"children":1478},{},[1479],{"type":26,"value":1480},"In this case, the POST request will contain the following JSON body:",{"type":21,"tag":42,"props":1482,"children":1484},{"className":1483,"code":8,"language":572,"meta":8},[571],[1485],{"type":21,"tag":34,"props":1486,"children":1487},{"__ignoreMap":8},[1488],{"type":26,"value":8},{"type":21,"tag":22,"props":1490,"children":1491},{},[1492],{"type":26,"value":1493},"This can be useful if you don't need to wait for the conversion to continue your process. For instance, when generating all the invoices from last month's payment, you can trigger the conversions and save the PDF on your webhook's destination. This way, you can continue your process without having to wait for the conversion to be done.",{"title":8,"searchDepth":59,"depth":59,"links":1495},[],"content:guides:python:aiohttp:receive-a-webhook-event.md","guides/python/aiohttp/receive-a-webhook-event.md",{"_path":1499,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1500,"description":1501,"language":11,"library":6,"property":1502,"output":13,"related":1503,"default":7,"body":1505,"_type":61,"_id":1586,"_source":63,"_file":1587,"_extension":65},"/guides/python/aiohttp/save-your-pdf-online-and-get-back-a-url","Save your PDF online and get back a URL","This guides shows you how can generate a PDF document from HTML and get back an URL instead of the raw PDF. This allows you to share the link directly to your users or redirect them to that page. Learn how you can achieve it using Python and the aiohttp library to call PDFShift's API.","filename",[1407,1504],"receive-a-webhook-event",{"type":18,"children":1506,"toc":1584},[1507,1512,1524,1533,1552,1557,1566,1575],{"type":21,"tag":22,"props":1508,"children":1509},{},[1510],{"type":26,"value":1511},"In this guide, we'll show you how you can generate a PDF document from HTML and get back an URL instead of the raw PDF. This allows you to share the link directly to your users or redirect them to that page.",{"type":21,"tag":22,"props":1513,"children":1514},{},[1515,1517,1522],{"type":26,"value":1516},"To do so, we are going to pass the ",{"type":21,"tag":34,"props":1518,"children":1520},{"className":1519},[],[1521],{"type":26,"value":1502},{"type":26,"value":1523}," parameter to the request. It expects a string that will be the name of the file once it is saved on our servers.",{"type":21,"tag":42,"props":1525,"children":1528},{"className":1526,"code":1527,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'filename': 'example.pdf'\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            print('The PDF document was generated and is available online via the url in the response')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[1529],{"type":21,"tag":34,"props":1530,"children":1531},{"__ignoreMap":8},[1532],{"type":26,"value":1527},{"type":21,"tag":22,"props":1534,"children":1535},{},[1536,1538,1543,1545,1550],{"type":26,"value":1537},"In the above example, we used the ",{"type":21,"tag":34,"props":1539,"children":1541},{"className":1540},[],[1542],{"type":26,"value":1502},{"type":26,"value":1544}," parameter to specify the name of the file once it is saved on our servers. The response will convert the document ",{"type":21,"tag":197,"props":1546,"children":1547},{},[1548],{"type":26,"value":1549},"but return a JSON response",{"type":26,"value":1551}," instead of the raw PDF.",{"type":21,"tag":22,"props":1553,"children":1554},{},[1555],{"type":26,"value":1556},"The body of the response will be similar to this:",{"type":21,"tag":42,"props":1558,"children":1561},{"className":1559,"code":1560,"language":572,"meta":8},[571],"{\n    \"success\": true,\n    \"url\": \"https://pdfshift.s3.amazonaws.com/d/2/2024-03/c9c2d3e536ff42d892f06fdda6bb1ff7/example.pdf\",\n    \"filesize\": 34980,\n    \"duration\": 1237,\n    \"response\": {\n        \"status-code\": 200,\n        \"content-length\": 0,\n        \"requests\": 0,\n        \"duration\": 1085.6739225387573\n    },\n    \"executed\": \"2024-03-06T10:05:51.516413\",\n    \"pdf_pages\": 1\n}\n",[1562],{"type":21,"tag":34,"props":1563,"children":1564},{"__ignoreMap":8},[1565],{"type":26,"value":1560},{"type":21,"tag":22,"props":1567,"children":1568},{},[1569,1573],{"type":21,"tag":197,"props":1570,"children":1571},{},[1572],{"type":26,"value":201},{"type":26,"value":1574},": Using the filename does save your document on our S3 storage for 2 days. After two days, the document is automatically deleted.",{"type":21,"tag":22,"props":1576,"children":1577},{},[1578,1582],{"type":21,"tag":197,"props":1579,"children":1580},{},[1581],{"type":26,"value":201},{"type":26,"value":1583},": Since we store your documents on our server, this command is not recommended if you want to be HIPAA compliant.",{"title":8,"searchDepth":59,"depth":59,"links":1585},[],"content:guides:python:aiohttp:save-your-pdf-online-and-get-back-a-url.md","guides/python/aiohttp/save-your-pdf-online-and-get-back-a-url.md",{"_path":1589,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1590,"description":1591,"language":11,"library":6,"property":1592,"output":13,"related":1593,"default":7,"body":1594,"_type":61,"_id":1695,"_source":63,"_file":1696,"_extension":65},"/guides/python/aiohttp/save-your-pdf-to-your-amazon-s3-bucket","Save your PDF to your Amazon S3 Bucket","This guides shows you how can generate a PDF document from HTML with PDFShift's API and save it to your own Amazon S3 bucket. This allows you to generate document and automate actions once the document has been created on your bucket. This guides explains you how to do it using Python and the aiohttp library.","s3_destination",[1406,1504],{"type":18,"children":1595,"toc":1693},[1596,1601,1606,1611,1620,1632,1641,1653,1662,1667,1676,1681],{"type":21,"tag":22,"props":1597,"children":1598},{},[1599],{"type":26,"value":1600},"In this guide, we'll show you how you can generate a PDF document from HTML with PDFShift's API and save it to your own Amazon S3 bucket. This allows you to generate document and automate actions once the document has been created on your bucket.",{"type":21,"tag":22,"props":1602,"children":1603},{},[1604],{"type":26,"value":1605},"First, you'll need to set up permissions in your bucket to allow PDFShift to write in it.",{"type":21,"tag":22,"props":1607,"children":1608},{},[1609],{"type":26,"value":1610},"We crafted a very simple policy that only does what is required and nothing more.\nYou can copy/paste it and apply it on your bucket, but don't forget to change the name of your bucket:",{"type":21,"tag":42,"props":1612,"children":1615},{"className":1613,"code":1614,"language":572,"meta":8},[571],"{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [{\n        \"Sid\": \"Allows PDFShift.io to write the generated PDF in this bucket.\",\n        \"Effect\": \"Allow\",\n        \"Principal\": {\n            \"AWS\": [\"arn:aws:iam::804461045055:user/pdfshift\"]\n        },\n        \"Action\": [\"s3:PutObject\"],\n        \"Resource\": \"arn:aws:s3:::DOC-EXAMPLE-BUCKET/*\"\n    }]\n}\n",[1616],{"type":21,"tag":34,"props":1617,"children":1618},{"__ignoreMap":8},[1619],{"type":26,"value":1614},{"type":21,"tag":22,"props":1621,"children":1622},{},[1623,1625,1630],{"type":26,"value":1624},"Once this is done, you can send a request to PDFShift by adding the ",{"type":21,"tag":34,"props":1626,"children":1628},{"className":1627},[],[1629],{"type":26,"value":1592},{"type":26,"value":1631}," parameter. It takes the full s3 bucket as a URL.\nOnce the conversion will be done, PDFShift will",{"type":21,"tag":42,"props":1633,"children":1636},{"className":1634,"code":1635,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    's3_destination': 's3://DOC-EXAMPLE-BUCKET/test/example.pdf'\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            print('The PDF document was generated and saved to your S3 Bucket')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[1637],{"type":21,"tag":34,"props":1638,"children":1639},{"__ignoreMap":8},[1640],{"type":26,"value":1635},{"type":21,"tag":22,"props":1642,"children":1643},{},[1644,1646,1651],{"type":26,"value":1645},"Once the conversion is done, PDFShift will save the content to your given ",{"type":21,"tag":34,"props":1647,"children":1649},{"className":1648},[],[1650],{"type":26,"value":1592},{"type":26,"value":1652}," path and will return a response with a JSON body, such as:",{"type":21,"tag":42,"props":1654,"children":1657},{"className":1655,"code":1656,"language":572,"meta":8},[571],"{\n    \"success\": true,\n    \"url\": \"https://DOC-EXAMPLE-BUCKET.s3.amazonaws.com/test/example.pdf\",\n    \"filesize\": 34980,\n    \"duration\": 1423,\n    \"response\": {\n        \"status-code\": 200,\n        \"content-length\": 0,\n        \"requests\": 0,\n        \"duration\": 1263.254446029663\n    },\n    \"executed\": \"2024-03-06T10:13:33.154960\",\n    \"pdf_pages\": 1\n}\n",[1658],{"type":21,"tag":34,"props":1659,"children":1660},{"__ignoreMap":8},[1661],{"type":26,"value":1656},{"type":21,"tag":22,"props":1663,"children":1664},{},[1665],{"type":26,"value":1666},"In the event you haven't setup the permissions properly, PDFShift will fail with the following JSON body error:",{"type":21,"tag":42,"props":1668,"children":1671},{"className":1669,"code":1670,"language":572,"meta":8},[571],"{\n    \"success\": false,\n    \"error\": \"The S3 destination you provided can not be accessed.\",\n    \"code\": 400\n}\n",[1672],{"type":21,"tag":34,"props":1673,"children":1674},{"__ignoreMap":8},[1675],{"type":26,"value":1670},{"type":21,"tag":22,"props":1677,"children":1678},{},[1679],{"type":26,"value":1680},"This features is really interesting as it allows you to not have to write the logic once the file was generated if your intention is to backup the file (such as an invoice, a report or saving a document).",{"type":21,"tag":22,"props":1682,"children":1683},{},[1684,1686,1691],{"type":26,"value":1685},"You can couple it with the ",{"type":21,"tag":34,"props":1687,"children":1689},{"className":1688},[],[1690],{"type":26,"value":1404},{"type":26,"value":1692}," parameter to increase the speed of processing. By doing so, PDFShift will treat your conversion request asynchronously and save the document in the given path. The request made to PDFShift will be immediate.",{"title":8,"searchDepth":59,"depth":59,"links":1694},[],"content:guides:python:aiohttp:save-your-pdf-to-your-amazon-s3-bucket.md","guides/python/aiohttp/save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":1698,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1699,"description":1700,"language":11,"library":6,"property":1701,"output":13,"related":1702,"default":7,"body":1704,"_type":61,"_id":1732,"_source":63,"_file":1733,"_extension":65},"/guides/python/aiohttp/send-custom-http-headers","Send custom HTTP headers","Learn how to add custom HTTP headers when requesting an URL to be converted in PDF with PDFShift's API. It allows you to add specific headers that your backend can check against to authenticate a query before converting it to PDF. This guide explains you how using Python and the aiohttp library.","http_headers",[16,1703],"accessing-secured-pages",{"type":18,"children":1705,"toc":1730},[1706,1711,1716,1725],{"type":21,"tag":22,"props":1707,"children":1708},{},[1709],{"type":26,"value":1710},"In this guide, we'll walk you through the process of sending custom HTTP headers when requesting an URL to be converted to PDF using PDFShift's API.",{"type":21,"tag":22,"props":1712,"children":1713},{},[1714],{"type":26,"value":1715},"This can be useful to pass custom parameters to your server. It can help for instance to identify from where is coming the request, and add some extra layer of security.",{"type":21,"tag":42,"props":1717,"children":1720},{"className":1718,"code":1719,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'http_headers': {\n        'x-custom-header': 'custom-value',\n        'Authorization': 'Bearer {token}'  # This allows you to authenticate PDFShift to your service in a custom way\n    }\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[1721],{"type":21,"tag":34,"props":1722,"children":1723},{"__ignoreMap":8},[1724],{"type":26,"value":1719},{"type":21,"tag":22,"props":1726,"children":1727},{},[1728],{"type":26,"value":1729},"This allows you to set specific HTTP headers that will be send along with the request PDFShift will make to your server.\nIt can be helpful to authenticate the request that your backend can check against before converting it to PDF.",{"title":8,"searchDepth":59,"depth":59,"links":1731},[],"content:guides:python:aiohttp:send-custom-http-headers.md","guides/python/aiohttp/send-custom-http-headers.md",{"_path":1735,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1736,"description":1737,"language":11,"library":6,"property":1738,"output":13,"related":1739,"default":7,"body":1740,"_type":61,"_id":1833,"_source":63,"_file":1834,"_extension":65},"/guides/python/aiohttp/using-cookies","Using cookies to convert HTML documents to PDF","Learn how to add custom Cookies when requesting an URL to be converted in PDF with PDFShift's API. It allows you to pursue an active session for instance, that will authenticate the request as a specific user before converting the page to PDF. This guide explains you how using Python and the aiohttp library.","cookies",[15,1703],{"type":18,"children":1741,"toc":1831},[1742,1747,1759,1768,1779,1826],{"type":21,"tag":22,"props":1743,"children":1744},{},[1745],{"type":26,"value":1746},"In this comprehensive guide, we will demonstrate the step-by-step process of incorporating custom Cookies into your URL request for PDF conversion using PDFShift's API. By leveraging this functionality, you can maintain an active session, enabling authentication as a specific user before generating the PDF document.",{"type":21,"tag":22,"props":1748,"children":1749},{},[1750,1752,1757],{"type":26,"value":1751},"To do so, we'll use the ",{"type":21,"tag":34,"props":1753,"children":1755},{"className":1754},[],[1756],{"type":26,"value":1738},{"type":26,"value":1758}," parameter when sending a request to PDFShift. It expects a list of dictionnary that contains the name and the value of the cookies (more details after):",{"type":21,"tag":42,"props":1760,"children":1763},{"className":1761,"code":1762,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    # The \"cookies\" parameter expects a list of dictionnary that contains the name and the value of the cookies\n    'cookies': [\n        { 'name': 'PHPSESSID', 'value': 'el4ukv0kqbvoirg7nkp4dncpk3' }\n    ]\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[1764],{"type":21,"tag":34,"props":1765,"children":1766},{"__ignoreMap":8},[1767],{"type":26,"value":1762},{"type":21,"tag":22,"props":1769,"children":1770},{},[1771,1772,1777],{"type":26,"value":115},{"type":21,"tag":34,"props":1773,"children":1775},{"className":1774},[],[1776],{"type":26,"value":1738},{"type":26,"value":1778}," parameter accept the following parameters:",{"type":21,"tag":124,"props":1780,"children":1781},{},[1782,1793,1804,1815],{"type":21,"tag":128,"props":1783,"children":1784},{},[1785,1791],{"type":21,"tag":34,"props":1786,"children":1788},{"className":1787},[],[1789],{"type":26,"value":1790},"name",{"type":26,"value":1792}," : The name of the cookie.",{"type":21,"tag":128,"props":1794,"children":1795},{},[1796,1802],{"type":21,"tag":34,"props":1797,"children":1799},{"className":1798},[],[1800],{"type":26,"value":1801},"value",{"type":26,"value":1803},": The value of the cookie.",{"type":21,"tag":128,"props":1805,"children":1806},{},[1807,1813],{"type":21,"tag":34,"props":1808,"children":1810},{"className":1809},[],[1811],{"type":26,"value":1812},"secure",{"type":26,"value":1814},": A boolean (defaults to false) that will tell the browser to only send the cookie if the request is being sent over HTTPS.",{"type":21,"tag":128,"props":1816,"children":1817},{},[1818,1824],{"type":21,"tag":34,"props":1819,"children":1821},{"className":1820},[],[1822],{"type":26,"value":1823},"http_only",{"type":26,"value":1825},": A boolean (defaults to false) that will tell the browser to not expose it to client-side scripts.",{"type":21,"tag":22,"props":1827,"children":1828},{},[1829],{"type":26,"value":1830},"Like in our guide to send custom HTTP headers or to access secured pages, this allows you to protect your documents from any visitors while allowing PDFShift to access the page and convert it to PDF.",{"title":8,"searchDepth":59,"depth":59,"links":1832},[],"content:guides:python:aiohttp:using-cookies.md","guides/python/aiohttp/using-cookies.md",{"_path":1836,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1837,"description":1838,"language":11,"library":6,"property":1839,"output":13,"related":1840,"default":7,"body":1842,"_type":61,"_id":2001,"_source":63,"_file":2002,"_extension":65},"/guides/python/aiohttp/waiting-for-a-custom-element-to-be-ready","Waiting for a custom element to be ready","Learn how to set up a custom javascript function that will waits for a specific condition to become true before allowing the conversion to happen. This is very interesting for waiting on charts to be generated, or custom fonts to be loaded. With PDFShift's API, this can easily be done using Python and the aiohttp library.","wait_for",[1841,74],"define-a-time-limit",{"type":18,"children":1843,"toc":1999},[1844,1855,1867,1879,1891,1902,1907,1917,1950,1959,1964,1973],{"type":21,"tag":22,"props":1845,"children":1846},{},[1847,1848,1853],{"type":26,"value":115},{"type":21,"tag":34,"props":1849,"children":1851},{"className":1850},[],[1852],{"type":26,"value":1839},{"type":26,"value":1854}," parameter is one of the most powerful feature of PDFShift. It allows you to control when the document is ready to be converted to PDF.",{"type":21,"tag":22,"props":1856,"children":1857},{},[1858,1860,1865],{"type":26,"value":1859},"For instance, you might need the ",{"type":21,"tag":34,"props":1861,"children":1863},{"className":1862},[],[1864],{"type":26,"value":1839},{"type":26,"value":1866}," parameter to wait on your charts to be visible.",{"type":21,"tag":22,"props":1868,"children":1869},{},[1870,1872,1877],{"type":26,"value":1871},"It makes sense because from our engine point of view, all the resources are loaded so the conversion to PDF can be executed. But from your page stand point, even though everything is loaded, ",{"type":21,"tag":104,"props":1873,"children":1874},{},[1875],{"type":26,"value":1876},"not everything is rendered",{"type":26,"value":1878},"!",{"type":21,"tag":22,"props":1880,"children":1881},{},[1882,1884,1889],{"type":26,"value":1883},"So by using the ",{"type":21,"tag":34,"props":1885,"children":1887},{"className":1886},[],[1888],{"type":26,"value":1839},{"type":26,"value":1890}," parameter, you can tell PDFShift to wait for a specific condition to be true before allowing the conversion to happen.",{"type":21,"tag":22,"props":1892,"children":1893},{},[1894,1896,1901],{"type":26,"value":1895},"That property ",{"type":21,"tag":197,"props":1897,"children":1898},{},[1899],{"type":26,"value":1900},"expects a string which points to a global function",{"type":26,"value":181},{"type":21,"tag":22,"props":1903,"children":1904},{},[1905],{"type":26,"value":1906},"For instance, if in your HTML page, you have the following script:",{"type":21,"tag":42,"props":1908,"children":1912},{"className":1909,"code":1911,"language":1147,"meta":8},[1910],"language-javascript","\u003Cscript>\nfunction isPageReady() {\n    return document.getElementById('chart').clientHeight > 0;\n}\n\u003C/script>\n",[1913],{"type":21,"tag":34,"props":1914,"children":1915},{"__ignoreMap":8},[1916],{"type":26,"value":1911},{"type":21,"tag":22,"props":1918,"children":1919},{},[1920,1922,1927,1928,1934,1936,1941,1943,1948],{"type":26,"value":1921},"You can set the ",{"type":21,"tag":34,"props":1923,"children":1925},{"className":1924},[],[1926],{"type":26,"value":1839},{"type":26,"value":607},{"type":21,"tag":34,"props":1929,"children":1931},{"className":1930},[],[1932],{"type":26,"value":1933},"isPageReady",{"type":26,"value":1935}," and PDFShift will wait for the ",{"type":21,"tag":34,"props":1937,"children":1939},{"className":1938},[],[1940],{"type":26,"value":1933},{"type":26,"value":1942}," function to return ",{"type":21,"tag":34,"props":1944,"children":1946},{"className":1945},[],[1947],{"type":26,"value":642},{"type":26,"value":1949}," before converting the page to PDF.",{"type":21,"tag":42,"props":1951,"children":1954},{"className":1952,"code":1953,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'wait_for': 'isPageReady'\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[1955],{"type":21,"tag":34,"props":1956,"children":1957},{"__ignoreMap":8},[1958],{"type":26,"value":1953},{"type":21,"tag":22,"props":1960,"children":1961},{},[1962],{"type":26,"value":1963},"In case your page doesn't have the javascript function available, but you still need to wait on some elements to be rendered before continuing the conversion, you can add javascript code directly in the request and use it at the same time:",{"type":21,"tag":42,"props":1965,"children":1968},{"className":1966,"code":1967,"language":47,"meta":8},[45],"import aiohttp, asyncio, json\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    'javascript': 'let isFontReady = false; document.fonts.ready.then(() => isFontReady = true); function isPageReady() { return isFontReady; }',\n    'wait_for': 'isPageReady'\n}\n\nresponse = None\ntry:\n    async with aiohttp.ClientSession() as session:\n        async with session.post(\n            'https://api.pdfshift.io/v3/convert/pdf',\n            headers={'X-API-Key': api_key},\n            json=params\n        ) as response:\n            if response.status >= 400:\n                raise Exception('Invalid request: {}'.format(await response.text()))\n\n            with open('result.pdf', 'wb') as f:\n                f.write(await response.read())\n\n            print('The PDF document was generated and saved to result.pdf')\nexcept asyncio.TimeoutError:\n    raise Exception('The request took too long to process')\nexcept aiohttp.ClientError as e:\n    raise Exception(f'An error occurred: {e}')\nexcept Exception as e:\n    # We highly recommend you to handle exceptions. Often, PDFShift will provide you with a clear explanation about what happened.\n    # Moreover, in case of error, no PDF are returned !\n    raise Exception(f'An error occurred: {e}')\n",[1969],{"type":21,"tag":34,"props":1970,"children":1971},{"__ignoreMap":8},[1972],{"type":26,"value":1967},{"type":21,"tag":22,"props":1974,"children":1975},{},[1976,1978,1983,1985,1990,1992,1997],{"type":26,"value":1977},"The above script will wait for all fonts to be ready before returning ",{"type":21,"tag":34,"props":1979,"children":1981},{"className":1980},[],[1982],{"type":26,"value":642},{"type":26,"value":1984}," for the ",{"type":21,"tag":34,"props":1986,"children":1988},{"className":1987},[],[1989],{"type":26,"value":1933},{"type":26,"value":1991}," function.\nPDFShift will then wait for the fonts to be ready, via the ",{"type":21,"tag":34,"props":1993,"children":1995},{"className":1994},[],[1996],{"type":26,"value":1933},{"type":26,"value":1998},", before converting the page to PDF.",{"title":8,"searchDepth":59,"depth":59,"links":2000},[],"content:guides:python:aiohttp:waiting-for-a-custom-element-to-be-ready.md","guides/python/aiohttp/waiting-for-a-custom-element-to-be-ready.md",{"_path":2004,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":2006,"language":11,"library":2005,"property":12,"output":13,"related":2007,"default":7,"body":2008,"_type":61,"_id":2040,"_source":63,"_file":2041,"_extension":65},"/guides/python/httplib2/accessing-secured-pages","httplib2","Learn how to access secured pages using Python and the httplib2 library. This guide offers detailed steps with code samples in Python and the httplib2 library, highlighting how you can acces page protected by basic authentication to convert them to PDF using PDFShift's API.",[15,16],{"type":18,"children":2009,"toc":2038},[2010,2015,2025,2034],{"type":21,"tag":22,"props":2011,"children":2012},{},[2013],{"type":26,"value":2014},"In this guide, we'll show you how to access secured page (protected by basic authentication) using Python and the httplib2 library to convert them to PDF using PDFShift's API.",{"type":21,"tag":22,"props":2016,"children":2017},{},[2018,2019,2024],{"type":26,"value":32},{"type":21,"tag":34,"props":2020,"children":2022},{"className":2021},[],[2023],{"type":26,"value":12},{"type":26,"value":40},{"type":21,"tag":42,"props":2026,"children":2029},{"className":2027,"code":2028,"language":47,"meta":8},[45],"import httplib2, 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    # You can set a basic authentication by passing the \"auth\" property which contains a username and password\n    'auth': {\n        'username': 'user',\n        'password': 'password'\n    }\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2030],{"type":21,"tag":34,"props":2031,"children":2032},{"__ignoreMap":8},[2033],{"type":26,"value":2028},{"type":21,"tag":22,"props":2035,"children":2036},{},[2037],{"type":26,"value":57},{"title":8,"searchDepth":59,"depth":59,"links":2039},[],"content:guides:python:httplib2:accessing-secured-pages.md","guides/python/httplib2/accessing-secured-pages.md",{"_path":2043,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":68,"description":2044,"language":11,"library":2005,"property":70,"output":13,"related":2045,"default":7,"body":2046,"_type":61,"_id":2233,"_source":63,"_file":2234,"_extension":65},"/guides/python/httplib2/adding-a-custom-header-or-footer","Discover how to add custom headers or footers to a PDF using Python and the httplib2 library. This in-depth guide includes Python codes that you can easily follow and quickly generate documents with PDFShift's API.",[72,73,74,75],{"type":18,"children":2047,"toc":2231},[2048,2053,2074,2084,2138,2146,2150,2159,2169,2173,2227],{"type":21,"tag":22,"props":2049,"children":2050},{},[2051],{"type":26,"value":2052},"In this guide, we'll show you how to add custom headers or footers to a PDF using Python and the httplib2 library.",{"type":21,"tag":22,"props":2054,"children":2055},{},[2056,2057,2062,2063,2068,2069,2073],{"type":26,"value":87},{"type":21,"tag":34,"props":2058,"children":2060},{"className":2059},[],[2061],{"type":26,"value":70},{"type":26,"value":94},{"type":21,"tag":34,"props":2064,"children":2066},{"className":2065},[],[2067],{"type":26,"value":100},{"type":26,"value":102},{"type":21,"tag":104,"props":2070,"children":2071},{},[2072],{"type":26,"value":108},{"type":26,"value":110},{"type":21,"tag":22,"props":2075,"children":2076},{},[2077,2078,2083],{"type":26,"value":115},{"type":21,"tag":34,"props":2079,"children":2081},{"className":2080},[],[2082],{"type":26,"value":70},{"type":26,"value":122},{"type":21,"tag":124,"props":2085,"children":2086},{},[2087,2096,2129],{"type":21,"tag":128,"props":2088,"children":2089},{},[2090,2095],{"type":21,"tag":34,"props":2091,"children":2093},{"className":2092},[],[2094],{"type":26,"value":136},{"type":26,"value":138},{"type":21,"tag":128,"props":2097,"children":2098},{},[2099,2104,2105,2110,2111,2116,2117,2122,2123,2128],{"type":21,"tag":34,"props":2100,"children":2102},{"className":2101},[],[2103],{"type":26,"value":147},{"type":26,"value":149},{"type":21,"tag":34,"props":2106,"children":2108},{"className":2107},[],[2109],{"type":26,"value":155},{"type":26,"value":157},{"type":21,"tag":34,"props":2112,"children":2114},{"className":2113},[],[2115],{"type":26,"value":163},{"type":26,"value":165},{"type":21,"tag":34,"props":2118,"children":2120},{"className":2119},[],[2121],{"type":26,"value":171},{"type":26,"value":173},{"type":21,"tag":34,"props":2124,"children":2126},{"className":2125},[],[2127],{"type":26,"value":179},{"type":26,"value":181},{"type":21,"tag":128,"props":2130,"children":2131},{},[2132,2137],{"type":21,"tag":34,"props":2133,"children":2135},{"className":2134},[],[2136],{"type":26,"value":190},{"type":26,"value":192},{"type":21,"tag":22,"props":2139,"children":2140},{},[2141,2145],{"type":21,"tag":197,"props":2142,"children":2143},{},[2144],{"type":26,"value":201},{"type":26,"value":203},{"type":21,"tag":22,"props":2147,"children":2148},{},[2149],{"type":26,"value":208},{"type":21,"tag":42,"props":2151,"children":2154},{"className":2152,"code":2153,"language":47,"meta":8},[45],"import httplib2, json, base64\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    'header': {\n        'source': '\u003Cdiv>Page {{ page }} over a total of {{ total }}. Made on {{ date }}\u003C/div>',\n        'height': 150,\n        'start_at': 2\n    }\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2155],{"type":21,"tag":34,"props":2156,"children":2157},{"__ignoreMap":8},[2158],{"type":26,"value":2153},{"type":21,"tag":22,"props":2160,"children":2161},{},[2162,2163,2168],{"type":26,"value":115},{"type":21,"tag":34,"props":2164,"children":2166},{"className":2165},[],[2167],{"type":26,"value":136},{"type":26,"value":228},{"type":21,"tag":22,"props":2170,"children":2171},{},[2172],{"type":26,"value":233},{"type":21,"tag":124,"props":2174,"children":2175},{},[2176,2185,2194,2203,2212],{"type":21,"tag":128,"props":2177,"children":2178},{},[2179,2184],{"type":21,"tag":34,"props":2180,"children":2182},{"className":2181},[],[2183],{"type":26,"value":245},{"type":26,"value":247},{"type":21,"tag":128,"props":2186,"children":2187},{},[2188,2193],{"type":21,"tag":34,"props":2189,"children":2191},{"className":2190},[],[2192],{"type":26,"value":256},{"type":26,"value":258},{"type":21,"tag":128,"props":2195,"children":2196},{},[2197,2202],{"type":21,"tag":34,"props":2198,"children":2200},{"className":2199},[],[2201],{"type":26,"value":267},{"type":26,"value":269},{"type":21,"tag":128,"props":2204,"children":2205},{},[2206,2211],{"type":21,"tag":34,"props":2207,"children":2209},{"className":2208},[],[2210],{"type":26,"value":278},{"type":26,"value":280},{"type":21,"tag":128,"props":2213,"children":2214},{},[2215,2220,2221,2226],{"type":21,"tag":34,"props":2216,"children":2218},{"className":2217},[],[2219],{"type":26,"value":289},{"type":26,"value":291},{"type":21,"tag":34,"props":2222,"children":2224},{"className":2223},[],[2225],{"type":26,"value":297},{"type":26,"value":299},{"type":21,"tag":22,"props":2228,"children":2229},{},[2230],{"type":26,"value":304},{"title":8,"searchDepth":59,"depth":59,"links":2232},[],"content:guides:python:httplib2:adding-a-custom-header-or-footer.md","guides/python/httplib2/adding-a-custom-header-or-footer.md",{"_path":2236,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":311,"description":2237,"language":11,"library":2005,"property":313,"output":13,"related":2238,"default":7,"body":2239,"_type":61,"_id":2368,"_source":63,"_file":2369,"_extension":65},"/guides/python/httplib2/adding-a-text-watermark","Learn how to add text watermarks to your generated PDF document using Python and the httplib2 library. With this guide, you'll be able to add watermarks on top of your generated PDFs easily with a quick request to PDFShift's API.",[315,316],{"type":18,"children":2240,"toc":2366},[2241,2245,2255,2264,2268,2325,2329,2350,2354,2358],{"type":21,"tag":22,"props":2242,"children":2243},{},[2244],{"type":26,"value":323},{"type":21,"tag":22,"props":2246,"children":2247},{},[2248,2249,2254],{"type":26,"value":328},{"type":21,"tag":34,"props":2250,"children":2252},{"className":2251},[],[2253],{"type":26,"value":313},{"type":26,"value":335},{"type":21,"tag":42,"props":2256,"children":2259},{"className":2257,"code":2258,"language":47,"meta":8},[45],"import httplib2, 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    'watermark': {\n        'text': 'PROTECTED DOCUMENT',\n        'offset_x': 'center',\n        'offset_top': 'top'\n    }\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2260],{"type":21,"tag":34,"props":2261,"children":2262},{"__ignoreMap":8},[2263],{"type":26,"value":2258},{"type":21,"tag":22,"props":2265,"children":2266},{},[2267],{"type":26,"value":349},{"type":21,"tag":124,"props":2269,"children":2270},{},[2271,2280,2289,2298,2307,2316],{"type":21,"tag":128,"props":2272,"children":2273},{},[2274,2279],{"type":21,"tag":34,"props":2275,"children":2277},{"className":2276},[],[2278],{"type":26,"value":361},{"type":26,"value":363},{"type":21,"tag":128,"props":2281,"children":2282},{},[2283,2288],{"type":21,"tag":34,"props":2284,"children":2286},{"className":2285},[],[2287],{"type":26,"value":372},{"type":26,"value":374},{"type":21,"tag":128,"props":2290,"children":2291},{},[2292,2297],{"type":21,"tag":34,"props":2293,"children":2295},{"className":2294},[],[2296],{"type":26,"value":383},{"type":26,"value":385},{"type":21,"tag":128,"props":2299,"children":2300},{},[2301,2306],{"type":21,"tag":34,"props":2302,"children":2304},{"className":2303},[],[2305],{"type":26,"value":394},{"type":26,"value":396},{"type":21,"tag":128,"props":2308,"children":2309},{},[2310,2315],{"type":21,"tag":34,"props":2311,"children":2313},{"className":2312},[],[2314],{"type":26,"value":405},{"type":26,"value":407},{"type":21,"tag":128,"props":2317,"children":2318},{},[2319,2324],{"type":21,"tag":34,"props":2320,"children":2322},{"className":2321},[],[2323],{"type":26,"value":416},{"type":26,"value":418},{"type":21,"tag":22,"props":2326,"children":2327},{},[2328],{"type":26,"value":423},{"type":21,"tag":124,"props":2330,"children":2331},{},[2332,2341],{"type":21,"tag":128,"props":2333,"children":2334},{},[2335,2340],{"type":21,"tag":34,"props":2336,"children":2338},{"className":2337},[],[2339],{"type":26,"value":435},{"type":26,"value":437},{"type":21,"tag":128,"props":2342,"children":2343},{},[2344,2349],{"type":21,"tag":34,"props":2345,"children":2347},{"className":2346},[],[2348],{"type":26,"value":446},{"type":26,"value":448},{"type":21,"tag":22,"props":2351,"children":2352},{},[2353],{"type":26,"value":453},{"type":21,"tag":22,"props":2355,"children":2356},{},[2357],{"type":26,"value":458},{"type":21,"tag":42,"props":2359,"children":2361},{"className":2360,"code":462,"language":47,"meta":8},[45],[2362],{"type":21,"tag":34,"props":2363,"children":2364},{"__ignoreMap":8},[2365],{"type":26,"value":462},{"title":8,"searchDepth":59,"depth":59,"links":2367},[],"content:guides:python:httplib2:adding-a-text-watermark.md","guides/python/httplib2/adding-a-text-watermark.md",{"_path":2371,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":474,"description":2372,"language":11,"library":2005,"property":313,"output":13,"related":2373,"default":7,"body":2374,"_type":61,"_id":2467,"_source":63,"_file":2468,"_extension":65},"/guides/python/httplib2/adding-an-image-watermark","Discover how to effortlessly add image watermarks to PDFs using Python and the httplib2 library. Our guide shows you how to add images on top of your PDF to protect your document easily. This is easily done with a simple request to PDFShift's API.",[316,477],{"type":18,"children":2375,"toc":2465},[2376,2380,2390,2399,2403,2414,2424,2428,2449,2453,2457],{"type":21,"tag":22,"props":2377,"children":2378},{},[2379],{"type":26,"value":323},{"type":21,"tag":22,"props":2381,"children":2382},{},[2383,2384,2389],{"type":26,"value":328},{"type":21,"tag":34,"props":2385,"children":2387},{"className":2386},[],[2388],{"type":26,"value":313},{"type":26,"value":494},{"type":21,"tag":42,"props":2391,"children":2394},{"className":2392,"code":2393,"language":47,"meta":8},[45],"import httplib2, 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    'watermark': {\n        'image': 'https://placekitten.com/200/300',\n        'offset_x': 'center',\n        'offset_top': 'top'\n    }\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2395],{"type":21,"tag":34,"props":2396,"children":2397},{"__ignoreMap":8},[2398],{"type":26,"value":2393},{"type":21,"tag":22,"props":2400,"children":2401},{},[2402],{"type":26,"value":508},{"type":21,"tag":124,"props":2404,"children":2405},{},[2406,2410],{"type":21,"tag":128,"props":2407,"children":2408},{},[2409],{"type":26,"value":516},{"type":21,"tag":128,"props":2411,"children":2412},{},[2413],{"type":26,"value":521},{"type":21,"tag":22,"props":2415,"children":2416},{},[2417,2418,2423],{"type":26,"value":526},{"type":21,"tag":34,"props":2419,"children":2421},{"className":2420},[],[2422],{"type":26,"value":532},{"type":26,"value":534},{"type":21,"tag":22,"props":2425,"children":2426},{},[2427],{"type":26,"value":423},{"type":21,"tag":124,"props":2429,"children":2430},{},[2431,2440],{"type":21,"tag":128,"props":2432,"children":2433},{},[2434,2439],{"type":21,"tag":34,"props":2435,"children":2437},{"className":2436},[],[2438],{"type":26,"value":435},{"type":26,"value":437},{"type":21,"tag":128,"props":2441,"children":2442},{},[2443,2448],{"type":21,"tag":34,"props":2444,"children":2446},{"className":2445},[],[2447],{"type":26,"value":446},{"type":26,"value":448},{"type":21,"tag":22,"props":2450,"children":2451},{},[2452],{"type":26,"value":453},{"type":21,"tag":22,"props":2454,"children":2455},{},[2456],{"type":26,"value":458},{"type":21,"tag":42,"props":2458,"children":2460},{"className":2459,"code":462,"language":572,"meta":8},[571],[2461],{"type":21,"tag":34,"props":2462,"children":2463},{"__ignoreMap":8},[2464],{"type":26,"value":462},{"title":8,"searchDepth":59,"depth":59,"links":2466},[],"content:guides:python:httplib2:adding-an-image-watermark.md","guides/python/httplib2/adding-an-image-watermark.md",{"_path":2470,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":584,"description":2471,"language":11,"library":2005,"property":586,"output":13,"related":2472,"default":7,"body":2473,"_type":61,"_id":2522,"_source":63,"_file":2523,"_extension":65},"/guides/python/httplib2/avoid-conversion-on-error","Learn how to avoid the conversion on error when loading the document using Python and the httplib2 library and relies on the PDFShift's API.",[588],{"type":18,"children":2474,"toc":2520},[2475,2479,2495,2504],{"type":21,"tag":22,"props":2476,"children":2477},{},[2478],{"type":26,"value":595},{"type":21,"tag":22,"props":2480,"children":2481},{},[2482,2483,2488,2489,2494],{"type":26,"value":600},{"type":21,"tag":34,"props":2484,"children":2486},{"className":2485},[],[2487],{"type":26,"value":586},{"type":26,"value":607},{"type":21,"tag":34,"props":2490,"children":2492},{"className":2491},[],[2493],{"type":26,"value":613},{"type":26,"value":615},{"type":21,"tag":42,"props":2496,"children":2499},{"className":2497,"code":2498,"language":47,"meta":8},[45],"import httplib2, json, base64\n\n# You can get an API key at https://pdfshift.io\napi_key = 'sk_xxxxxxxxxxxx'\n\nparams = {\n    'source': 'https://www.httpstat.us/404',\n    'raise_for_status': True\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2500],{"type":21,"tag":34,"props":2501,"children":2502},{"__ignoreMap":8},[2503],{"type":26,"value":2498},{"type":21,"tag":22,"props":2505,"children":2506},{},[2507,2508,2513,2514,2519],{"type":26,"value":629},{"type":21,"tag":34,"props":2509,"children":2511},{"className":2510},[],[2512],{"type":26,"value":586},{"type":26,"value":636},{"type":21,"tag":34,"props":2515,"children":2517},{"className":2516},[],[2518],{"type":26,"value":642},{"type":26,"value":644},{"title":8,"searchDepth":59,"depth":59,"links":2521},[],"content:guides:python:httplib2:avoid-conversion-on-error.md","guides/python/httplib2/avoid-conversion-on-error.md",{"_path":2525,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":651,"description":2526,"language":11,"library":2005,"property":136,"output":13,"related":2527,"default":7,"body":2528,"_type":61,"_id":2549,"_source":63,"_file":2550,"_extension":65},"/guides/python/httplib2/convert-html-to-pdf-from-a-url","Learn how to easily convert HTML documents to PDF from a URL using Python and the httplib2 library. This how-to guide offers clear Python code examples that show developers how to implement this using the PDFShift API.",[588,654],{"type":18,"children":2529,"toc":2547},[2530,2534,2543],{"type":21,"tag":22,"props":2531,"children":2532},{},[2533],{"type":26,"value":661},{"type":21,"tag":42,"props":2535,"children":2538},{"className":2536,"code":2537,"language":47,"meta":8},[45],"import httplib2, 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}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2539],{"type":21,"tag":34,"props":2540,"children":2541},{"__ignoreMap":8},[2542],{"type":26,"value":2537},{"type":21,"tag":22,"props":2544,"children":2545},{},[2546],{"type":26,"value":675},{"title":8,"searchDepth":59,"depth":59,"links":2548},[],"content:guides:python:httplib2:convert-html-to-pdf-from-a-url.md","guides/python/httplib2/convert-html-to-pdf-from-a-url.md",{"_path":2552,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":682,"description":2553,"language":11,"library":2005,"output":13,"related":2554,"default":7,"body":2555,"_type":61,"_id":2628,"_source":63,"_file":2629,"_extension":65},"/guides/python/httplib2/convert-html-to-pdf-from-raw-html","Learn how to to convert raw HTML document to PDF using Python and the httplib2 library. Our guide will explain you how to quickly convert documents with PDFShift's API.",[685],{"type":18,"children":2556,"toc":2626},[2557,2562,2577,2593,2603,2607,2616],{"type":21,"tag":22,"props":2558,"children":2559},{},[2560],{"type":26,"value":2561},"In this guide, we'll show you how to convert an HTML document to PDF using Python and the httplib2 library.\nProviding the HTML document as raw as a lot of great advantages :",{"type":21,"tag":124,"props":2563,"children":2564},{},[2565,2569,2573],{"type":21,"tag":128,"props":2566,"children":2567},{},[2568],{"type":26,"value":700},{"type":21,"tag":128,"props":2570,"children":2571},{},[2572],{"type":26,"value":705},{"type":21,"tag":128,"props":2574,"children":2575},{},[2576],{"type":26,"value":710},{"type":21,"tag":22,"props":2578,"children":2579},{},[2580,2581,2586,2587,2592],{"type":26,"value":715},{"type":21,"tag":34,"props":2582,"children":2584},{"className":2583},[],[2585],{"type":26,"value":721},{"type":26,"value":723},{"type":21,"tag":34,"props":2588,"children":2590},{"className":2589},[],[2591],{"type":26,"value":729},{"type":26,"value":731},{"type":21,"tag":22,"props":2594,"children":2595},{},[2596,2597,2602],{"type":26,"value":736},{"type":21,"tag":34,"props":2598,"children":2600},{"className":2599},[],[2601],{"type":26,"value":136},{"type":26,"value":743},{"type":21,"tag":22,"props":2604,"children":2605},{},[2606],{"type":26,"value":208},{"type":21,"tag":42,"props":2608,"children":2611},{"className":2609,"code":2610,"language":47,"meta":8},[45],"import httplib2, json, base64\n\n# You can get an API key at https://pdfshift.io\napi_key = 'sk_xxxxxxxxxxxx'\n\nparams = {\n    'source': '\u003Chtml>\u003Cbody>\u003Ch1>This will be a PDF document\u003C/h1>\u003Cp>This will generate a basic PDF to show how you can add raw HTML\u003C/body>\u003C/html>',\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2612],{"type":21,"tag":34,"props":2613,"children":2614},{"__ignoreMap":8},[2615],{"type":26,"value":2610},{"type":21,"tag":22,"props":2617,"children":2618},{},[2619,2620,2625],{"type":26,"value":761},{"type":21,"tag":34,"props":2621,"children":2623},{"className":2622},[],[2624],{"type":26,"value":136},{"type":26,"value":768},{"title":8,"searchDepth":59,"depth":59,"links":2627},[],"content:guides:python:httplib2:convert-html-to-pdf-from-raw-html.md","guides/python/httplib2/convert-html-to-pdf-from-raw-html.md",{"_path":2631,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":775,"description":2632,"language":11,"library":2005,"property":777,"output":13,"related":2633,"default":7,"body":2634,"_type":61,"_id":2674,"_source":63,"_file":2675,"_extension":65},"/guides/python/httplib2/define-a-time-limit","Learn how to set a conversion time limit at PDFShift. This will allow you to define a maximum time for the conversion process to complete, and if the process takes longer than the defined time, the conversion will be aborted. This guides explains you how to achieve it using Python and the httplib2 library.",[779],{"type":18,"children":2635,"toc":2672},[2636,2640,2644,2659,2668],{"type":21,"tag":22,"props":2637,"children":2638},{},[2639],{"type":26,"value":786},{"type":21,"tag":22,"props":2641,"children":2642},{},[2643],{"type":26,"value":791},{"type":21,"tag":22,"props":2645,"children":2646},{},[2647,2648,2653,2654,2658],{"type":26,"value":796},{"type":21,"tag":34,"props":2649,"children":2651},{"className":2650},[],[2652],{"type":26,"value":777},{"type":26,"value":803},{"type":21,"tag":197,"props":2655,"children":2656},{},[2657],{"type":26,"value":808},{"type":26,"value":810},{"type":21,"tag":42,"props":2660,"children":2663},{"className":2661,"code":2662,"language":47,"meta":8},[45],"import httplib2, 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    'timeout': 10\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2664],{"type":21,"tag":34,"props":2665,"children":2666},{"__ignoreMap":8},[2667],{"type":26,"value":2662},{"type":21,"tag":22,"props":2669,"children":2670},{},[2671],{"type":26,"value":824},{"title":8,"searchDepth":59,"depth":59,"links":2673},[],"content:guides:python:httplib2:define-a-time-limit.md","guides/python/httplib2/define-a-time-limit.md",{"_path":2677,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":831,"description":2678,"language":11,"library":2005,"property":833,"output":13,"default":7,"body":2679,"_type":61,"_id":2756,"_source":63,"_file":2757,"_extension":65},"/guides/python/httplib2/exporting-only-a-specific-set-of-pages","Learn how to export only a specific set of pages from a document using Python and the httplib2 library. This guide offers detailed steps with code samples in Python and the httplib2 library, highlighting how you can export only a specific set of pages from a document using PDFShift's API.",{"type":18,"children":2680,"toc":2754},[2681,2686,2696,2700,2704,2737,2741,2745],{"type":21,"tag":22,"props":2682,"children":2683},{},[2684],{"type":26,"value":2685},"In this guide, we'll show you how to export only a specific set of pages from a document using Python and the httplib2 library to convert them to PDF using PDFShift's API.",{"type":21,"tag":22,"props":2687,"children":2688},{},[2689,2690,2695],{"type":26,"value":845},{"type":21,"tag":34,"props":2691,"children":2693},{"className":2692},[],[2694],{"type":26,"value":833},{"type":26,"value":40},{"type":21,"tag":22,"props":2697,"children":2698},{},[2699],{"type":26,"value":856},{"type":21,"tag":22,"props":2701,"children":2702},{},[2703],{"type":26,"value":861},{"type":21,"tag":124,"props":2705,"children":2706},{},[2707,2717,2727],{"type":21,"tag":128,"props":2708,"children":2709},{},[2710,2711,2716],{"type":26,"value":869},{"type":21,"tag":34,"props":2712,"children":2714},{"className":2713},[],[2715],{"type":26,"value":875},{"type":26,"value":877},{"type":21,"tag":128,"props":2718,"children":2719},{},[2720,2721,2726],{"type":26,"value":882},{"type":21,"tag":34,"props":2722,"children":2724},{"className":2723},[],[2725],{"type":26,"value":888},{"type":26,"value":890},{"type":21,"tag":128,"props":2728,"children":2729},{},[2730,2731,2736],{"type":26,"value":895},{"type":21,"tag":34,"props":2732,"children":2734},{"className":2733},[],[2735],{"type":26,"value":901},{"type":26,"value":903},{"type":21,"tag":22,"props":2738,"children":2739},{},[2740],{"type":26,"value":908},{"type":21,"tag":22,"props":2742,"children":2743},{},[2744],{"type":26,"value":208},{"type":21,"tag":42,"props":2746,"children":2749},{"className":2747,"code":2748,"language":47,"meta":8},[45],"import httplib2, json, base64\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\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2750],{"type":21,"tag":34,"props":2751,"children":2752},{"__ignoreMap":8},[2753],{"type":26,"value":2748},{"title":8,"searchDepth":59,"depth":59,"links":2755},[],"content:guides:python:httplib2:exporting-only-a-specific-set-of-pages.md","guides/python/httplib2/exporting-only-a-specific-set-of-pages.md",{"_path":2759,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":928,"description":2760,"language":11,"library":2005,"property":930,"output":13,"default":7,"body":2761,"_type":61,"_id":2864,"_source":63,"_file":2865,"_extension":65},"/guides/python/httplib2/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 httplib2 library to help you generate full-height documents with PDFShift's API.",{"type":18,"children":2762,"toc":2862},[2763,2768,2784,2793,2797,2806,2822,2826,2834],{"type":21,"tag":22,"props":2764,"children":2765},{},[2766],{"type":26,"value":2767},"In this guide, we'll show you how to generate a document with full height dynamically using Python and the httplib2 library to convert them to PDF using PDFShift's API.",{"type":21,"tag":22,"props":2769,"children":2770},{},[2771,2772,2777,2778,2783],{"type":26,"value":942},{"type":21,"tag":34,"props":2773,"children":2775},{"className":2774},[],[2776],{"type":26,"value":930},{"type":26,"value":949},{"type":21,"tag":34,"props":2779,"children":2781},{"className":2780},[],[2782],{"type":26,"value":955},{"type":26,"value":957},{"type":21,"tag":42,"props":2785,"children":2788},{"className":2786,"code":2787,"language":47,"meta":8},[45],"import httplib2, 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 = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2789],{"type":21,"tag":34,"props":2790,"children":2791},{"__ignoreMap":8},[2792],{"type":26,"value":2787},{"type":21,"tag":22,"props":2794,"children":2795},{},[2796],{"type":26,"value":971},{"type":21,"tag":22,"props":2798,"children":2799},{},[2800,2801],{"type":26,"value":976},{"type":21,"tag":34,"props":2802,"children":2804},{"className":2803},[],[2805],{"type":26,"value":982},{"type":21,"tag":22,"props":2807,"children":2808},{},[2809,2810,2815,2816,2821],{"type":26,"value":987},{"type":21,"tag":34,"props":2811,"children":2813},{"className":2812},[],[2814],{"type":26,"value":993},{"type":26,"value":723},{"type":21,"tag":34,"props":2817,"children":2819},{"className":2818},[],[2820],{"type":26,"value":147},{"type":26,"value":1001},{"type":21,"tag":22,"props":2823,"children":2824},{},[2825],{"type":26,"value":1006},{"type":21,"tag":42,"props":2827,"children":2829},{"className":2828,"code":1010,"language":572,"meta":8},[571],[2830],{"type":21,"tag":34,"props":2831,"children":2832},{"__ignoreMap":8},[2833],{"type":26,"value":1010},{"type":21,"tag":22,"props":2835,"children":2836},{},[2837,2838,2843,2844,2849,2850,2855,2856,2861],{"type":26,"value":1020},{"type":21,"tag":34,"props":2839,"children":2841},{"className":2840},[],[2842],{"type":26,"value":955},{"type":26,"value":1027},{"type":21,"tag":34,"props":2845,"children":2847},{"className":2846},[],[2848],{"type":26,"value":1033},{"type":26,"value":1035},{"type":21,"tag":34,"props":2851,"children":2853},{"className":2852},[],[2854],{"type":26,"value":1041},{"type":26,"value":1043},{"type":21,"tag":34,"props":2857,"children":2859},{"className":2858},[],[2860],{"type":26,"value":1049},{"type":26,"value":1051},{"title":8,"searchDepth":59,"depth":59,"links":2863},[],"content:guides:python:httplib2:generate-a-document-with-full-height.md","guides/python/httplib2/generate-a-document-with-full-height.md",{"_path":2867,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":1058,"description":2868,"language":11,"library":2005,"property":1060,"output":13,"related":2869,"default":7,"body":2870,"_type":61,"_id":2901,"_source":63,"_file":2902,"_extension":65},"/guides/python/httplib2/loading-css-from-a-string","Follow this guide to load custom CSS as a given string when converting an HTML document to PDF with PDFShift's API. This guide provides Python code samples with the httplib2 library.",[1062,73,74,75],{"type":18,"children":2871,"toc":2899},[2872,2876,2880,2889],{"type":21,"tag":22,"props":2873,"children":2874},{},[2875],{"type":26,"value":1069},{"type":21,"tag":22,"props":2877,"children":2878},{},[2879],{"type":26,"value":1074},{"type":21,"tag":42,"props":2881,"children":2884},{"className":2882,"code":2883,"language":47,"meta":8},[45],"import httplib2, 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    'css': 'body { background-color: #f00; }'\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2885],{"type":21,"tag":34,"props":2886,"children":2887},{"__ignoreMap":8},[2888],{"type":26,"value":2883},{"type":21,"tag":22,"props":2890,"children":2891},{},[2892,2893,2898],{"type":26,"value":115},{"type":21,"tag":34,"props":2894,"children":2896},{"className":2895},[],[2897],{"type":26,"value":1060},{"type":26,"value":1094},{"title":8,"searchDepth":59,"depth":59,"links":2900},[],"content:guides:python:httplib2:loading-css-from-a-string.md","guides/python/httplib2/loading-css-from-a-string.md",{"_path":2904,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":1101,"description":2905,"language":11,"library":2005,"property":1060,"output":13,"related":2906,"default":7,"body":2907,"_type":61,"_id":2942,"_source":63,"_file":2943,"_extension":65},"/guides/python/httplib2/loading-css-from-a-url","This guides shows you how to add a custom CSS from an URL onto your document to customize the output of your generated PDF. Follow this guides to learn how to do it using Python and the httplib2 library and see how it can quickly be implemented using the PDFShift's API.",[1062,72,74,75],{"type":18,"children":2908,"toc":2940},[2909,2913,2917,2921,2930],{"type":21,"tag":22,"props":2910,"children":2911},{},[2912],{"type":26,"value":1110},{"type":21,"tag":22,"props":2914,"children":2915},{},[2916],{"type":26,"value":1074},{"type":21,"tag":22,"props":2918,"children":2919},{},[2920],{"type":26,"value":1119},{"type":21,"tag":42,"props":2922,"children":2925},{"className":2923,"code":2924,"language":47,"meta":8},[45],"import httplib2, 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    'css': \"https://www.example.com/public/style/print.css\"\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2926],{"type":21,"tag":34,"props":2927,"children":2928},{"__ignoreMap":8},[2929],{"type":26,"value":2924},{"type":21,"tag":22,"props":2931,"children":2932},{},[2933,2934,2939],{"type":26,"value":115},{"type":21,"tag":34,"props":2935,"children":2937},{"className":2936},[],[2938],{"type":26,"value":1060},{"type":26,"value":1094},{"title":8,"searchDepth":59,"depth":59,"links":2941},[],"content:guides:python:httplib2:loading-css-from-a-url.md","guides/python/httplib2/loading-css-from-a-url.md",{"_path":2945,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":1145,"description":2946,"language":11,"library":2005,"property":1147,"output":13,"related":2947,"default":7,"body":2948,"_type":61,"_id":2979,"_source":63,"_file":2980,"_extension":65},"/guides/python/httplib2/loading-javascript-from-a-string","Follow this guide to learn how to add custom javascript to your page to customize the output of your generated PDF. This allows you to modify elements on the page, add or remove content, etc. This guide uses Python and the httplib2 library and relies on the PDFShift's API.",[1062,72,73,75],{"type":18,"children":2949,"toc":2977},[2950,2954,2958,2967],{"type":21,"tag":22,"props":2951,"children":2952},{},[2953],{"type":26,"value":1155},{"type":21,"tag":22,"props":2955,"children":2956},{},[2957],{"type":26,"value":1160},{"type":21,"tag":42,"props":2959,"children":2962},{"className":2960,"code":2961,"language":47,"meta":8},[45],"import httplib2, 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    'javascript': 'document.querySelector(\"h1\").style.color = \"red\";'\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[2963],{"type":21,"tag":34,"props":2964,"children":2965},{"__ignoreMap":8},[2966],{"type":26,"value":2961},{"type":21,"tag":22,"props":2968,"children":2969},{},[2970,2971,2976],{"type":26,"value":115},{"type":21,"tag":34,"props":2972,"children":2974},{"className":2973},[],[2975],{"type":26,"value":1147},{"type":26,"value":1180},{"title":8,"searchDepth":59,"depth":59,"links":2978},[],"content:guides:python:httplib2:loading-javascript-from-a-string.md","guides/python/httplib2/loading-javascript-from-a-string.md",{"_path":2982,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":1187,"description":2983,"language":11,"library":2005,"property":1147,"output":13,"related":2984,"default":7,"body":2985,"_type":61,"_id":3020,"_source":63,"_file":3021,"_extension":65},"/guides/python/httplib2/loading-javascript-from-a-url","Follow this guide to add custom javascript to your page before converting it to PDF. Using a URL allows you to later be able to change the content of the javascript without having to update the query made to PDFShift. Learn how you can implement this using Python and the httplib2 library to call the PDFShift's API.",[1062,72,73,74],{"type":18,"children":2986,"toc":3018},[2987,2991,2995,2999,3008],{"type":21,"tag":22,"props":2988,"children":2989},{},[2990],{"type":26,"value":1196},{"type":21,"tag":22,"props":2992,"children":2993},{},[2994],{"type":26,"value":1201},{"type":21,"tag":22,"props":2996,"children":2997},{},[2998],{"type":26,"value":1206},{"type":21,"tag":42,"props":3000,"children":3003},{"className":3001,"code":3002,"language":47,"meta":8},[45],"import httplib2, 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    'javascript': 'https://www.example.com/custom.js'\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[3004],{"type":21,"tag":34,"props":3005,"children":3006},{"__ignoreMap":8},[3007],{"type":26,"value":3002},{"type":21,"tag":22,"props":3009,"children":3010},{},[3011,3012,3017],{"type":26,"value":115},{"type":21,"tag":34,"props":3013,"children":3015},{"className":3014},[],[3016],{"type":26,"value":1147},{"type":26,"value":1226},{"title":8,"searchDepth":59,"depth":59,"links":3019},[],"content:guides:python:httplib2:loading-javascript-from-a-url.md","guides/python/httplib2/loading-javascript-from-a-url.md",{"_path":3023,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":1233,"description":3024,"language":11,"library":2005,"property":1235,"output":13,"related":3025,"default":7,"body":3026,"_type":61,"_id":3165,"_source":63,"_file":3166,"_extension":65},"/guides/python/httplib2/protecting-the-generated-pdf","Learn how to protect your generated PDF with encryption for owner and user, and for choosing who can modify, print and/or copy the generated PDF. This guides explains you to do it using Python and the httplib2 library and relies on the PDFShift's API.",[315,477],{"type":18,"children":3027,"toc":3163},[3028,3033,3037,3047,3051,3060,3070,3080,3155],{"type":21,"tag":22,"props":3029,"children":3030},{},[3031],{"type":26,"value":3032},"In this guide, we'll show you how you can protect your generated PDF with encryption for owner and user, and for choosing who can modify, print and/or copy the generated PDF. This guides explains you to do it using Python and the httplib2 library and relies on the PDFShift's API.",{"type":21,"tag":22,"props":3034,"children":3035},{},[3036],{"type":26,"value":1248},{"type":21,"tag":22,"props":3038,"children":3039},{},[3040,3041,3046],{"type":26,"value":1253},{"type":21,"tag":34,"props":3042,"children":3044},{"className":3043},[],[3045],{"type":26,"value":1235},{"type":26,"value":1260},{"type":21,"tag":22,"props":3048,"children":3049},{},[3050],{"type":26,"value":1265},{"type":21,"tag":42,"props":3052,"children":3055},{"className":3053,"code":3054,"language":47,"meta":8},[45],"import httplib2, 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    'protection': {\n        'owner_password': 'owner_password',\n        'user_password': 'user_password',\n        'no_print': True,\n        'no_modify': True\n    }\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[3056],{"type":21,"tag":34,"props":3057,"children":3058},{"__ignoreMap":8},[3059],{"type":26,"value":3054},{"type":21,"tag":22,"props":3061,"children":3062},{},[3063,3064,3069],{"type":26,"value":1279},{"type":21,"tag":34,"props":3065,"children":3067},{"className":3066},[],[3068],{"type":26,"value":1235},{"type":26,"value":1286},{"type":21,"tag":22,"props":3071,"children":3072},{},[3073,3074,3079],{"type":26,"value":115},{"type":21,"tag":34,"props":3075,"children":3077},{"className":3076},[],[3078],{"type":26,"value":1235},{"type":26,"value":1297},{"type":21,"tag":124,"props":3081,"children":3082},{},[3083,3092,3101,3110,3125,3140],{"type":21,"tag":128,"props":3084,"children":3085},{},[3086,3091],{"type":21,"tag":34,"props":3087,"children":3089},{"className":3088},[],[3090],{"type":26,"value":1309},{"type":26,"value":1311},{"type":21,"tag":128,"props":3093,"children":3094},{},[3095,3100],{"type":21,"tag":34,"props":3096,"children":3098},{"className":3097},[],[3099],{"type":26,"value":1320},{"type":26,"value":1322},{"type":21,"tag":128,"props":3102,"children":3103},{},[3104,3109],{"type":21,"tag":34,"props":3105,"children":3107},{"className":3106},[],[3108],{"type":26,"value":1331},{"type":26,"value":1333},{"type":21,"tag":128,"props":3111,"children":3112},{},[3113,3118,3119,3124],{"type":21,"tag":34,"props":3114,"children":3116},{"className":3115},[],[3117],{"type":26,"value":1342},{"type":26,"value":1344},{"type":21,"tag":34,"props":3120,"children":3122},{"className":3121},[],[3123],{"type":26,"value":613},{"type":26,"value":1351},{"type":21,"tag":128,"props":3126,"children":3127},{},[3128,3133,3134,3139],{"type":21,"tag":34,"props":3129,"children":3131},{"className":3130},[],[3132],{"type":26,"value":1360},{"type":26,"value":1344},{"type":21,"tag":34,"props":3135,"children":3137},{"className":3136},[],[3138],{"type":26,"value":613},{"type":26,"value":1368},{"type":21,"tag":128,"props":3141,"children":3142},{},[3143,3148,3149,3154],{"type":21,"tag":34,"props":3144,"children":3146},{"className":3145},[],[3147],{"type":26,"value":1377},{"type":26,"value":1344},{"type":21,"tag":34,"props":3150,"children":3152},{"className":3151},[],[3153],{"type":26,"value":613},{"type":26,"value":1385},{"type":21,"tag":22,"props":3156,"children":3157},{},[3158,3162],{"type":21,"tag":197,"props":3159,"children":3160},{},[3161],{"type":26,"value":1393},{"type":26,"value":1395},{"title":8,"searchDepth":59,"depth":59,"links":3164},[],"content:guides:python:httplib2:protecting-the-generated-pdf.md","guides/python/httplib2/protecting-the-generated-pdf.md",{"_path":3168,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":1402,"description":3169,"language":11,"library":2005,"property":1404,"output":13,"related":3170,"default":7,"body":3171,"_type":61,"_id":3248,"_source":63,"_file":3249,"_extension":65},"/guides/python/httplib2/receive-a-webhook-event","Receive a notification via a POST request on your server once the conversion was done. This allows you to trigger a massive amount of conversion without having to wait on their results, and get notified once they are done. This guides will show you how to receive webhook events in Python and the httplib2 library to call the PDFShift's API.",[1406,1407],{"type":18,"children":3172,"toc":3246},[3173,3177,3181,3185,3194,3198,3202,3206,3214,3218,3226,3230,3234,3242],{"type":21,"tag":22,"props":3174,"children":3175},{},[3176],{"type":26,"value":1414},{"type":21,"tag":22,"props":3178,"children":3179},{},[3180],{"type":26,"value":1419},{"type":21,"tag":22,"props":3182,"children":3183},{},[3184],{"type":26,"value":1265},{"type":21,"tag":42,"props":3186,"children":3189},{"className":3187,"code":3188,"language":47,"meta":8},[45],"import httplib2, 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    'webhook': 'https://enyygzdj8jy9b.x.pipedream.net/'\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nprint('The PDF document was generated and you will receive an event on your webhook once it is done.')\n",[3190],{"type":21,"tag":34,"props":3191,"children":3192},{"__ignoreMap":8},[3193],{"type":26,"value":3188},{"type":21,"tag":22,"props":3195,"children":3196},{},[3197],{"type":26,"value":1437},{"type":21,"tag":22,"props":3199,"children":3200},{},[3201],{"type":26,"value":1442},{"type":21,"tag":22,"props":3203,"children":3204},{},[3205],{"type":26,"value":1447},{"type":21,"tag":42,"props":3207,"children":3209},{"className":3208,"code":1451,"language":572,"meta":8},[571],[3210],{"type":21,"tag":34,"props":3211,"children":3212},{"__ignoreMap":8},[3213],{"type":26,"value":1451},{"type":21,"tag":22,"props":3215,"children":3216},{},[3217],{"type":26,"value":1461},{"type":21,"tag":42,"props":3219,"children":3221},{"className":3220,"code":1465,"language":572,"meta":8},[571],[3222],{"type":21,"tag":34,"props":3223,"children":3224},{"__ignoreMap":8},[3225],{"type":26,"value":1465},{"type":21,"tag":22,"props":3227,"children":3228},{},[3229],{"type":26,"value":1475},{"type":21,"tag":22,"props":3231,"children":3232},{},[3233],{"type":26,"value":1480},{"type":21,"tag":42,"props":3235,"children":3237},{"className":3236,"code":8,"language":572,"meta":8},[571],[3238],{"type":21,"tag":34,"props":3239,"children":3240},{"__ignoreMap":8},[3241],{"type":26,"value":8},{"type":21,"tag":22,"props":3243,"children":3244},{},[3245],{"type":26,"value":1493},{"title":8,"searchDepth":59,"depth":59,"links":3247},[],"content:guides:python:httplib2:receive-a-webhook-event.md","guides/python/httplib2/receive-a-webhook-event.md",{"_path":3251,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":1500,"description":3252,"language":11,"library":2005,"property":1502,"output":13,"related":3253,"default":7,"body":3254,"_type":61,"_id":3324,"_source":63,"_file":3325,"_extension":65},"/guides/python/httplib2/save-your-pdf-online-and-get-back-a-url","This guides shows you how can generate a PDF document from HTML and get back an URL instead of the raw PDF. This allows you to share the link directly to your users or redirect them to that page. Learn how you can achieve it using Python and the httplib2 library to call PDFShift's API.",[1407,1504],{"type":18,"children":3255,"toc":3322},[3256,3260,3270,3279,3294,3298,3306,3314],{"type":21,"tag":22,"props":3257,"children":3258},{},[3259],{"type":26,"value":1511},{"type":21,"tag":22,"props":3261,"children":3262},{},[3263,3264,3269],{"type":26,"value":1516},{"type":21,"tag":34,"props":3265,"children":3267},{"className":3266},[],[3268],{"type":26,"value":1502},{"type":26,"value":1523},{"type":21,"tag":42,"props":3271,"children":3274},{"className":3272,"code":3273,"language":47,"meta":8},[45],"import httplib2, 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    'filename': 'example.pdf'\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nprint('The PDF document was generated and is available online via the url in the response')\n",[3275],{"type":21,"tag":34,"props":3276,"children":3277},{"__ignoreMap":8},[3278],{"type":26,"value":3273},{"type":21,"tag":22,"props":3280,"children":3281},{},[3282,3283,3288,3289,3293],{"type":26,"value":1537},{"type":21,"tag":34,"props":3284,"children":3286},{"className":3285},[],[3287],{"type":26,"value":1502},{"type":26,"value":1544},{"type":21,"tag":197,"props":3290,"children":3291},{},[3292],{"type":26,"value":1549},{"type":26,"value":1551},{"type":21,"tag":22,"props":3295,"children":3296},{},[3297],{"type":26,"value":1556},{"type":21,"tag":42,"props":3299,"children":3301},{"className":3300,"code":1560,"language":572,"meta":8},[571],[3302],{"type":21,"tag":34,"props":3303,"children":3304},{"__ignoreMap":8},[3305],{"type":26,"value":1560},{"type":21,"tag":22,"props":3307,"children":3308},{},[3309,3313],{"type":21,"tag":197,"props":3310,"children":3311},{},[3312],{"type":26,"value":201},{"type":26,"value":1574},{"type":21,"tag":22,"props":3315,"children":3316},{},[3317,3321],{"type":21,"tag":197,"props":3318,"children":3319},{},[3320],{"type":26,"value":201},{"type":26,"value":1583},{"title":8,"searchDepth":59,"depth":59,"links":3323},[],"content:guides:python:httplib2:save-your-pdf-online-and-get-back-a-url.md","guides/python/httplib2/save-your-pdf-online-and-get-back-a-url.md",{"_path":3327,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":1590,"description":3328,"language":11,"library":2005,"property":1592,"output":13,"related":3329,"default":7,"body":3330,"_type":61,"_id":3417,"_source":63,"_file":3418,"_extension":65},"/guides/python/httplib2/save-your-pdf-to-your-amazon-s3-bucket","This guides shows you how can generate a PDF document from HTML with PDFShift's API and save it to your own Amazon S3 bucket. This allows you to generate document and automate actions once the document has been created on your bucket. This guides explains you how to do it using Python and the httplib2 library.",[1406,1504],{"type":18,"children":3331,"toc":3415},[3332,3336,3340,3344,3352,3362,3371,3381,3389,3393,3401,3405],{"type":21,"tag":22,"props":3333,"children":3334},{},[3335],{"type":26,"value":1600},{"type":21,"tag":22,"props":3337,"children":3338},{},[3339],{"type":26,"value":1605},{"type":21,"tag":22,"props":3341,"children":3342},{},[3343],{"type":26,"value":1610},{"type":21,"tag":42,"props":3345,"children":3347},{"className":3346,"code":1614,"language":572,"meta":8},[571],[3348],{"type":21,"tag":34,"props":3349,"children":3350},{"__ignoreMap":8},[3351],{"type":26,"value":1614},{"type":21,"tag":22,"props":3353,"children":3354},{},[3355,3356,3361],{"type":26,"value":1624},{"type":21,"tag":34,"props":3357,"children":3359},{"className":3358},[],[3360],{"type":26,"value":1592},{"type":26,"value":1631},{"type":21,"tag":42,"props":3363,"children":3366},{"className":3364,"code":3365,"language":47,"meta":8},[45],"import httplib2, 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    's3_destination': 's3://DOC-EXAMPLE-BUCKET/test/example.pdf'\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nprint('The PDF document was generated and saved to your S3 Bucket')\n",[3367],{"type":21,"tag":34,"props":3368,"children":3369},{"__ignoreMap":8},[3370],{"type":26,"value":3365},{"type":21,"tag":22,"props":3372,"children":3373},{},[3374,3375,3380],{"type":26,"value":1645},{"type":21,"tag":34,"props":3376,"children":3378},{"className":3377},[],[3379],{"type":26,"value":1592},{"type":26,"value":1652},{"type":21,"tag":42,"props":3382,"children":3384},{"className":3383,"code":1656,"language":572,"meta":8},[571],[3385],{"type":21,"tag":34,"props":3386,"children":3387},{"__ignoreMap":8},[3388],{"type":26,"value":1656},{"type":21,"tag":22,"props":3390,"children":3391},{},[3392],{"type":26,"value":1666},{"type":21,"tag":42,"props":3394,"children":3396},{"className":3395,"code":1670,"language":572,"meta":8},[571],[3397],{"type":21,"tag":34,"props":3398,"children":3399},{"__ignoreMap":8},[3400],{"type":26,"value":1670},{"type":21,"tag":22,"props":3402,"children":3403},{},[3404],{"type":26,"value":1680},{"type":21,"tag":22,"props":3406,"children":3407},{},[3408,3409,3414],{"type":26,"value":1685},{"type":21,"tag":34,"props":3410,"children":3412},{"className":3411},[],[3413],{"type":26,"value":1404},{"type":26,"value":1692},{"title":8,"searchDepth":59,"depth":59,"links":3416},[],"content:guides:python:httplib2:save-your-pdf-to-your-amazon-s3-bucket.md","guides/python/httplib2/save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":3420,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":1699,"description":3421,"language":11,"library":2005,"property":1701,"output":13,"related":3422,"default":7,"body":3423,"_type":61,"_id":3448,"_source":63,"_file":3449,"_extension":65},"/guides/python/httplib2/send-custom-http-headers","Learn how to add custom HTTP headers when requesting an URL to be converted in PDF with PDFShift's API. It allows you to add specific headers that your backend can check against to authenticate a query before converting it to PDF. This guide explains you how using Python and the httplib2 library.",[16,1703],{"type":18,"children":3424,"toc":3446},[3425,3429,3433,3442],{"type":21,"tag":22,"props":3426,"children":3427},{},[3428],{"type":26,"value":1710},{"type":21,"tag":22,"props":3430,"children":3431},{},[3432],{"type":26,"value":1715},{"type":21,"tag":42,"props":3434,"children":3437},{"className":3435,"code":3436,"language":47,"meta":8},[45],"import httplib2, 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    'http_headers': {\n        'x-custom-header': 'custom-value',\n        'Authorization': 'Bearer {token}'  # This allows you to authenticate PDFShift to your service in a custom way\n    }\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[3438],{"type":21,"tag":34,"props":3439,"children":3440},{"__ignoreMap":8},[3441],{"type":26,"value":3436},{"type":21,"tag":22,"props":3443,"children":3444},{},[3445],{"type":26,"value":1729},{"title":8,"searchDepth":59,"depth":59,"links":3447},[],"content:guides:python:httplib2:send-custom-http-headers.md","guides/python/httplib2/send-custom-http-headers.md",{"_path":3451,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":1736,"description":3452,"language":11,"library":2005,"property":1738,"output":13,"related":3453,"default":7,"body":3454,"_type":61,"_id":3534,"_source":63,"_file":3535,"_extension":65},"/guides/python/httplib2/using-cookies","Learn how to add custom Cookies when requesting an URL to be converted in PDF with PDFShift's API. It allows you to pursue an active session for instance, that will authenticate the request as a specific user before converting the page to PDF. This guide explains you how using Python and the httplib2 library.",[15,1703],{"type":18,"children":3455,"toc":3532},[3456,3460,3470,3479,3489,3528],{"type":21,"tag":22,"props":3457,"children":3458},{},[3459],{"type":26,"value":1746},{"type":21,"tag":22,"props":3461,"children":3462},{},[3463,3464,3469],{"type":26,"value":1751},{"type":21,"tag":34,"props":3465,"children":3467},{"className":3466},[],[3468],{"type":26,"value":1738},{"type":26,"value":1758},{"type":21,"tag":42,"props":3471,"children":3474},{"className":3472,"code":3473,"language":47,"meta":8},[45],"import httplib2, 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    # The \"cookies\" parameter expects a list of dictionnary that contains the name and the value of the cookies\n    'cookies': [\n        { 'name': 'PHPSESSID', 'value': 'el4ukv0kqbvoirg7nkp4dncpk3' }\n    ]\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[3475],{"type":21,"tag":34,"props":3476,"children":3477},{"__ignoreMap":8},[3478],{"type":26,"value":3473},{"type":21,"tag":22,"props":3480,"children":3481},{},[3482,3483,3488],{"type":26,"value":115},{"type":21,"tag":34,"props":3484,"children":3486},{"className":3485},[],[3487],{"type":26,"value":1738},{"type":26,"value":1778},{"type":21,"tag":124,"props":3490,"children":3491},{},[3492,3501,3510,3519],{"type":21,"tag":128,"props":3493,"children":3494},{},[3495,3500],{"type":21,"tag":34,"props":3496,"children":3498},{"className":3497},[],[3499],{"type":26,"value":1790},{"type":26,"value":1792},{"type":21,"tag":128,"props":3502,"children":3503},{},[3504,3509],{"type":21,"tag":34,"props":3505,"children":3507},{"className":3506},[],[3508],{"type":26,"value":1801},{"type":26,"value":1803},{"type":21,"tag":128,"props":3511,"children":3512},{},[3513,3518],{"type":21,"tag":34,"props":3514,"children":3516},{"className":3515},[],[3517],{"type":26,"value":1812},{"type":26,"value":1814},{"type":21,"tag":128,"props":3520,"children":3521},{},[3522,3527],{"type":21,"tag":34,"props":3523,"children":3525},{"className":3524},[],[3526],{"type":26,"value":1823},{"type":26,"value":1825},{"type":21,"tag":22,"props":3529,"children":3530},{},[3531],{"type":26,"value":1830},{"title":8,"searchDepth":59,"depth":59,"links":3533},[],"content:guides:python:httplib2:using-cookies.md","guides/python/httplib2/using-cookies.md",{"_path":3537,"_dir":2005,"_draft":7,"_partial":7,"_locale":8,"title":1837,"description":3538,"language":11,"library":2005,"property":1839,"output":13,"related":3539,"default":7,"body":3540,"_type":61,"_id":3676,"_source":63,"_file":3677,"_extension":65},"/guides/python/httplib2/waiting-for-a-custom-element-to-be-ready","Learn how to set up a custom javascript function that will waits for a specific condition to become true before allowing the conversion to happen. This is very interesting for waiting on charts to be generated, or custom fonts to be loaded. With PDFShift's API, this can easily be done using Python and the httplib2 library.",[1841,74],{"type":18,"children":3541,"toc":3674},[3542,3552,3562,3571,3581,3590,3594,3602,3630,3639,3643,3652],{"type":21,"tag":22,"props":3543,"children":3544},{},[3545,3546,3551],{"type":26,"value":115},{"type":21,"tag":34,"props":3547,"children":3549},{"className":3548},[],[3550],{"type":26,"value":1839},{"type":26,"value":1854},{"type":21,"tag":22,"props":3553,"children":3554},{},[3555,3556,3561],{"type":26,"value":1859},{"type":21,"tag":34,"props":3557,"children":3559},{"className":3558},[],[3560],{"type":26,"value":1839},{"type":26,"value":1866},{"type":21,"tag":22,"props":3563,"children":3564},{},[3565,3566,3570],{"type":26,"value":1871},{"type":21,"tag":104,"props":3567,"children":3568},{},[3569],{"type":26,"value":1876},{"type":26,"value":1878},{"type":21,"tag":22,"props":3572,"children":3573},{},[3574,3575,3580],{"type":26,"value":1883},{"type":21,"tag":34,"props":3576,"children":3578},{"className":3577},[],[3579],{"type":26,"value":1839},{"type":26,"value":1890},{"type":21,"tag":22,"props":3582,"children":3583},{},[3584,3585,3589],{"type":26,"value":1895},{"type":21,"tag":197,"props":3586,"children":3587},{},[3588],{"type":26,"value":1900},{"type":26,"value":181},{"type":21,"tag":22,"props":3591,"children":3592},{},[3593],{"type":26,"value":1906},{"type":21,"tag":42,"props":3595,"children":3597},{"className":3596,"code":1911,"language":1147,"meta":8},[1910],[3598],{"type":21,"tag":34,"props":3599,"children":3600},{"__ignoreMap":8},[3601],{"type":26,"value":1911},{"type":21,"tag":22,"props":3603,"children":3604},{},[3605,3606,3611,3612,3617,3618,3623,3624,3629],{"type":26,"value":1921},{"type":21,"tag":34,"props":3607,"children":3609},{"className":3608},[],[3610],{"type":26,"value":1839},{"type":26,"value":607},{"type":21,"tag":34,"props":3613,"children":3615},{"className":3614},[],[3616],{"type":26,"value":1933},{"type":26,"value":1935},{"type":21,"tag":34,"props":3619,"children":3621},{"className":3620},[],[3622],{"type":26,"value":1933},{"type":26,"value":1942},{"type":21,"tag":34,"props":3625,"children":3627},{"className":3626},[],[3628],{"type":26,"value":642},{"type":26,"value":1949},{"type":21,"tag":42,"props":3631,"children":3634},{"className":3632,"code":3633,"language":47,"meta":8},[45],"import httplib2, 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    'wait_for': 'isPageReady'\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[3635],{"type":21,"tag":34,"props":3636,"children":3637},{"__ignoreMap":8},[3638],{"type":26,"value":3633},{"type":21,"tag":22,"props":3640,"children":3641},{},[3642],{"type":26,"value":1963},{"type":21,"tag":42,"props":3644,"children":3647},{"className":3645,"code":3646,"language":47,"meta":8},[45],"import httplib2, 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    'javascript': 'let isFontReady = false; document.fonts.ready.then(() => isFontReady = true); function isPageReady() { return isFontReady; }',\n    'wait_for': 'isPageReady'\n}\n\nhttp = httplib2.Http()\nresponse, content = http.request(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    method='POST',\n    body=json.dumps(params),\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    }\n)\n\nif response.status >= 400:\n    raise ValueError(f\"Request failed with status code {response.status}: {content.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(content)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[3648],{"type":21,"tag":34,"props":3649,"children":3650},{"__ignoreMap":8},[3651],{"type":26,"value":3646},{"type":21,"tag":22,"props":3653,"children":3654},{},[3655,3656,3661,3662,3667,3668,3673],{"type":26,"value":1977},{"type":21,"tag":34,"props":3657,"children":3659},{"className":3658},[],[3660],{"type":26,"value":642},{"type":26,"value":1984},{"type":21,"tag":34,"props":3663,"children":3665},{"className":3664},[],[3666],{"type":26,"value":1933},{"type":26,"value":1991},{"type":21,"tag":34,"props":3669,"children":3671},{"className":3670},[],[3672],{"type":26,"value":1933},{"type":26,"value":1998},{"title":8,"searchDepth":59,"depth":59,"links":3675},[],"content:guides:python:httplib2:waiting-for-a-custom-element-to-be-ready.md","guides/python/httplib2/waiting-for-a-custom-element-to-be-ready.md",{"_path":3679,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":3681,"language":11,"library":3680,"property":12,"output":13,"related":3682,"default":3683,"body":3684,"_type":61,"_id":3716,"_source":63,"_file":3717,"_extension":65},"/guides/python/requests/accessing-secured-pages","requests","Learn how to access secured pages using Python and the requests library. This guide offers detailed steps with code samples in Python and the requests library, highlighting how you can acces page protected by basic authentication to convert them to PDF using PDFShift's API.",[15,16],true,{"type":18,"children":3685,"toc":3714},[3686,3691,3701,3710],{"type":21,"tag":22,"props":3687,"children":3688},{},[3689],{"type":26,"value":3690},"In this guide, we'll show you how to access secured page (protected by basic authentication) using Python and the requests library to convert them to PDF using PDFShift's API.",{"type":21,"tag":22,"props":3692,"children":3693},{},[3694,3695,3700],{"type":26,"value":32},{"type":21,"tag":34,"props":3696,"children":3698},{"className":3697},[],[3699],{"type":26,"value":12},{"type":26,"value":40},{"type":21,"tag":42,"props":3702,"children":3705},{"className":3703,"code":3704,"language":47,"meta":8},[45],"import requests\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    # You can set a basic authentication by passing the \"auth\" property which contains a username and password\n    'auth': {\n        'username': 'user',\n        'password': 'password'\n    }\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[3706],{"type":21,"tag":34,"props":3707,"children":3708},{"__ignoreMap":8},[3709],{"type":26,"value":3704},{"type":21,"tag":22,"props":3711,"children":3712},{},[3713],{"type":26,"value":57},{"title":8,"searchDepth":59,"depth":59,"links":3715},[],"content:guides:python:requests:accessing-secured-pages.md","guides/python/requests/accessing-secured-pages.md",{"_path":3719,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":68,"description":3720,"language":11,"library":3680,"property":70,"output":13,"related":3721,"default":3683,"body":3722,"_type":61,"_id":3909,"_source":63,"_file":3910,"_extension":65},"/guides/python/requests/adding-a-custom-header-or-footer","Discover how to add custom headers or footers to a PDF using Python and the requests library. This in-depth guide includes Python codes that you can easily follow and quickly generate documents with PDFShift's API.",[72,73,74,75],{"type":18,"children":3723,"toc":3907},[3724,3729,3750,3760,3814,3822,3826,3835,3845,3849,3903],{"type":21,"tag":22,"props":3725,"children":3726},{},[3727],{"type":26,"value":3728},"In this guide, we'll show you how to add custom headers or footers to a PDF using Python and the requests library.",{"type":21,"tag":22,"props":3730,"children":3731},{},[3732,3733,3738,3739,3744,3745,3749],{"type":26,"value":87},{"type":21,"tag":34,"props":3734,"children":3736},{"className":3735},[],[3737],{"type":26,"value":70},{"type":26,"value":94},{"type":21,"tag":34,"props":3740,"children":3742},{"className":3741},[],[3743],{"type":26,"value":100},{"type":26,"value":102},{"type":21,"tag":104,"props":3746,"children":3747},{},[3748],{"type":26,"value":108},{"type":26,"value":110},{"type":21,"tag":22,"props":3751,"children":3752},{},[3753,3754,3759],{"type":26,"value":115},{"type":21,"tag":34,"props":3755,"children":3757},{"className":3756},[],[3758],{"type":26,"value":70},{"type":26,"value":122},{"type":21,"tag":124,"props":3761,"children":3762},{},[3763,3772,3805],{"type":21,"tag":128,"props":3764,"children":3765},{},[3766,3771],{"type":21,"tag":34,"props":3767,"children":3769},{"className":3768},[],[3770],{"type":26,"value":136},{"type":26,"value":138},{"type":21,"tag":128,"props":3773,"children":3774},{},[3775,3780,3781,3786,3787,3792,3793,3798,3799,3804],{"type":21,"tag":34,"props":3776,"children":3778},{"className":3777},[],[3779],{"type":26,"value":147},{"type":26,"value":149},{"type":21,"tag":34,"props":3782,"children":3784},{"className":3783},[],[3785],{"type":26,"value":155},{"type":26,"value":157},{"type":21,"tag":34,"props":3788,"children":3790},{"className":3789},[],[3791],{"type":26,"value":163},{"type":26,"value":165},{"type":21,"tag":34,"props":3794,"children":3796},{"className":3795},[],[3797],{"type":26,"value":171},{"type":26,"value":173},{"type":21,"tag":34,"props":3800,"children":3802},{"className":3801},[],[3803],{"type":26,"value":179},{"type":26,"value":181},{"type":21,"tag":128,"props":3806,"children":3807},{},[3808,3813],{"type":21,"tag":34,"props":3809,"children":3811},{"className":3810},[],[3812],{"type":26,"value":190},{"type":26,"value":192},{"type":21,"tag":22,"props":3815,"children":3816},{},[3817,3821],{"type":21,"tag":197,"props":3818,"children":3819},{},[3820],{"type":26,"value":201},{"type":26,"value":203},{"type":21,"tag":22,"props":3823,"children":3824},{},[3825],{"type":26,"value":208},{"type":21,"tag":42,"props":3827,"children":3830},{"className":3828,"code":3829,"language":47,"meta":8},[45],"import requests\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    'header': {\n        'source': '\u003Cdiv>Page {{ page }} over a total of {{ total }}. Made on {{ date }}\u003C/div>',\n        'height': 150,\n        'start_at': 2\n    }\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[3831],{"type":21,"tag":34,"props":3832,"children":3833},{"__ignoreMap":8},[3834],{"type":26,"value":3829},{"type":21,"tag":22,"props":3836,"children":3837},{},[3838,3839,3844],{"type":26,"value":115},{"type":21,"tag":34,"props":3840,"children":3842},{"className":3841},[],[3843],{"type":26,"value":136},{"type":26,"value":228},{"type":21,"tag":22,"props":3846,"children":3847},{},[3848],{"type":26,"value":233},{"type":21,"tag":124,"props":3850,"children":3851},{},[3852,3861,3870,3879,3888],{"type":21,"tag":128,"props":3853,"children":3854},{},[3855,3860],{"type":21,"tag":34,"props":3856,"children":3858},{"className":3857},[],[3859],{"type":26,"value":245},{"type":26,"value":247},{"type":21,"tag":128,"props":3862,"children":3863},{},[3864,3869],{"type":21,"tag":34,"props":3865,"children":3867},{"className":3866},[],[3868],{"type":26,"value":256},{"type":26,"value":258},{"type":21,"tag":128,"props":3871,"children":3872},{},[3873,3878],{"type":21,"tag":34,"props":3874,"children":3876},{"className":3875},[],[3877],{"type":26,"value":267},{"type":26,"value":269},{"type":21,"tag":128,"props":3880,"children":3881},{},[3882,3887],{"type":21,"tag":34,"props":3883,"children":3885},{"className":3884},[],[3886],{"type":26,"value":278},{"type":26,"value":280},{"type":21,"tag":128,"props":3889,"children":3890},{},[3891,3896,3897,3902],{"type":21,"tag":34,"props":3892,"children":3894},{"className":3893},[],[3895],{"type":26,"value":289},{"type":26,"value":291},{"type":21,"tag":34,"props":3898,"children":3900},{"className":3899},[],[3901],{"type":26,"value":297},{"type":26,"value":299},{"type":21,"tag":22,"props":3904,"children":3905},{},[3906],{"type":26,"value":304},{"title":8,"searchDepth":59,"depth":59,"links":3908},[],"content:guides:python:requests:adding-a-custom-header-or-footer.md","guides/python/requests/adding-a-custom-header-or-footer.md",{"_path":3912,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":311,"description":3913,"language":11,"library":3680,"property":313,"output":13,"related":3914,"default":3683,"body":3915,"_type":61,"_id":4044,"_source":63,"_file":4045,"_extension":65},"/guides/python/requests/adding-a-text-watermark","Learn how to add text watermarks to your generated PDF document using Python and the requests library. With this guide, you'll be able to add watermarks on top of your generated PDFs easily with a quick request to PDFShift's API.",[315,316],{"type":18,"children":3916,"toc":4042},[3917,3921,3931,3940,3944,4001,4005,4026,4030,4034],{"type":21,"tag":22,"props":3918,"children":3919},{},[3920],{"type":26,"value":323},{"type":21,"tag":22,"props":3922,"children":3923},{},[3924,3925,3930],{"type":26,"value":328},{"type":21,"tag":34,"props":3926,"children":3928},{"className":3927},[],[3929],{"type":26,"value":313},{"type":26,"value":335},{"type":21,"tag":42,"props":3932,"children":3935},{"className":3933,"code":3934,"language":47,"meta":8},[45],"import requests\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    'watermark': {\n        'text': 'PROTECTED DOCUMENT',\n        'offset_x': 'center',\n        'offset_top': 'top'\n    }\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[3936],{"type":21,"tag":34,"props":3937,"children":3938},{"__ignoreMap":8},[3939],{"type":26,"value":3934},{"type":21,"tag":22,"props":3941,"children":3942},{},[3943],{"type":26,"value":349},{"type":21,"tag":124,"props":3945,"children":3946},{},[3947,3956,3965,3974,3983,3992],{"type":21,"tag":128,"props":3948,"children":3949},{},[3950,3955],{"type":21,"tag":34,"props":3951,"children":3953},{"className":3952},[],[3954],{"type":26,"value":361},{"type":26,"value":363},{"type":21,"tag":128,"props":3957,"children":3958},{},[3959,3964],{"type":21,"tag":34,"props":3960,"children":3962},{"className":3961},[],[3963],{"type":26,"value":372},{"type":26,"value":374},{"type":21,"tag":128,"props":3966,"children":3967},{},[3968,3973],{"type":21,"tag":34,"props":3969,"children":3971},{"className":3970},[],[3972],{"type":26,"value":383},{"type":26,"value":385},{"type":21,"tag":128,"props":3975,"children":3976},{},[3977,3982],{"type":21,"tag":34,"props":3978,"children":3980},{"className":3979},[],[3981],{"type":26,"value":394},{"type":26,"value":396},{"type":21,"tag":128,"props":3984,"children":3985},{},[3986,3991],{"type":21,"tag":34,"props":3987,"children":3989},{"className":3988},[],[3990],{"type":26,"value":405},{"type":26,"value":407},{"type":21,"tag":128,"props":3993,"children":3994},{},[3995,4000],{"type":21,"tag":34,"props":3996,"children":3998},{"className":3997},[],[3999],{"type":26,"value":416},{"type":26,"value":418},{"type":21,"tag":22,"props":4002,"children":4003},{},[4004],{"type":26,"value":423},{"type":21,"tag":124,"props":4006,"children":4007},{},[4008,4017],{"type":21,"tag":128,"props":4009,"children":4010},{},[4011,4016],{"type":21,"tag":34,"props":4012,"children":4014},{"className":4013},[],[4015],{"type":26,"value":435},{"type":26,"value":437},{"type":21,"tag":128,"props":4018,"children":4019},{},[4020,4025],{"type":21,"tag":34,"props":4021,"children":4023},{"className":4022},[],[4024],{"type":26,"value":446},{"type":26,"value":448},{"type":21,"tag":22,"props":4027,"children":4028},{},[4029],{"type":26,"value":453},{"type":21,"tag":22,"props":4031,"children":4032},{},[4033],{"type":26,"value":458},{"type":21,"tag":42,"props":4035,"children":4037},{"className":4036,"code":462,"language":47,"meta":8},[45],[4038],{"type":21,"tag":34,"props":4039,"children":4040},{"__ignoreMap":8},[4041],{"type":26,"value":462},{"title":8,"searchDepth":59,"depth":59,"links":4043},[],"content:guides:python:requests:adding-a-text-watermark.md","guides/python/requests/adding-a-text-watermark.md",{"_path":4047,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":474,"description":4048,"language":11,"library":3680,"property":313,"output":13,"related":4049,"default":3683,"body":4050,"_type":61,"_id":4143,"_source":63,"_file":4144,"_extension":65},"/guides/python/requests/adding-an-image-watermark","Discover how to effortlessly add image watermarks to PDFs using Python and the requests library. Our guide shows you how to add images on top of your PDF to protect your document easily. This is easily done with a simple request to PDFShift's API.",[316,477],{"type":18,"children":4051,"toc":4141},[4052,4056,4066,4075,4079,4090,4100,4104,4125,4129,4133],{"type":21,"tag":22,"props":4053,"children":4054},{},[4055],{"type":26,"value":323},{"type":21,"tag":22,"props":4057,"children":4058},{},[4059,4060,4065],{"type":26,"value":328},{"type":21,"tag":34,"props":4061,"children":4063},{"className":4062},[],[4064],{"type":26,"value":313},{"type":26,"value":494},{"type":21,"tag":42,"props":4067,"children":4070},{"className":4068,"code":4069,"language":47,"meta":8},[45],"import requests\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    'watermark': {\n        'image': 'https://placekitten.com/200/300',\n        'offset_x': 'center',\n        'offset_top': 'top'\n    }\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[4071],{"type":21,"tag":34,"props":4072,"children":4073},{"__ignoreMap":8},[4074],{"type":26,"value":4069},{"type":21,"tag":22,"props":4076,"children":4077},{},[4078],{"type":26,"value":508},{"type":21,"tag":124,"props":4080,"children":4081},{},[4082,4086],{"type":21,"tag":128,"props":4083,"children":4084},{},[4085],{"type":26,"value":516},{"type":21,"tag":128,"props":4087,"children":4088},{},[4089],{"type":26,"value":521},{"type":21,"tag":22,"props":4091,"children":4092},{},[4093,4094,4099],{"type":26,"value":526},{"type":21,"tag":34,"props":4095,"children":4097},{"className":4096},[],[4098],{"type":26,"value":532},{"type":26,"value":534},{"type":21,"tag":22,"props":4101,"children":4102},{},[4103],{"type":26,"value":423},{"type":21,"tag":124,"props":4105,"children":4106},{},[4107,4116],{"type":21,"tag":128,"props":4108,"children":4109},{},[4110,4115],{"type":21,"tag":34,"props":4111,"children":4113},{"className":4112},[],[4114],{"type":26,"value":435},{"type":26,"value":437},{"type":21,"tag":128,"props":4117,"children":4118},{},[4119,4124],{"type":21,"tag":34,"props":4120,"children":4122},{"className":4121},[],[4123],{"type":26,"value":446},{"type":26,"value":448},{"type":21,"tag":22,"props":4126,"children":4127},{},[4128],{"type":26,"value":453},{"type":21,"tag":22,"props":4130,"children":4131},{},[4132],{"type":26,"value":458},{"type":21,"tag":42,"props":4134,"children":4136},{"className":4135,"code":462,"language":572,"meta":8},[571],[4137],{"type":21,"tag":34,"props":4138,"children":4139},{"__ignoreMap":8},[4140],{"type":26,"value":462},{"title":8,"searchDepth":59,"depth":59,"links":4142},[],"content:guides:python:requests:adding-an-image-watermark.md","guides/python/requests/adding-an-image-watermark.md",{"_path":4146,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":584,"description":4147,"language":11,"library":3680,"property":586,"output":13,"related":4148,"default":3683,"body":4149,"_type":61,"_id":4198,"_source":63,"_file":4199,"_extension":65},"/guides/python/requests/avoid-conversion-on-error","Learn how to avoid the conversion on error when loading the document using Python and the requests library and relies on the PDFShift's API.",[588],{"type":18,"children":4150,"toc":4196},[4151,4155,4171,4180],{"type":21,"tag":22,"props":4152,"children":4153},{},[4154],{"type":26,"value":595},{"type":21,"tag":22,"props":4156,"children":4157},{},[4158,4159,4164,4165,4170],{"type":26,"value":600},{"type":21,"tag":34,"props":4160,"children":4162},{"className":4161},[],[4163],{"type":26,"value":586},{"type":26,"value":607},{"type":21,"tag":34,"props":4166,"children":4168},{"className":4167},[],[4169],{"type":26,"value":613},{"type":26,"value":615},{"type":21,"tag":42,"props":4172,"children":4175},{"className":4173,"code":4174,"language":47,"meta":8},[45],"import requests\n\n# You can get an API key at https://pdfshift.io\napi_key = 'sk_xxxxxxxxxxxx'\n\nparams = {\n    'source': 'https://www.httpstat.us/404',\n    'raise_for_status': True\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[4176],{"type":21,"tag":34,"props":4177,"children":4178},{"__ignoreMap":8},[4179],{"type":26,"value":4174},{"type":21,"tag":22,"props":4181,"children":4182},{},[4183,4184,4189,4190,4195],{"type":26,"value":629},{"type":21,"tag":34,"props":4185,"children":4187},{"className":4186},[],[4188],{"type":26,"value":586},{"type":26,"value":636},{"type":21,"tag":34,"props":4191,"children":4193},{"className":4192},[],[4194],{"type":26,"value":642},{"type":26,"value":644},{"title":8,"searchDepth":59,"depth":59,"links":4197},[],"content:guides:python:requests:avoid-conversion-on-error.md","guides/python/requests/avoid-conversion-on-error.md",{"_path":4201,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":651,"description":4202,"language":11,"library":3680,"property":136,"output":13,"related":4203,"default":3683,"body":4204,"_type":61,"_id":4226,"_source":63,"_file":4227,"_extension":65},"/guides/python/requests/convert-html-to-pdf-from-a-url","Learn how to easily convert HTML documents to PDF from a URL using Python and the requests library. This how-to guide offers clear Python code examples that show developers how to implement this using the PDFShift API.",[588,654],{"type":18,"children":4205,"toc":4224},[4206,4211,4220],{"type":21,"tag":22,"props":4207,"children":4208},{},[4209],{"type":26,"value":4210},"Converting HTML documents to PDFs using PDFShift's API is a straightforward process.\nWith just a few lines of Python code, you can seamlessly convert a URL into a PDF document.",{"type":21,"tag":42,"props":4212,"children":4215},{"className":4213,"code":4214,"language":47,"meta":8},[45],"import requests\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}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[4216],{"type":21,"tag":34,"props":4217,"children":4218},{"__ignoreMap":8},[4219],{"type":26,"value":4214},{"type":21,"tag":22,"props":4221,"children":4222},{},[4223],{"type":26,"value":675},{"title":8,"searchDepth":59,"depth":59,"links":4225},[],"content:guides:python:requests:convert-html-to-pdf-from-a-url.md","guides/python/requests/convert-html-to-pdf-from-a-url.md",{"_path":4229,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":682,"description":4230,"language":11,"library":3680,"output":13,"related":4231,"default":3683,"body":4232,"_type":61,"_id":4305,"_source":63,"_file":4306,"_extension":65},"/guides/python/requests/convert-html-to-pdf-from-raw-html","Learn how to to convert raw HTML document to PDF using Python and the requests library. Our guide will explain you how to quickly convert documents with PDFShift's API.",[685],{"type":18,"children":4233,"toc":4303},[4234,4239,4254,4270,4280,4284,4293],{"type":21,"tag":22,"props":4235,"children":4236},{},[4237],{"type":26,"value":4238},"In this guide, we'll show you how to convert an HTML document to PDF using Python and the requests library.\nProviding the HTML document as raw as a lot of great advantages :",{"type":21,"tag":124,"props":4240,"children":4241},{},[4242,4246,4250],{"type":21,"tag":128,"props":4243,"children":4244},{},[4245],{"type":26,"value":700},{"type":21,"tag":128,"props":4247,"children":4248},{},[4249],{"type":26,"value":705},{"type":21,"tag":128,"props":4251,"children":4252},{},[4253],{"type":26,"value":710},{"type":21,"tag":22,"props":4255,"children":4256},{},[4257,4258,4263,4264,4269],{"type":26,"value":715},{"type":21,"tag":34,"props":4259,"children":4261},{"className":4260},[],[4262],{"type":26,"value":721},{"type":26,"value":723},{"type":21,"tag":34,"props":4265,"children":4267},{"className":4266},[],[4268],{"type":26,"value":729},{"type":26,"value":731},{"type":21,"tag":22,"props":4271,"children":4272},{},[4273,4274,4279],{"type":26,"value":736},{"type":21,"tag":34,"props":4275,"children":4277},{"className":4276},[],[4278],{"type":26,"value":136},{"type":26,"value":743},{"type":21,"tag":22,"props":4281,"children":4282},{},[4283],{"type":26,"value":208},{"type":21,"tag":42,"props":4285,"children":4288},{"className":4286,"code":4287,"language":47,"meta":8},[45],"import requests\n\n# You can get an API key at https://pdfshift.io\napi_key = 'sk_xxxxxxxxxxxx'\n\nparams = {\n    'source': '\u003Chtml>\u003Cbody>\u003Ch1>This will be a PDF document\u003C/h1>\u003Cp>This will generate a basic PDF to show how you can add raw HTML\u003C/body>\u003C/html>',\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[4289],{"type":21,"tag":34,"props":4290,"children":4291},{"__ignoreMap":8},[4292],{"type":26,"value":4287},{"type":21,"tag":22,"props":4294,"children":4295},{},[4296,4297,4302],{"type":26,"value":761},{"type":21,"tag":34,"props":4298,"children":4300},{"className":4299},[],[4301],{"type":26,"value":136},{"type":26,"value":768},{"title":8,"searchDepth":59,"depth":59,"links":4304},[],"content:guides:python:requests:convert-html-to-pdf-from-raw-html.md","guides/python/requests/convert-html-to-pdf-from-raw-html.md",{"_path":4308,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":775,"description":4309,"language":11,"library":3680,"property":777,"output":13,"related":4310,"default":3683,"body":4311,"_type":61,"_id":4351,"_source":63,"_file":4352,"_extension":65},"/guides/python/requests/define-a-time-limit","Learn how to set a conversion time limit at PDFShift. This will allow you to define a maximum time for the conversion process to complete, and if the process takes longer than the defined time, the conversion will be aborted. This guides explains you how to achieve it using Python and the requests library.",[779],{"type":18,"children":4312,"toc":4349},[4313,4317,4321,4336,4345],{"type":21,"tag":22,"props":4314,"children":4315},{},[4316],{"type":26,"value":786},{"type":21,"tag":22,"props":4318,"children":4319},{},[4320],{"type":26,"value":791},{"type":21,"tag":22,"props":4322,"children":4323},{},[4324,4325,4330,4331,4335],{"type":26,"value":796},{"type":21,"tag":34,"props":4326,"children":4328},{"className":4327},[],[4329],{"type":26,"value":777},{"type":26,"value":803},{"type":21,"tag":197,"props":4332,"children":4333},{},[4334],{"type":26,"value":808},{"type":26,"value":810},{"type":21,"tag":42,"props":4337,"children":4340},{"className":4338,"code":4339,"language":47,"meta":8},[45],"import requests\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    'timeout': 10\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[4341],{"type":21,"tag":34,"props":4342,"children":4343},{"__ignoreMap":8},[4344],{"type":26,"value":4339},{"type":21,"tag":22,"props":4346,"children":4347},{},[4348],{"type":26,"value":824},{"title":8,"searchDepth":59,"depth":59,"links":4350},[],"content:guides:python:requests:define-a-time-limit.md","guides/python/requests/define-a-time-limit.md",{"_path":4354,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":831,"description":4355,"language":11,"library":3680,"property":833,"output":13,"default":3683,"body":4356,"_type":61,"_id":4433,"_source":63,"_file":4434,"_extension":65},"/guides/python/requests/exporting-only-a-specific-set-of-pages","Learn how to export only a specific set of pages from a document using Python and the requests library. This guide offers detailed steps with code samples in Python and the requests library, highlighting how you can export only a specific set of pages from a document using PDFShift's API.",{"type":18,"children":4357,"toc":4431},[4358,4363,4373,4377,4381,4414,4418,4422],{"type":21,"tag":22,"props":4359,"children":4360},{},[4361],{"type":26,"value":4362},"In this guide, we'll show you how to export only a specific set of pages from a document using Python and the requests library to convert them to PDF using PDFShift's API.",{"type":21,"tag":22,"props":4364,"children":4365},{},[4366,4367,4372],{"type":26,"value":845},{"type":21,"tag":34,"props":4368,"children":4370},{"className":4369},[],[4371],{"type":26,"value":833},{"type":26,"value":40},{"type":21,"tag":22,"props":4374,"children":4375},{},[4376],{"type":26,"value":856},{"type":21,"tag":22,"props":4378,"children":4379},{},[4380],{"type":26,"value":861},{"type":21,"tag":124,"props":4382,"children":4383},{},[4384,4394,4404],{"type":21,"tag":128,"props":4385,"children":4386},{},[4387,4388,4393],{"type":26,"value":869},{"type":21,"tag":34,"props":4389,"children":4391},{"className":4390},[],[4392],{"type":26,"value":875},{"type":26,"value":877},{"type":21,"tag":128,"props":4395,"children":4396},{},[4397,4398,4403],{"type":26,"value":882},{"type":21,"tag":34,"props":4399,"children":4401},{"className":4400},[],[4402],{"type":26,"value":888},{"type":26,"value":890},{"type":21,"tag":128,"props":4405,"children":4406},{},[4407,4408,4413],{"type":26,"value":895},{"type":21,"tag":34,"props":4409,"children":4411},{"className":4410},[],[4412],{"type":26,"value":901},{"type":26,"value":903},{"type":21,"tag":22,"props":4415,"children":4416},{},[4417],{"type":26,"value":908},{"type":21,"tag":22,"props":4419,"children":4420},{},[4421],{"type":26,"value":208},{"type":21,"tag":42,"props":4423,"children":4426},{"className":4424,"code":4425,"language":47,"meta":8},[45],"import requests\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\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[4427],{"type":21,"tag":34,"props":4428,"children":4429},{"__ignoreMap":8},[4430],{"type":26,"value":4425},{"title":8,"searchDepth":59,"depth":59,"links":4432},[],"content:guides:python:requests:exporting-only-a-specific-set-of-pages.md","guides/python/requests/exporting-only-a-specific-set-of-pages.md",{"_path":4436,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":928,"description":4437,"language":11,"library":3680,"property":930,"output":13,"default":3683,"body":4438,"_type":61,"_id":4541,"_source":63,"_file":4542,"_extension":65},"/guides/python/requests/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 requests library to help you generate full-height documents with PDFShift's API.",{"type":18,"children":4439,"toc":4539},[4440,4445,4461,4470,4474,4483,4499,4503,4511],{"type":21,"tag":22,"props":4441,"children":4442},{},[4443],{"type":26,"value":4444},"In this guide, we'll show you how to generate a document with full height dynamically using Python and the requests library to convert them to PDF using PDFShift's API.",{"type":21,"tag":22,"props":4446,"children":4447},{},[4448,4449,4454,4455,4460],{"type":26,"value":942},{"type":21,"tag":34,"props":4450,"children":4452},{"className":4451},[],[4453],{"type":26,"value":930},{"type":26,"value":949},{"type":21,"tag":34,"props":4456,"children":4458},{"className":4457},[],[4459],{"type":26,"value":955},{"type":26,"value":957},{"type":21,"tag":42,"props":4462,"children":4465},{"className":4463,"code":4464,"language":47,"meta":8},[45],"import requests\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\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[4466],{"type":21,"tag":34,"props":4467,"children":4468},{"__ignoreMap":8},[4469],{"type":26,"value":4464},{"type":21,"tag":22,"props":4471,"children":4472},{},[4473],{"type":26,"value":971},{"type":21,"tag":22,"props":4475,"children":4476},{},[4477,4478],{"type":26,"value":976},{"type":21,"tag":34,"props":4479,"children":4481},{"className":4480},[],[4482],{"type":26,"value":982},{"type":21,"tag":22,"props":4484,"children":4485},{},[4486,4487,4492,4493,4498],{"type":26,"value":987},{"type":21,"tag":34,"props":4488,"children":4490},{"className":4489},[],[4491],{"type":26,"value":993},{"type":26,"value":723},{"type":21,"tag":34,"props":4494,"children":4496},{"className":4495},[],[4497],{"type":26,"value":147},{"type":26,"value":1001},{"type":21,"tag":22,"props":4500,"children":4501},{},[4502],{"type":26,"value":1006},{"type":21,"tag":42,"props":4504,"children":4506},{"className":4505,"code":1010,"language":572,"meta":8},[571],[4507],{"type":21,"tag":34,"props":4508,"children":4509},{"__ignoreMap":8},[4510],{"type":26,"value":1010},{"type":21,"tag":22,"props":4512,"children":4513},{},[4514,4515,4520,4521,4526,4527,4532,4533,4538],{"type":26,"value":1020},{"type":21,"tag":34,"props":4516,"children":4518},{"className":4517},[],[4519],{"type":26,"value":955},{"type":26,"value":1027},{"type":21,"tag":34,"props":4522,"children":4524},{"className":4523},[],[4525],{"type":26,"value":1033},{"type":26,"value":1035},{"type":21,"tag":34,"props":4528,"children":4530},{"className":4529},[],[4531],{"type":26,"value":1041},{"type":26,"value":1043},{"type":21,"tag":34,"props":4534,"children":4536},{"className":4535},[],[4537],{"type":26,"value":1049},{"type":26,"value":1051},{"title":8,"searchDepth":59,"depth":59,"links":4540},[],"content:guides:python:requests:generate-a-document-with-full-height.md","guides/python/requests/generate-a-document-with-full-height.md",{"_path":4544,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":1058,"description":4545,"language":11,"library":3680,"property":1060,"output":13,"related":4546,"default":3683,"body":4547,"_type":61,"_id":4578,"_source":63,"_file":4579,"_extension":65},"/guides/python/requests/loading-css-from-a-string","Follow this guide to load custom CSS as a given string when converting an HTML document to PDF with PDFShift's API. This guide provides Python code samples with the requests library.",[1062,73,74,75],{"type":18,"children":4548,"toc":4576},[4549,4553,4557,4566],{"type":21,"tag":22,"props":4550,"children":4551},{},[4552],{"type":26,"value":1069},{"type":21,"tag":22,"props":4554,"children":4555},{},[4556],{"type":26,"value":1074},{"type":21,"tag":42,"props":4558,"children":4561},{"className":4559,"code":4560,"language":47,"meta":8},[45],"import requests\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    'css': 'body { background-color: #f00; }'\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[4562],{"type":21,"tag":34,"props":4563,"children":4564},{"__ignoreMap":8},[4565],{"type":26,"value":4560},{"type":21,"tag":22,"props":4567,"children":4568},{},[4569,4570,4575],{"type":26,"value":115},{"type":21,"tag":34,"props":4571,"children":4573},{"className":4572},[],[4574],{"type":26,"value":1060},{"type":26,"value":1094},{"title":8,"searchDepth":59,"depth":59,"links":4577},[],"content:guides:python:requests:loading-css-from-a-string.md","guides/python/requests/loading-css-from-a-string.md",{"_path":4581,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":1101,"description":4582,"language":11,"library":3680,"property":1060,"output":13,"related":4583,"default":3683,"body":4584,"_type":61,"_id":4619,"_source":63,"_file":4620,"_extension":65},"/guides/python/requests/loading-css-from-a-url","This guides shows you how to add a custom CSS from an URL onto your document to customize the output of your generated PDF. Follow this guides to learn how to do it using Python and the requests library and see how it can quickly be implemented using the PDFShift's API.",[1062,72,74,75],{"type":18,"children":4585,"toc":4617},[4586,4590,4594,4598,4607],{"type":21,"tag":22,"props":4587,"children":4588},{},[4589],{"type":26,"value":1110},{"type":21,"tag":22,"props":4591,"children":4592},{},[4593],{"type":26,"value":1074},{"type":21,"tag":22,"props":4595,"children":4596},{},[4597],{"type":26,"value":1119},{"type":21,"tag":42,"props":4599,"children":4602},{"className":4600,"code":4601,"language":47,"meta":8},[45],"import requests\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    'css': \"https://www.example.com/public/style/print.css\"\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[4603],{"type":21,"tag":34,"props":4604,"children":4605},{"__ignoreMap":8},[4606],{"type":26,"value":4601},{"type":21,"tag":22,"props":4608,"children":4609},{},[4610,4611,4616],{"type":26,"value":115},{"type":21,"tag":34,"props":4612,"children":4614},{"className":4613},[],[4615],{"type":26,"value":1060},{"type":26,"value":1094},{"title":8,"searchDepth":59,"depth":59,"links":4618},[],"content:guides:python:requests:loading-css-from-a-url.md","guides/python/requests/loading-css-from-a-url.md",{"_path":4622,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":1145,"description":4623,"language":11,"library":3680,"property":1147,"output":13,"related":4624,"default":3683,"body":4625,"_type":61,"_id":4656,"_source":63,"_file":4657,"_extension":65},"/guides/python/requests/loading-javascript-from-a-string","Follow this guide to learn how to add custom javascript to your page to customize the output of your generated PDF. This allows you to modify elements on the page, add or remove content, etc. This guide uses Python and the requests library and relies on the PDFShift's API.",[1062,72,73,75],{"type":18,"children":4626,"toc":4654},[4627,4631,4635,4644],{"type":21,"tag":22,"props":4628,"children":4629},{},[4630],{"type":26,"value":1155},{"type":21,"tag":22,"props":4632,"children":4633},{},[4634],{"type":26,"value":1160},{"type":21,"tag":42,"props":4636,"children":4639},{"className":4637,"code":4638,"language":47,"meta":8},[45],"import requests\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    'javascript': 'document.querySelector(\"h1\").style.color = \"red\";'\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[4640],{"type":21,"tag":34,"props":4641,"children":4642},{"__ignoreMap":8},[4643],{"type":26,"value":4638},{"type":21,"tag":22,"props":4645,"children":4646},{},[4647,4648,4653],{"type":26,"value":115},{"type":21,"tag":34,"props":4649,"children":4651},{"className":4650},[],[4652],{"type":26,"value":1147},{"type":26,"value":1180},{"title":8,"searchDepth":59,"depth":59,"links":4655},[],"content:guides:python:requests:loading-javascript-from-a-string.md","guides/python/requests/loading-javascript-from-a-string.md",{"_path":4659,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":1187,"description":4660,"language":11,"library":3680,"property":1147,"output":13,"related":4661,"default":3683,"body":4662,"_type":61,"_id":4697,"_source":63,"_file":4698,"_extension":65},"/guides/python/requests/loading-javascript-from-a-url","Follow this guide to add custom javascript to your page before converting it to PDF. Using a URL allows you to later be able to change the content of the javascript without having to update the query made to PDFShift. Learn how you can implement this using Python and the requests library to call the PDFShift's API.",[1062,72,73,74],{"type":18,"children":4663,"toc":4695},[4664,4668,4672,4676,4685],{"type":21,"tag":22,"props":4665,"children":4666},{},[4667],{"type":26,"value":1196},{"type":21,"tag":22,"props":4669,"children":4670},{},[4671],{"type":26,"value":1201},{"type":21,"tag":22,"props":4673,"children":4674},{},[4675],{"type":26,"value":1206},{"type":21,"tag":42,"props":4677,"children":4680},{"className":4678,"code":4679,"language":47,"meta":8},[45],"import requests\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    'javascript': 'https://www.example.com/custom.js'\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[4681],{"type":21,"tag":34,"props":4682,"children":4683},{"__ignoreMap":8},[4684],{"type":26,"value":4679},{"type":21,"tag":22,"props":4686,"children":4687},{},[4688,4689,4694],{"type":26,"value":115},{"type":21,"tag":34,"props":4690,"children":4692},{"className":4691},[],[4693],{"type":26,"value":1147},{"type":26,"value":1226},{"title":8,"searchDepth":59,"depth":59,"links":4696},[],"content:guides:python:requests:loading-javascript-from-a-url.md","guides/python/requests/loading-javascript-from-a-url.md",{"_path":4700,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":1233,"description":4701,"language":11,"library":3680,"property":1235,"output":13,"related":4702,"default":3683,"body":4703,"_type":61,"_id":4842,"_source":63,"_file":4843,"_extension":65},"/guides/python/requests/protecting-the-generated-pdf","Learn how to protect your generated PDF with encryption for owner and user, and for choosing who can modify, print and/or copy the generated PDF. This guides explains you to do it using Python and the requests library and relies on the PDFShift's API.",[315,477],{"type":18,"children":4704,"toc":4840},[4705,4710,4714,4724,4728,4737,4747,4757,4832],{"type":21,"tag":22,"props":4706,"children":4707},{},[4708],{"type":26,"value":4709},"In this guide, we'll show you how you can protect your generated PDF with encryption for owner and user, and for choosing who can modify, print and/or copy the generated PDF. This guides explains you to do it using Python and the requests library and relies on the PDFShift's API.",{"type":21,"tag":22,"props":4711,"children":4712},{},[4713],{"type":26,"value":1248},{"type":21,"tag":22,"props":4715,"children":4716},{},[4717,4718,4723],{"type":26,"value":1253},{"type":21,"tag":34,"props":4719,"children":4721},{"className":4720},[],[4722],{"type":26,"value":1235},{"type":26,"value":1260},{"type":21,"tag":22,"props":4725,"children":4726},{},[4727],{"type":26,"value":1265},{"type":21,"tag":42,"props":4729,"children":4732},{"className":4730,"code":4731,"language":47,"meta":8},[45],"import requests\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    'protection': {\n        'owner_password': 'owner_password',\n        'user_password': 'user_password',\n        'no_print': True,\n        'no_modify': True\n    }\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[4733],{"type":21,"tag":34,"props":4734,"children":4735},{"__ignoreMap":8},[4736],{"type":26,"value":4731},{"type":21,"tag":22,"props":4738,"children":4739},{},[4740,4741,4746],{"type":26,"value":1279},{"type":21,"tag":34,"props":4742,"children":4744},{"className":4743},[],[4745],{"type":26,"value":1235},{"type":26,"value":1286},{"type":21,"tag":22,"props":4748,"children":4749},{},[4750,4751,4756],{"type":26,"value":115},{"type":21,"tag":34,"props":4752,"children":4754},{"className":4753},[],[4755],{"type":26,"value":1235},{"type":26,"value":1297},{"type":21,"tag":124,"props":4758,"children":4759},{},[4760,4769,4778,4787,4802,4817],{"type":21,"tag":128,"props":4761,"children":4762},{},[4763,4768],{"type":21,"tag":34,"props":4764,"children":4766},{"className":4765},[],[4767],{"type":26,"value":1309},{"type":26,"value":1311},{"type":21,"tag":128,"props":4770,"children":4771},{},[4772,4777],{"type":21,"tag":34,"props":4773,"children":4775},{"className":4774},[],[4776],{"type":26,"value":1320},{"type":26,"value":1322},{"type":21,"tag":128,"props":4779,"children":4780},{},[4781,4786],{"type":21,"tag":34,"props":4782,"children":4784},{"className":4783},[],[4785],{"type":26,"value":1331},{"type":26,"value":1333},{"type":21,"tag":128,"props":4788,"children":4789},{},[4790,4795,4796,4801],{"type":21,"tag":34,"props":4791,"children":4793},{"className":4792},[],[4794],{"type":26,"value":1342},{"type":26,"value":1344},{"type":21,"tag":34,"props":4797,"children":4799},{"className":4798},[],[4800],{"type":26,"value":613},{"type":26,"value":1351},{"type":21,"tag":128,"props":4803,"children":4804},{},[4805,4810,4811,4816],{"type":21,"tag":34,"props":4806,"children":4808},{"className":4807},[],[4809],{"type":26,"value":1360},{"type":26,"value":1344},{"type":21,"tag":34,"props":4812,"children":4814},{"className":4813},[],[4815],{"type":26,"value":613},{"type":26,"value":1368},{"type":21,"tag":128,"props":4818,"children":4819},{},[4820,4825,4826,4831],{"type":21,"tag":34,"props":4821,"children":4823},{"className":4822},[],[4824],{"type":26,"value":1377},{"type":26,"value":1344},{"type":21,"tag":34,"props":4827,"children":4829},{"className":4828},[],[4830],{"type":26,"value":613},{"type":26,"value":1385},{"type":21,"tag":22,"props":4833,"children":4834},{},[4835,4839],{"type":21,"tag":197,"props":4836,"children":4837},{},[4838],{"type":26,"value":1393},{"type":26,"value":1395},{"title":8,"searchDepth":59,"depth":59,"links":4841},[],"content:guides:python:requests:protecting-the-generated-pdf.md","guides/python/requests/protecting-the-generated-pdf.md",{"_path":4845,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":1402,"description":4846,"language":11,"library":3680,"property":1404,"output":13,"related":4847,"default":3683,"body":4848,"_type":61,"_id":4925,"_source":63,"_file":4926,"_extension":65},"/guides/python/requests/receive-a-webhook-event","Receive a notification via a POST request on your server once the conversion was done. This allows you to trigger a massive amount of conversion without having to wait on their results, and get notified once they are done. This guides will show you how to receive webhook events in Python and the requests library to call the PDFShift's API.",[1406,1407],{"type":18,"children":4849,"toc":4923},[4850,4854,4858,4862,4871,4875,4879,4883,4891,4895,4903,4907,4911,4919],{"type":21,"tag":22,"props":4851,"children":4852},{},[4853],{"type":26,"value":1414},{"type":21,"tag":22,"props":4855,"children":4856},{},[4857],{"type":26,"value":1419},{"type":21,"tag":22,"props":4859,"children":4860},{},[4861],{"type":26,"value":1265},{"type":21,"tag":42,"props":4863,"children":4866},{"className":4864,"code":4865,"language":47,"meta":8},[45],"import requests\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    'webhook': 'https://enyygzdj8jy9b.x.pipedream.net/'\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\n\nprint('The PDF document was generated and you will receive an event on your webhook once it is done.')\n",[4867],{"type":21,"tag":34,"props":4868,"children":4869},{"__ignoreMap":8},[4870],{"type":26,"value":4865},{"type":21,"tag":22,"props":4872,"children":4873},{},[4874],{"type":26,"value":1437},{"type":21,"tag":22,"props":4876,"children":4877},{},[4878],{"type":26,"value":1442},{"type":21,"tag":22,"props":4880,"children":4881},{},[4882],{"type":26,"value":1447},{"type":21,"tag":42,"props":4884,"children":4886},{"className":4885,"code":1451,"language":572,"meta":8},[571],[4887],{"type":21,"tag":34,"props":4888,"children":4889},{"__ignoreMap":8},[4890],{"type":26,"value":1451},{"type":21,"tag":22,"props":4892,"children":4893},{},[4894],{"type":26,"value":1461},{"type":21,"tag":42,"props":4896,"children":4898},{"className":4897,"code":1465,"language":572,"meta":8},[571],[4899],{"type":21,"tag":34,"props":4900,"children":4901},{"__ignoreMap":8},[4902],{"type":26,"value":1465},{"type":21,"tag":22,"props":4904,"children":4905},{},[4906],{"type":26,"value":1475},{"type":21,"tag":22,"props":4908,"children":4909},{},[4910],{"type":26,"value":1480},{"type":21,"tag":42,"props":4912,"children":4914},{"className":4913,"code":8,"language":572,"meta":8},[571],[4915],{"type":21,"tag":34,"props":4916,"children":4917},{"__ignoreMap":8},[4918],{"type":26,"value":8},{"type":21,"tag":22,"props":4920,"children":4921},{},[4922],{"type":26,"value":1493},{"title":8,"searchDepth":59,"depth":59,"links":4924},[],"content:guides:python:requests:receive-a-webhook-event.md","guides/python/requests/receive-a-webhook-event.md",{"_path":4928,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":1500,"description":4929,"language":11,"library":3680,"property":1502,"output":13,"related":4930,"default":3683,"body":4931,"_type":61,"_id":5001,"_source":63,"_file":5002,"_extension":65},"/guides/python/requests/save-your-pdf-online-and-get-back-a-url","This guides shows you how can generate a PDF document from HTML and get back an URL instead of the raw PDF. This allows you to share the link directly to your users or redirect them to that page. Learn how you can achieve it using Python and the requests library to call PDFShift's API.",[1407,1504],{"type":18,"children":4932,"toc":4999},[4933,4937,4947,4956,4971,4975,4983,4991],{"type":21,"tag":22,"props":4934,"children":4935},{},[4936],{"type":26,"value":1511},{"type":21,"tag":22,"props":4938,"children":4939},{},[4940,4941,4946],{"type":26,"value":1516},{"type":21,"tag":34,"props":4942,"children":4944},{"className":4943},[],[4945],{"type":26,"value":1502},{"type":26,"value":1523},{"type":21,"tag":42,"props":4948,"children":4951},{"className":4949,"code":4950,"language":47,"meta":8},[45],"import requests\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    'filename': 'example.pdf'\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\n\nprint('The PDF document was generated and is available online via the url in the response')\n",[4952],{"type":21,"tag":34,"props":4953,"children":4954},{"__ignoreMap":8},[4955],{"type":26,"value":4950},{"type":21,"tag":22,"props":4957,"children":4958},{},[4959,4960,4965,4966,4970],{"type":26,"value":1537},{"type":21,"tag":34,"props":4961,"children":4963},{"className":4962},[],[4964],{"type":26,"value":1502},{"type":26,"value":1544},{"type":21,"tag":197,"props":4967,"children":4968},{},[4969],{"type":26,"value":1549},{"type":26,"value":1551},{"type":21,"tag":22,"props":4972,"children":4973},{},[4974],{"type":26,"value":1556},{"type":21,"tag":42,"props":4976,"children":4978},{"className":4977,"code":1560,"language":572,"meta":8},[571],[4979],{"type":21,"tag":34,"props":4980,"children":4981},{"__ignoreMap":8},[4982],{"type":26,"value":1560},{"type":21,"tag":22,"props":4984,"children":4985},{},[4986,4990],{"type":21,"tag":197,"props":4987,"children":4988},{},[4989],{"type":26,"value":201},{"type":26,"value":1574},{"type":21,"tag":22,"props":4992,"children":4993},{},[4994,4998],{"type":21,"tag":197,"props":4995,"children":4996},{},[4997],{"type":26,"value":201},{"type":26,"value":1583},{"title":8,"searchDepth":59,"depth":59,"links":5000},[],"content:guides:python:requests:save-your-pdf-online-and-get-back-a-url.md","guides/python/requests/save-your-pdf-online-and-get-back-a-url.md",{"_path":5004,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":1590,"description":5005,"language":11,"library":3680,"property":1592,"output":13,"related":5006,"default":3683,"body":5007,"_type":61,"_id":5094,"_source":63,"_file":5095,"_extension":65},"/guides/python/requests/save-your-pdf-to-your-amazon-s3-bucket","This guides shows you how can generate a PDF document from HTML with PDFShift's API and save it to your own Amazon S3 bucket. This allows you to generate document and automate actions once the document has been created on your bucket. This guides explains you how to do it using Python and the requests library.",[1406,1504],{"type":18,"children":5008,"toc":5092},[5009,5013,5017,5021,5029,5039,5048,5058,5066,5070,5078,5082],{"type":21,"tag":22,"props":5010,"children":5011},{},[5012],{"type":26,"value":1600},{"type":21,"tag":22,"props":5014,"children":5015},{},[5016],{"type":26,"value":1605},{"type":21,"tag":22,"props":5018,"children":5019},{},[5020],{"type":26,"value":1610},{"type":21,"tag":42,"props":5022,"children":5024},{"className":5023,"code":1614,"language":572,"meta":8},[571],[5025],{"type":21,"tag":34,"props":5026,"children":5027},{"__ignoreMap":8},[5028],{"type":26,"value":1614},{"type":21,"tag":22,"props":5030,"children":5031},{},[5032,5033,5038],{"type":26,"value":1624},{"type":21,"tag":34,"props":5034,"children":5036},{"className":5035},[],[5037],{"type":26,"value":1592},{"type":26,"value":1631},{"type":21,"tag":42,"props":5040,"children":5043},{"className":5041,"code":5042,"language":47,"meta":8},[45],"import requests\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    's3_destination': 's3://DOC-EXAMPLE-BUCKET/test/example.pdf'\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\n\nprint('The PDF document was generated and saved to your S3 Bucket')\n",[5044],{"type":21,"tag":34,"props":5045,"children":5046},{"__ignoreMap":8},[5047],{"type":26,"value":5042},{"type":21,"tag":22,"props":5049,"children":5050},{},[5051,5052,5057],{"type":26,"value":1645},{"type":21,"tag":34,"props":5053,"children":5055},{"className":5054},[],[5056],{"type":26,"value":1592},{"type":26,"value":1652},{"type":21,"tag":42,"props":5059,"children":5061},{"className":5060,"code":1656,"language":572,"meta":8},[571],[5062],{"type":21,"tag":34,"props":5063,"children":5064},{"__ignoreMap":8},[5065],{"type":26,"value":1656},{"type":21,"tag":22,"props":5067,"children":5068},{},[5069],{"type":26,"value":1666},{"type":21,"tag":42,"props":5071,"children":5073},{"className":5072,"code":1670,"language":572,"meta":8},[571],[5074],{"type":21,"tag":34,"props":5075,"children":5076},{"__ignoreMap":8},[5077],{"type":26,"value":1670},{"type":21,"tag":22,"props":5079,"children":5080},{},[5081],{"type":26,"value":1680},{"type":21,"tag":22,"props":5083,"children":5084},{},[5085,5086,5091],{"type":26,"value":1685},{"type":21,"tag":34,"props":5087,"children":5089},{"className":5088},[],[5090],{"type":26,"value":1404},{"type":26,"value":1692},{"title":8,"searchDepth":59,"depth":59,"links":5093},[],"content:guides:python:requests:save-your-pdf-to-your-amazon-s3-bucket.md","guides/python/requests/save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":5097,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":1699,"description":5098,"language":11,"library":3680,"property":1701,"output":13,"related":5099,"default":3683,"body":5100,"_type":61,"_id":5125,"_source":63,"_file":5126,"_extension":65},"/guides/python/requests/send-custom-http-headers","Learn how to add custom HTTP headers when requesting an URL to be converted in PDF with PDFShift's API. It allows you to add specific headers that your backend can check against to authenticate a query before converting it to PDF. This guide explains you how using Python and the requests library.",[16,1703],{"type":18,"children":5101,"toc":5123},[5102,5106,5110,5119],{"type":21,"tag":22,"props":5103,"children":5104},{},[5105],{"type":26,"value":1710},{"type":21,"tag":22,"props":5107,"children":5108},{},[5109],{"type":26,"value":1715},{"type":21,"tag":42,"props":5111,"children":5114},{"className":5112,"code":5113,"language":47,"meta":8},[45],"import requests\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    'http_headers': {\n        'x-custom-header': 'custom-value',\n        'Authorization': 'Bearer {token}'  # This allows you to authenticate PDFShift to your service in a custom way\n    }\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[5115],{"type":21,"tag":34,"props":5116,"children":5117},{"__ignoreMap":8},[5118],{"type":26,"value":5113},{"type":21,"tag":22,"props":5120,"children":5121},{},[5122],{"type":26,"value":1729},{"title":8,"searchDepth":59,"depth":59,"links":5124},[],"content:guides:python:requests:send-custom-http-headers.md","guides/python/requests/send-custom-http-headers.md",{"_path":5128,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":1736,"description":5129,"language":11,"library":3680,"property":1738,"output":13,"related":5130,"default":3683,"body":5131,"_type":61,"_id":5211,"_source":63,"_file":5212,"_extension":65},"/guides/python/requests/using-cookies","Learn how to add custom Cookies when requesting an URL to be converted in PDF with PDFShift's API. It allows you to pursue an active session for instance, that will authenticate the request as a specific user before converting the page to PDF. This guide explains you how using Python and the requests library.",[15,1703],{"type":18,"children":5132,"toc":5209},[5133,5137,5147,5156,5166,5205],{"type":21,"tag":22,"props":5134,"children":5135},{},[5136],{"type":26,"value":1746},{"type":21,"tag":22,"props":5138,"children":5139},{},[5140,5141,5146],{"type":26,"value":1751},{"type":21,"tag":34,"props":5142,"children":5144},{"className":5143},[],[5145],{"type":26,"value":1738},{"type":26,"value":1758},{"type":21,"tag":42,"props":5148,"children":5151},{"className":5149,"code":5150,"language":47,"meta":8},[45],"import requests\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    # The \"cookies\" parameter expects a list of dictionnary that contains the name and the value of the cookies\n    'cookies': [\n        { 'name': 'PHPSESSID', 'value': 'el4ukv0kqbvoirg7nkp4dncpk3' }\n    ]\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[5152],{"type":21,"tag":34,"props":5153,"children":5154},{"__ignoreMap":8},[5155],{"type":26,"value":5150},{"type":21,"tag":22,"props":5157,"children":5158},{},[5159,5160,5165],{"type":26,"value":115},{"type":21,"tag":34,"props":5161,"children":5163},{"className":5162},[],[5164],{"type":26,"value":1738},{"type":26,"value":1778},{"type":21,"tag":124,"props":5167,"children":5168},{},[5169,5178,5187,5196],{"type":21,"tag":128,"props":5170,"children":5171},{},[5172,5177],{"type":21,"tag":34,"props":5173,"children":5175},{"className":5174},[],[5176],{"type":26,"value":1790},{"type":26,"value":1792},{"type":21,"tag":128,"props":5179,"children":5180},{},[5181,5186],{"type":21,"tag":34,"props":5182,"children":5184},{"className":5183},[],[5185],{"type":26,"value":1801},{"type":26,"value":1803},{"type":21,"tag":128,"props":5188,"children":5189},{},[5190,5195],{"type":21,"tag":34,"props":5191,"children":5193},{"className":5192},[],[5194],{"type":26,"value":1812},{"type":26,"value":1814},{"type":21,"tag":128,"props":5197,"children":5198},{},[5199,5204],{"type":21,"tag":34,"props":5200,"children":5202},{"className":5201},[],[5203],{"type":26,"value":1823},{"type":26,"value":1825},{"type":21,"tag":22,"props":5206,"children":5207},{},[5208],{"type":26,"value":1830},{"title":8,"searchDepth":59,"depth":59,"links":5210},[],"content:guides:python:requests:using-cookies.md","guides/python/requests/using-cookies.md",{"_path":5214,"_dir":3680,"_draft":7,"_partial":7,"_locale":8,"title":1837,"description":5215,"language":11,"library":3680,"property":1839,"output":13,"related":5216,"default":3683,"body":5217,"_type":61,"_id":5353,"_source":63,"_file":5354,"_extension":65},"/guides/python/requests/waiting-for-a-custom-element-to-be-ready","Learn how to set up a custom javascript function that will waits for a specific condition to become true before allowing the conversion to happen. This is very interesting for waiting on charts to be generated, or custom fonts to be loaded. With PDFShift's API, this can easily be done using Python and the requests library.",[1841,74],{"type":18,"children":5218,"toc":5351},[5219,5229,5239,5248,5258,5267,5271,5279,5307,5316,5320,5329],{"type":21,"tag":22,"props":5220,"children":5221},{},[5222,5223,5228],{"type":26,"value":115},{"type":21,"tag":34,"props":5224,"children":5226},{"className":5225},[],[5227],{"type":26,"value":1839},{"type":26,"value":1854},{"type":21,"tag":22,"props":5230,"children":5231},{},[5232,5233,5238],{"type":26,"value":1859},{"type":21,"tag":34,"props":5234,"children":5236},{"className":5235},[],[5237],{"type":26,"value":1839},{"type":26,"value":1866},{"type":21,"tag":22,"props":5240,"children":5241},{},[5242,5243,5247],{"type":26,"value":1871},{"type":21,"tag":104,"props":5244,"children":5245},{},[5246],{"type":26,"value":1876},{"type":26,"value":1878},{"type":21,"tag":22,"props":5249,"children":5250},{},[5251,5252,5257],{"type":26,"value":1883},{"type":21,"tag":34,"props":5253,"children":5255},{"className":5254},[],[5256],{"type":26,"value":1839},{"type":26,"value":1890},{"type":21,"tag":22,"props":5259,"children":5260},{},[5261,5262,5266],{"type":26,"value":1895},{"type":21,"tag":197,"props":5263,"children":5264},{},[5265],{"type":26,"value":1900},{"type":26,"value":181},{"type":21,"tag":22,"props":5268,"children":5269},{},[5270],{"type":26,"value":1906},{"type":21,"tag":42,"props":5272,"children":5274},{"className":5273,"code":1911,"language":1147,"meta":8},[1910],[5275],{"type":21,"tag":34,"props":5276,"children":5277},{"__ignoreMap":8},[5278],{"type":26,"value":1911},{"type":21,"tag":22,"props":5280,"children":5281},{},[5282,5283,5288,5289,5294,5295,5300,5301,5306],{"type":26,"value":1921},{"type":21,"tag":34,"props":5284,"children":5286},{"className":5285},[],[5287],{"type":26,"value":1839},{"type":26,"value":607},{"type":21,"tag":34,"props":5290,"children":5292},{"className":5291},[],[5293],{"type":26,"value":1933},{"type":26,"value":1935},{"type":21,"tag":34,"props":5296,"children":5298},{"className":5297},[],[5299],{"type":26,"value":1933},{"type":26,"value":1942},{"type":21,"tag":34,"props":5302,"children":5304},{"className":5303},[],[5305],{"type":26,"value":642},{"type":26,"value":1949},{"type":21,"tag":42,"props":5308,"children":5311},{"className":5309,"code":5310,"language":47,"meta":8},[45],"import requests\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    'wait_for': 'isPageReady'\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[5312],{"type":21,"tag":34,"props":5313,"children":5314},{"__ignoreMap":8},[5315],{"type":26,"value":5310},{"type":21,"tag":22,"props":5317,"children":5318},{},[5319],{"type":26,"value":1963},{"type":21,"tag":42,"props":5321,"children":5324},{"className":5322,"code":5323,"language":47,"meta":8},[45],"import requests\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    'javascript': 'let isFontReady = false; document.fonts.ready.then(() => isFontReady = true); function isPageReady() { return isFontReady; }',\n    'wait_for': 'isPageReady'\n}\n\nresponse = requests.post(\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={'X-API-Key': api_key},\n    json=params\n)\nresponse.raise_for_status()\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",[5325],{"type":21,"tag":34,"props":5326,"children":5327},{"__ignoreMap":8},[5328],{"type":26,"value":5323},{"type":21,"tag":22,"props":5330,"children":5331},{},[5332,5333,5338,5339,5344,5345,5350],{"type":26,"value":1977},{"type":21,"tag":34,"props":5334,"children":5336},{"className":5335},[],[5337],{"type":26,"value":642},{"type":26,"value":1984},{"type":21,"tag":34,"props":5340,"children":5342},{"className":5341},[],[5343],{"type":26,"value":1933},{"type":26,"value":1991},{"type":21,"tag":34,"props":5346,"children":5348},{"className":5347},[],[5349],{"type":26,"value":1933},{"type":26,"value":1998},{"title":8,"searchDepth":59,"depth":59,"links":5352},[],"content:guides:python:requests:waiting-for-a-custom-element-to-be-ready.md","guides/python/requests/waiting-for-a-custom-element-to-be-ready.md",{"_path":5356,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":5358,"language":11,"library":5357,"property":12,"output":13,"related":5359,"default":7,"body":5360,"_type":61,"_id":5392,"_source":63,"_file":5393,"_extension":65},"/guides/python/urllib3/accessing-secured-pages","urllib3","Learn how to access secured pages using Python and the urllib3 library. This guide offers detailed steps with code samples in Python and the urllib3 library, highlighting how you can acces page protected by basic authentication to convert them to PDF using PDFShift's API.",[15,16],{"type":18,"children":5361,"toc":5390},[5362,5367,5377,5386],{"type":21,"tag":22,"props":5363,"children":5364},{},[5365],{"type":26,"value":5366},"In this guide, we'll show you how to access secured page (protected by basic authentication) using Python and the urllib3 library to convert them to PDF using PDFShift's API.",{"type":21,"tag":22,"props":5368,"children":5369},{},[5370,5371,5376],{"type":26,"value":32},{"type":21,"tag":34,"props":5372,"children":5374},{"className":5373},[],[5375],{"type":26,"value":12},{"type":26,"value":40},{"type":21,"tag":42,"props":5378,"children":5381},{"className":5379,"code":5380,"language":47,"meta":8},[45],"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    # You can set a basic authentication by passing the \"auth\" property which contains a username and password\n    'auth': {\n        'username': 'user',\n        'password': 'password'\n    }\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.data)\n\nprint('The PDF document was generated and saved to result.pdf')\n",[5382],{"type":21,"tag":34,"props":5383,"children":5384},{"__ignoreMap":8},[5385],{"type":26,"value":5380},{"type":21,"tag":22,"props":5387,"children":5388},{},[5389],{"type":26,"value":57},{"title":8,"searchDepth":59,"depth":59,"links":5391},[],"content:guides:python:urllib3:accessing-secured-pages.md","guides/python/urllib3/accessing-secured-pages.md",{"_path":5395,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":68,"description":5396,"language":11,"library":5357,"property":70,"output":13,"related":5397,"default":7,"body":5398,"_type":61,"_id":5585,"_source":63,"_file":5586,"_extension":65},"/guides/python/urllib3/adding-a-custom-header-or-footer","Discover how to add custom headers or footers to a PDF using Python and the urllib3 library. This in-depth guide includes Python codes that you can easily follow and quickly generate documents with PDFShift's API.",[72,73,74,75],{"type":18,"children":5399,"toc":5583},[5400,5405,5426,5436,5490,5498,5502,5511,5521,5525,5579],{"type":21,"tag":22,"props":5401,"children":5402},{},[5403],{"type":26,"value":5404},"In this guide, we'll show you how to add custom headers or footers to a PDF using Python and the urllib3 library.",{"type":21,"tag":22,"props":5406,"children":5407},{},[5408,5409,5414,5415,5420,5421,5425],{"type":26,"value":87},{"type":21,"tag":34,"props":5410,"children":5412},{"className":5411},[],[5413],{"type":26,"value":70},{"type":26,"value":94},{"type":21,"tag":34,"props":5416,"children":5418},{"className":5417},[],[5419],{"type":26,"value":100},{"type":26,"value":102},{"type":21,"tag":104,"props":5422,"children":5423},{},[5424],{"type":26,"value":108},{"type":26,"value":110},{"type":21,"tag":22,"props":5427,"children":5428},{},[5429,5430,5435],{"type":26,"value":115},{"type":21,"tag":34,"props":5431,"children":5433},{"className":5432},[],[5434],{"type":26,"value":70},{"type":26,"value":122},{"type":21,"tag":124,"props":5437,"children":5438},{},[5439,5448,5481],{"type":21,"tag":128,"props":5440,"children":5441},{},[5442,5447],{"type":21,"tag":34,"props":5443,"children":5445},{"className":5444},[],[5446],{"type":26,"value":136},{"type":26,"value":138},{"type":21,"tag":128,"props":5449,"children":5450},{},[5451,5456,5457,5462,5463,5468,5469,5474,5475,5480],{"type":21,"tag":34,"props":5452,"children":5454},{"className":5453},[],[5455],{"type":26,"value":147},{"type":26,"value":149},{"type":21,"tag":34,"props":5458,"children":5460},{"className":5459},[],[5461],{"type":26,"value":155},{"type":26,"value":157},{"type":21,"tag":34,"props":5464,"children":5466},{"className":5465},[],[5467],{"type":26,"value":163},{"type":26,"value":165},{"type":21,"tag":34,"props":5470,"children":5472},{"className":5471},[],[5473],{"type":26,"value":171},{"type":26,"value":173},{"type":21,"tag":34,"props":5476,"children":5478},{"className":5477},[],[5479],{"type":26,"value":179},{"type":26,"value":181},{"type":21,"tag":128,"props":5482,"children":5483},{},[5484,5489],{"type":21,"tag":34,"props":5485,"children":5487},{"className":5486},[],[5488],{"type":26,"value":190},{"type":26,"value":192},{"type":21,"tag":22,"props":5491,"children":5492},{},[5493,5497],{"type":21,"tag":197,"props":5494,"children":5495},{},[5496],{"type":26,"value":201},{"type":26,"value":203},{"type":21,"tag":22,"props":5499,"children":5500},{},[5501],{"type":26,"value":208},{"type":21,"tag":42,"props":5503,"children":5506},{"className":5504,"code":5505,"language":47,"meta":8},[45],"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://en.wikipedia.org/wiki/PDF',\n    'header': {\n        'source': '\u003Cdiv>Page {{ page }} over a total of {{ total }}. Made on {{ date }}\u003C/div>',\n        'height': 150,\n        'start_at': 2\n    }\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",[5507],{"type":21,"tag":34,"props":5508,"children":5509},{"__ignoreMap":8},[5510],{"type":26,"value":5505},{"type":21,"tag":22,"props":5512,"children":5513},{},[5514,5515,5520],{"type":26,"value":115},{"type":21,"tag":34,"props":5516,"children":5518},{"className":5517},[],[5519],{"type":26,"value":136},{"type":26,"value":228},{"type":21,"tag":22,"props":5522,"children":5523},{},[5524],{"type":26,"value":233},{"type":21,"tag":124,"props":5526,"children":5527},{},[5528,5537,5546,5555,5564],{"type":21,"tag":128,"props":5529,"children":5530},{},[5531,5536],{"type":21,"tag":34,"props":5532,"children":5534},{"className":5533},[],[5535],{"type":26,"value":245},{"type":26,"value":247},{"type":21,"tag":128,"props":5538,"children":5539},{},[5540,5545],{"type":21,"tag":34,"props":5541,"children":5543},{"className":5542},[],[5544],{"type":26,"value":256},{"type":26,"value":258},{"type":21,"tag":128,"props":5547,"children":5548},{},[5549,5554],{"type":21,"tag":34,"props":5550,"children":5552},{"className":5551},[],[5553],{"type":26,"value":267},{"type":26,"value":269},{"type":21,"tag":128,"props":5556,"children":5557},{},[5558,5563],{"type":21,"tag":34,"props":5559,"children":5561},{"className":5560},[],[5562],{"type":26,"value":278},{"type":26,"value":280},{"type":21,"tag":128,"props":5565,"children":5566},{},[5567,5572,5573,5578],{"type":21,"tag":34,"props":5568,"children":5570},{"className":5569},[],[5571],{"type":26,"value":289},{"type":26,"value":291},{"type":21,"tag":34,"props":5574,"children":5576},{"className":5575},[],[5577],{"type":26,"value":297},{"type":26,"value":299},{"type":21,"tag":22,"props":5580,"children":5581},{},[5582],{"type":26,"value":304},{"title":8,"searchDepth":59,"depth":59,"links":5584},[],"content:guides:python:urllib3:adding-a-custom-header-or-footer.md","guides/python/urllib3/adding-a-custom-header-or-footer.md",{"_path":5588,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":311,"description":5589,"language":11,"library":5357,"property":313,"output":13,"related":5590,"default":7,"body":5591,"_type":61,"_id":5720,"_source":63,"_file":5721,"_extension":65},"/guides/python/urllib3/adding-a-text-watermark","Learn how to add text watermarks to your generated PDF document using Python and the urllib3 library. With this guide, you'll be able to add watermarks on top of your generated PDFs easily with a quick request to PDFShift's API.",[315,316],{"type":18,"children":5592,"toc":5718},[5593,5597,5607,5616,5620,5677,5681,5702,5706,5710],{"type":21,"tag":22,"props":5594,"children":5595},{},[5596],{"type":26,"value":323},{"type":21,"tag":22,"props":5598,"children":5599},{},[5600,5601,5606],{"type":26,"value":328},{"type":21,"tag":34,"props":5602,"children":5604},{"className":5603},[],[5605],{"type":26,"value":313},{"type":26,"value":335},{"type":21,"tag":42,"props":5608,"children":5611},{"className":5609,"code":5610,"language":47,"meta":8},[45],"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    'watermark': {\n        'text': 'PROTECTED DOCUMENT',\n        'offset_x': 'center',\n        'offset_top': 'top'\n    }\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",[5612],{"type":21,"tag":34,"props":5613,"children":5614},{"__ignoreMap":8},[5615],{"type":26,"value":5610},{"type":21,"tag":22,"props":5617,"children":5618},{},[5619],{"type":26,"value":349},{"type":21,"tag":124,"props":5621,"children":5622},{},[5623,5632,5641,5650,5659,5668],{"type":21,"tag":128,"props":5624,"children":5625},{},[5626,5631],{"type":21,"tag":34,"props":5627,"children":5629},{"className":5628},[],[5630],{"type":26,"value":361},{"type":26,"value":363},{"type":21,"tag":128,"props":5633,"children":5634},{},[5635,5640],{"type":21,"tag":34,"props":5636,"children":5638},{"className":5637},[],[5639],{"type":26,"value":372},{"type":26,"value":374},{"type":21,"tag":128,"props":5642,"children":5643},{},[5644,5649],{"type":21,"tag":34,"props":5645,"children":5647},{"className":5646},[],[5648],{"type":26,"value":383},{"type":26,"value":385},{"type":21,"tag":128,"props":5651,"children":5652},{},[5653,5658],{"type":21,"tag":34,"props":5654,"children":5656},{"className":5655},[],[5657],{"type":26,"value":394},{"type":26,"value":396},{"type":21,"tag":128,"props":5660,"children":5661},{},[5662,5667],{"type":21,"tag":34,"props":5663,"children":5665},{"className":5664},[],[5666],{"type":26,"value":405},{"type":26,"value":407},{"type":21,"tag":128,"props":5669,"children":5670},{},[5671,5676],{"type":21,"tag":34,"props":5672,"children":5674},{"className":5673},[],[5675],{"type":26,"value":416},{"type":26,"value":418},{"type":21,"tag":22,"props":5678,"children":5679},{},[5680],{"type":26,"value":423},{"type":21,"tag":124,"props":5682,"children":5683},{},[5684,5693],{"type":21,"tag":128,"props":5685,"children":5686},{},[5687,5692],{"type":21,"tag":34,"props":5688,"children":5690},{"className":5689},[],[5691],{"type":26,"value":435},{"type":26,"value":437},{"type":21,"tag":128,"props":5694,"children":5695},{},[5696,5701],{"type":21,"tag":34,"props":5697,"children":5699},{"className":5698},[],[5700],{"type":26,"value":446},{"type":26,"value":448},{"type":21,"tag":22,"props":5703,"children":5704},{},[5705],{"type":26,"value":453},{"type":21,"tag":22,"props":5707,"children":5708},{},[5709],{"type":26,"value":458},{"type":21,"tag":42,"props":5711,"children":5713},{"className":5712,"code":462,"language":47,"meta":8},[45],[5714],{"type":21,"tag":34,"props":5715,"children":5716},{"__ignoreMap":8},[5717],{"type":26,"value":462},{"title":8,"searchDepth":59,"depth":59,"links":5719},[],"content:guides:python:urllib3:adding-a-text-watermark.md","guides/python/urllib3/adding-a-text-watermark.md",{"_path":5723,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":474,"description":5724,"language":11,"library":5357,"property":313,"output":13,"related":5725,"default":7,"body":5726,"_type":61,"_id":5819,"_source":63,"_file":5820,"_extension":65},"/guides/python/urllib3/adding-an-image-watermark","Discover how to effortlessly add image watermarks to PDFs using Python and the urllib3 library. Our guide shows you how to add images on top of your PDF to protect your document easily. This is easily done with a simple request to PDFShift's API.",[316,477],{"type":18,"children":5727,"toc":5817},[5728,5732,5742,5751,5755,5766,5776,5780,5801,5805,5809],{"type":21,"tag":22,"props":5729,"children":5730},{},[5731],{"type":26,"value":323},{"type":21,"tag":22,"props":5733,"children":5734},{},[5735,5736,5741],{"type":26,"value":328},{"type":21,"tag":34,"props":5737,"children":5739},{"className":5738},[],[5740],{"type":26,"value":313},{"type":26,"value":494},{"type":21,"tag":42,"props":5743,"children":5746},{"className":5744,"code":5745,"language":47,"meta":8},[45],"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    'watermark': {\n        'image': 'https://placekitten.com/200/300',\n        'offset_x': 'center',\n        'offset_top': 'top'\n    }\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",[5747],{"type":21,"tag":34,"props":5748,"children":5749},{"__ignoreMap":8},[5750],{"type":26,"value":5745},{"type":21,"tag":22,"props":5752,"children":5753},{},[5754],{"type":26,"value":508},{"type":21,"tag":124,"props":5756,"children":5757},{},[5758,5762],{"type":21,"tag":128,"props":5759,"children":5760},{},[5761],{"type":26,"value":516},{"type":21,"tag":128,"props":5763,"children":5764},{},[5765],{"type":26,"value":521},{"type":21,"tag":22,"props":5767,"children":5768},{},[5769,5770,5775],{"type":26,"value":526},{"type":21,"tag":34,"props":5771,"children":5773},{"className":5772},[],[5774],{"type":26,"value":532},{"type":26,"value":534},{"type":21,"tag":22,"props":5777,"children":5778},{},[5779],{"type":26,"value":423},{"type":21,"tag":124,"props":5781,"children":5782},{},[5783,5792],{"type":21,"tag":128,"props":5784,"children":5785},{},[5786,5791],{"type":21,"tag":34,"props":5787,"children":5789},{"className":5788},[],[5790],{"type":26,"value":435},{"type":26,"value":437},{"type":21,"tag":128,"props":5793,"children":5794},{},[5795,5800],{"type":21,"tag":34,"props":5796,"children":5798},{"className":5797},[],[5799],{"type":26,"value":446},{"type":26,"value":448},{"type":21,"tag":22,"props":5802,"children":5803},{},[5804],{"type":26,"value":453},{"type":21,"tag":22,"props":5806,"children":5807},{},[5808],{"type":26,"value":458},{"type":21,"tag":42,"props":5810,"children":5812},{"className":5811,"code":462,"language":572,"meta":8},[571],[5813],{"type":21,"tag":34,"props":5814,"children":5815},{"__ignoreMap":8},[5816],{"type":26,"value":462},{"title":8,"searchDepth":59,"depth":59,"links":5818},[],"content:guides:python:urllib3:adding-an-image-watermark.md","guides/python/urllib3/adding-an-image-watermark.md",{"_path":5822,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":584,"description":5823,"language":11,"library":5357,"property":586,"output":13,"related":5824,"default":7,"body":5825,"_type":61,"_id":5874,"_source":63,"_file":5875,"_extension":65},"/guides/python/urllib3/avoid-conversion-on-error","Learn how to avoid the conversion on error when loading the document using Python and the urllib3 library and relies on the PDFShift's API.",[588],{"type":18,"children":5826,"toc":5872},[5827,5831,5847,5856],{"type":21,"tag":22,"props":5828,"children":5829},{},[5830],{"type":26,"value":595},{"type":21,"tag":22,"props":5832,"children":5833},{},[5834,5835,5840,5841,5846],{"type":26,"value":600},{"type":21,"tag":34,"props":5836,"children":5838},{"className":5837},[],[5839],{"type":26,"value":586},{"type":26,"value":607},{"type":21,"tag":34,"props":5842,"children":5844},{"className":5843},[],[5845],{"type":26,"value":613},{"type":26,"value":615},{"type":21,"tag":42,"props":5848,"children":5851},{"className":5849,"code":5850,"language":47,"meta":8},[45],"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.httpstat.us/404',\n    'raise_for_status': True\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",[5852],{"type":21,"tag":34,"props":5853,"children":5854},{"__ignoreMap":8},[5855],{"type":26,"value":5850},{"type":21,"tag":22,"props":5857,"children":5858},{},[5859,5860,5865,5866,5871],{"type":26,"value":629},{"type":21,"tag":34,"props":5861,"children":5863},{"className":5862},[],[5864],{"type":26,"value":586},{"type":26,"value":636},{"type":21,"tag":34,"props":5867,"children":5869},{"className":5868},[],[5870],{"type":26,"value":642},{"type":26,"value":644},{"title":8,"searchDepth":59,"depth":59,"links":5873},[],"content:guides:python:urllib3:avoid-conversion-on-error.md","guides/python/urllib3/avoid-conversion-on-error.md",{"_path":5877,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":651,"description":5878,"language":11,"library":5357,"property":136,"output":13,"related":5879,"default":7,"body":5880,"_type":61,"_id":5901,"_source":63,"_file":5902,"_extension":65},"/guides/python/urllib3/convert-html-to-pdf-from-a-url","Learn how to easily convert HTML documents to PDF from a URL using Python and the urllib3 library. This how-to guide offers clear Python code examples that show developers how to implement this using the PDFShift API.",[588,654],{"type":18,"children":5881,"toc":5899},[5882,5886,5895],{"type":21,"tag":22,"props":5883,"children":5884},{},[5885],{"type":26,"value":661},{"type":21,"tag":42,"props":5887,"children":5890},{"className":5888,"code":5889,"language":47,"meta":8},[45],"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}\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",[5891],{"type":21,"tag":34,"props":5892,"children":5893},{"__ignoreMap":8},[5894],{"type":26,"value":5889},{"type":21,"tag":22,"props":5896,"children":5897},{},[5898],{"type":26,"value":675},{"title":8,"searchDepth":59,"depth":59,"links":5900},[],"content:guides:python:urllib3:convert-html-to-pdf-from-a-url.md","guides/python/urllib3/convert-html-to-pdf-from-a-url.md",{"_path":5904,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":682,"description":5905,"language":11,"library":5357,"output":13,"related":5906,"default":7,"body":5907,"_type":61,"_id":5980,"_source":63,"_file":5981,"_extension":65},"/guides/python/urllib3/convert-html-to-pdf-from-raw-html","Learn how to to convert raw HTML document to PDF using Python and the urllib3 library. Our guide will explain you how to quickly convert documents with PDFShift's API.",[685],{"type":18,"children":5908,"toc":5978},[5909,5914,5929,5945,5955,5959,5968],{"type":21,"tag":22,"props":5910,"children":5911},{},[5912],{"type":26,"value":5913},"In this guide, we'll show you how to convert an HTML document to PDF using Python and the urllib3 library.\nProviding the HTML document as raw as a lot of great advantages :",{"type":21,"tag":124,"props":5915,"children":5916},{},[5917,5921,5925],{"type":21,"tag":128,"props":5918,"children":5919},{},[5920],{"type":26,"value":700},{"type":21,"tag":128,"props":5922,"children":5923},{},[5924],{"type":26,"value":705},{"type":21,"tag":128,"props":5926,"children":5927},{},[5928],{"type":26,"value":710},{"type":21,"tag":22,"props":5930,"children":5931},{},[5932,5933,5938,5939,5944],{"type":26,"value":715},{"type":21,"tag":34,"props":5934,"children":5936},{"className":5935},[],[5937],{"type":26,"value":721},{"type":26,"value":723},{"type":21,"tag":34,"props":5940,"children":5942},{"className":5941},[],[5943],{"type":26,"value":729},{"type":26,"value":731},{"type":21,"tag":22,"props":5946,"children":5947},{},[5948,5949,5954],{"type":26,"value":736},{"type":21,"tag":34,"props":5950,"children":5952},{"className":5951},[],[5953],{"type":26,"value":136},{"type":26,"value":743},{"type":21,"tag":22,"props":5956,"children":5957},{},[5958],{"type":26,"value":208},{"type":21,"tag":42,"props":5960,"children":5963},{"className":5961,"code":5962,"language":47,"meta":8},[45],"import urllib3, json, base64\n\n# You can get an API key at https://pdfshift.io\napi_key = 'sk_xxxxxxxxxxxx'\n\nparams = {\n    'source': '\u003Chtml>\u003Cbody>\u003Ch1>This will be a PDF document\u003C/h1>\u003Cp>This will generate a basic PDF to show how you can add raw HTML\u003C/body>\u003C/html>',\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",[5964],{"type":21,"tag":34,"props":5965,"children":5966},{"__ignoreMap":8},[5967],{"type":26,"value":5962},{"type":21,"tag":22,"props":5969,"children":5970},{},[5971,5972,5977],{"type":26,"value":761},{"type":21,"tag":34,"props":5973,"children":5975},{"className":5974},[],[5976],{"type":26,"value":136},{"type":26,"value":768},{"title":8,"searchDepth":59,"depth":59,"links":5979},[],"content:guides:python:urllib3:convert-html-to-pdf-from-raw-html.md","guides/python/urllib3/convert-html-to-pdf-from-raw-html.md",{"_path":5983,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":775,"description":5984,"language":11,"library":5357,"property":777,"output":13,"related":5985,"default":7,"body":5986,"_type":61,"_id":6026,"_source":63,"_file":6027,"_extension":65},"/guides/python/urllib3/define-a-time-limit","Learn how to set a conversion time limit at PDFShift. This will allow you to define a maximum time for the conversion process to complete, and if the process takes longer than the defined time, the conversion will be aborted. This guides explains you how to achieve it using Python and the urllib3 library.",[779],{"type":18,"children":5987,"toc":6024},[5988,5992,5996,6011,6020],{"type":21,"tag":22,"props":5989,"children":5990},{},[5991],{"type":26,"value":786},{"type":21,"tag":22,"props":5993,"children":5994},{},[5995],{"type":26,"value":791},{"type":21,"tag":22,"props":5997,"children":5998},{},[5999,6000,6005,6006,6010],{"type":26,"value":796},{"type":21,"tag":34,"props":6001,"children":6003},{"className":6002},[],[6004],{"type":26,"value":777},{"type":26,"value":803},{"type":21,"tag":197,"props":6007,"children":6008},{},[6009],{"type":26,"value":808},{"type":26,"value":810},{"type":21,"tag":42,"props":6012,"children":6015},{"className":6013,"code":6014,"language":47,"meta":8},[45],"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    'timeout': 10\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",[6016],{"type":21,"tag":34,"props":6017,"children":6018},{"__ignoreMap":8},[6019],{"type":26,"value":6014},{"type":21,"tag":22,"props":6021,"children":6022},{},[6023],{"type":26,"value":824},{"title":8,"searchDepth":59,"depth":59,"links":6025},[],"content:guides:python:urllib3:define-a-time-limit.md","guides/python/urllib3/define-a-time-limit.md",{"_path":6029,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":831,"description":6030,"language":11,"library":5357,"property":833,"output":13,"default":7,"body":6031,"_type":61,"_id":6108,"_source":63,"_file":6109,"_extension":65},"/guides/python/urllib3/exporting-only-a-specific-set-of-pages","Learn how to export only a specific set of pages from a document using Python and the urllib3 library. This guide offers detailed steps with code samples in Python and the urllib3 library, highlighting how you can export only a specific set of pages from a document using PDFShift's API.",{"type":18,"children":6032,"toc":6106},[6033,6038,6048,6052,6056,6089,6093,6097],{"type":21,"tag":22,"props":6034,"children":6035},{},[6036],{"type":26,"value":6037},"In this guide, we'll show you how to export only a specific set of pages from a document using Python and the urllib3 library to convert them to PDF using PDFShift's API.",{"type":21,"tag":22,"props":6039,"children":6040},{},[6041,6042,6047],{"type":26,"value":845},{"type":21,"tag":34,"props":6043,"children":6045},{"className":6044},[],[6046],{"type":26,"value":833},{"type":26,"value":40},{"type":21,"tag":22,"props":6049,"children":6050},{},[6051],{"type":26,"value":856},{"type":21,"tag":22,"props":6053,"children":6054},{},[6055],{"type":26,"value":861},{"type":21,"tag":124,"props":6057,"children":6058},{},[6059,6069,6079],{"type":21,"tag":128,"props":6060,"children":6061},{},[6062,6063,6068],{"type":26,"value":869},{"type":21,"tag":34,"props":6064,"children":6066},{"className":6065},[],[6067],{"type":26,"value":875},{"type":26,"value":877},{"type":21,"tag":128,"props":6070,"children":6071},{},[6072,6073,6078],{"type":26,"value":882},{"type":21,"tag":34,"props":6074,"children":6076},{"className":6075},[],[6077],{"type":26,"value":888},{"type":26,"value":890},{"type":21,"tag":128,"props":6080,"children":6081},{},[6082,6083,6088],{"type":26,"value":895},{"type":21,"tag":34,"props":6084,"children":6086},{"className":6085},[],[6087],{"type":26,"value":901},{"type":26,"value":903},{"type":21,"tag":22,"props":6090,"children":6091},{},[6092],{"type":26,"value":908},{"type":21,"tag":22,"props":6094,"children":6095},{},[6096],{"type":26,"value":208},{"type":21,"tag":42,"props":6098,"children":6101},{"className":6099,"code":6100,"language":47,"meta":8},[45],"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://en.wikipedia.org/wiki/PDF',\n    'pages': '2-4'\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",[6102],{"type":21,"tag":34,"props":6103,"children":6104},{"__ignoreMap":8},[6105],{"type":26,"value":6100},{"title":8,"searchDepth":59,"depth":59,"links":6107},[],"content:guides:python:urllib3:exporting-only-a-specific-set-of-pages.md","guides/python/urllib3/exporting-only-a-specific-set-of-pages.md",{"_path":6111,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":928,"description":6112,"language":11,"library":5357,"property":930,"output":13,"default":7,"body":6113,"_type":61,"_id":6216,"_source":63,"_file":6217,"_extension":65},"/guides/python/urllib3/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.",{"type":18,"children":6114,"toc":6214},[6115,6120,6136,6145,6149,6158,6174,6178,6186],{"type":21,"tag":22,"props":6116,"children":6117},{},[6118],{"type":26,"value":6119},"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":21,"tag":22,"props":6121,"children":6122},{},[6123,6124,6129,6130,6135],{"type":26,"value":942},{"type":21,"tag":34,"props":6125,"children":6127},{"className":6126},[],[6128],{"type":26,"value":930},{"type":26,"value":949},{"type":21,"tag":34,"props":6131,"children":6133},{"className":6132},[],[6134],{"type":26,"value":955},{"type":26,"value":957},{"type":21,"tag":42,"props":6137,"children":6140},{"className":6138,"code":6139,"language":47,"meta":8},[45],"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",[6141],{"type":21,"tag":34,"props":6142,"children":6143},{"__ignoreMap":8},[6144],{"type":26,"value":6139},{"type":21,"tag":22,"props":6146,"children":6147},{},[6148],{"type":26,"value":971},{"type":21,"tag":22,"props":6150,"children":6151},{},[6152,6153],{"type":26,"value":976},{"type":21,"tag":34,"props":6154,"children":6156},{"className":6155},[],[6157],{"type":26,"value":982},{"type":21,"tag":22,"props":6159,"children":6160},{},[6161,6162,6167,6168,6173],{"type":26,"value":987},{"type":21,"tag":34,"props":6163,"children":6165},{"className":6164},[],[6166],{"type":26,"value":993},{"type":26,"value":723},{"type":21,"tag":34,"props":6169,"children":6171},{"className":6170},[],[6172],{"type":26,"value":147},{"type":26,"value":1001},{"type":21,"tag":22,"props":6175,"children":6176},{},[6177],{"type":26,"value":1006},{"type":21,"tag":42,"props":6179,"children":6181},{"className":6180,"code":1010,"language":572,"meta":8},[571],[6182],{"type":21,"tag":34,"props":6183,"children":6184},{"__ignoreMap":8},[6185],{"type":26,"value":1010},{"type":21,"tag":22,"props":6187,"children":6188},{},[6189,6190,6195,6196,6201,6202,6207,6208,6213],{"type":26,"value":1020},{"type":21,"tag":34,"props":6191,"children":6193},{"className":6192},[],[6194],{"type":26,"value":955},{"type":26,"value":1027},{"type":21,"tag":34,"props":6197,"children":6199},{"className":6198},[],[6200],{"type":26,"value":1033},{"type":26,"value":1035},{"type":21,"tag":34,"props":6203,"children":6205},{"className":6204},[],[6206],{"type":26,"value":1041},{"type":26,"value":1043},{"type":21,"tag":34,"props":6209,"children":6211},{"className":6210},[],[6212],{"type":26,"value":1049},{"type":26,"value":1051},{"title":8,"searchDepth":59,"depth":59,"links":6215},[],"content:guides:python:urllib3:generate-a-document-with-full-height.md","guides/python/urllib3/generate-a-document-with-full-height.md",{"_path":6219,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":1058,"description":6220,"language":11,"library":5357,"property":1060,"output":13,"related":6221,"default":7,"body":6222,"_type":61,"_id":6253,"_source":63,"_file":6254,"_extension":65},"/guides/python/urllib3/loading-css-from-a-string","Follow this guide to load custom CSS as a given string when converting an HTML document to PDF with PDFShift's API. This guide provides Python code samples with the urllib3 library.",[1062,73,74,75],{"type":18,"children":6223,"toc":6251},[6224,6228,6232,6241],{"type":21,"tag":22,"props":6225,"children":6226},{},[6227],{"type":26,"value":1069},{"type":21,"tag":22,"props":6229,"children":6230},{},[6231],{"type":26,"value":1074},{"type":21,"tag":42,"props":6233,"children":6236},{"className":6234,"code":6235,"language":47,"meta":8},[45],"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    'css': 'body { background-color: #f00; }'\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",[6237],{"type":21,"tag":34,"props":6238,"children":6239},{"__ignoreMap":8},[6240],{"type":26,"value":6235},{"type":21,"tag":22,"props":6242,"children":6243},{},[6244,6245,6250],{"type":26,"value":115},{"type":21,"tag":34,"props":6246,"children":6248},{"className":6247},[],[6249],{"type":26,"value":1060},{"type":26,"value":1094},{"title":8,"searchDepth":59,"depth":59,"links":6252},[],"content:guides:python:urllib3:loading-css-from-a-string.md","guides/python/urllib3/loading-css-from-a-string.md",{"_path":6256,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":1101,"description":6257,"language":11,"library":5357,"property":1060,"output":13,"related":6258,"default":7,"body":6259,"_type":61,"_id":6294,"_source":63,"_file":6295,"_extension":65},"/guides/python/urllib3/loading-css-from-a-url","This guides shows you how to add a custom CSS from an URL onto your document to customize the output of your generated PDF. Follow this guides to learn how to do it using Python and the urllib3 library and see how it can quickly be implemented using the PDFShift's API.",[1062,72,74,75],{"type":18,"children":6260,"toc":6292},[6261,6265,6269,6273,6282],{"type":21,"tag":22,"props":6262,"children":6263},{},[6264],{"type":26,"value":1110},{"type":21,"tag":22,"props":6266,"children":6267},{},[6268],{"type":26,"value":1074},{"type":21,"tag":22,"props":6270,"children":6271},{},[6272],{"type":26,"value":1119},{"type":21,"tag":42,"props":6274,"children":6277},{"className":6275,"code":6276,"language":47,"meta":8},[45],"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    'css': \"https://www.example.com/public/style/print.css\"\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",[6278],{"type":21,"tag":34,"props":6279,"children":6280},{"__ignoreMap":8},[6281],{"type":26,"value":6276},{"type":21,"tag":22,"props":6283,"children":6284},{},[6285,6286,6291],{"type":26,"value":115},{"type":21,"tag":34,"props":6287,"children":6289},{"className":6288},[],[6290],{"type":26,"value":1060},{"type":26,"value":1094},{"title":8,"searchDepth":59,"depth":59,"links":6293},[],"content:guides:python:urllib3:loading-css-from-a-url.md","guides/python/urllib3/loading-css-from-a-url.md",{"_path":6297,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":1145,"description":6298,"language":11,"library":5357,"property":1147,"output":13,"related":6299,"default":7,"body":6300,"_type":61,"_id":6331,"_source":63,"_file":6332,"_extension":65},"/guides/python/urllib3/loading-javascript-from-a-string","Follow this guide to learn how to add custom javascript to your page to customize the output of your generated PDF. This allows you to modify elements on the page, add or remove content, etc. This guide uses Python and the urllib3 library and relies on the PDFShift's API.",[1062,72,73,75],{"type":18,"children":6301,"toc":6329},[6302,6306,6310,6319],{"type":21,"tag":22,"props":6303,"children":6304},{},[6305],{"type":26,"value":1155},{"type":21,"tag":22,"props":6307,"children":6308},{},[6309],{"type":26,"value":1160},{"type":21,"tag":42,"props":6311,"children":6314},{"className":6312,"code":6313,"language":47,"meta":8},[45],"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    'javascript': 'document.querySelector(\"h1\").style.color = \"red\";'\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",[6315],{"type":21,"tag":34,"props":6316,"children":6317},{"__ignoreMap":8},[6318],{"type":26,"value":6313},{"type":21,"tag":22,"props":6320,"children":6321},{},[6322,6323,6328],{"type":26,"value":115},{"type":21,"tag":34,"props":6324,"children":6326},{"className":6325},[],[6327],{"type":26,"value":1147},{"type":26,"value":1180},{"title":8,"searchDepth":59,"depth":59,"links":6330},[],"content:guides:python:urllib3:loading-javascript-from-a-string.md","guides/python/urllib3/loading-javascript-from-a-string.md",{"_path":6334,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":1187,"description":6335,"language":11,"library":5357,"property":1147,"output":13,"related":6336,"default":7,"body":6337,"_type":61,"_id":6372,"_source":63,"_file":6373,"_extension":65},"/guides/python/urllib3/loading-javascript-from-a-url","Follow this guide to add custom javascript to your page before converting it to PDF. Using a URL allows you to later be able to change the content of the javascript without having to update the query made to PDFShift. Learn how you can implement this using Python and the urllib3 library to call the PDFShift's API.",[1062,72,73,74],{"type":18,"children":6338,"toc":6370},[6339,6343,6347,6351,6360],{"type":21,"tag":22,"props":6340,"children":6341},{},[6342],{"type":26,"value":1196},{"type":21,"tag":22,"props":6344,"children":6345},{},[6346],{"type":26,"value":1201},{"type":21,"tag":22,"props":6348,"children":6349},{},[6350],{"type":26,"value":1206},{"type":21,"tag":42,"props":6352,"children":6355},{"className":6353,"code":6354,"language":47,"meta":8},[45],"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    'javascript': 'https://www.example.com/custom.js'\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",[6356],{"type":21,"tag":34,"props":6357,"children":6358},{"__ignoreMap":8},[6359],{"type":26,"value":6354},{"type":21,"tag":22,"props":6361,"children":6362},{},[6363,6364,6369],{"type":26,"value":115},{"type":21,"tag":34,"props":6365,"children":6367},{"className":6366},[],[6368],{"type":26,"value":1147},{"type":26,"value":1226},{"title":8,"searchDepth":59,"depth":59,"links":6371},[],"content:guides:python:urllib3:loading-javascript-from-a-url.md","guides/python/urllib3/loading-javascript-from-a-url.md",{"_path":6375,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":1233,"description":6376,"language":11,"library":5357,"property":1235,"output":13,"related":6377,"default":7,"body":6378,"_type":61,"_id":6517,"_source":63,"_file":6518,"_extension":65},"/guides/python/urllib3/protecting-the-generated-pdf","Learn how to protect your generated PDF with encryption for owner and user, and for choosing who can modify, print and/or copy the generated PDF. This guides explains you to do it using Python and the urllib3 library and relies on the PDFShift's API.",[315,477],{"type":18,"children":6379,"toc":6515},[6380,6385,6389,6399,6403,6412,6422,6432,6507],{"type":21,"tag":22,"props":6381,"children":6382},{},[6383],{"type":26,"value":6384},"In this guide, we'll show you how you can protect your generated PDF with encryption for owner and user, and for choosing who can modify, print and/or copy the generated PDF. This guides explains you to do it using Python and the urllib3 library and relies on the PDFShift's API.",{"type":21,"tag":22,"props":6386,"children":6387},{},[6388],{"type":26,"value":1248},{"type":21,"tag":22,"props":6390,"children":6391},{},[6392,6393,6398],{"type":26,"value":1253},{"type":21,"tag":34,"props":6394,"children":6396},{"className":6395},[],[6397],{"type":26,"value":1235},{"type":26,"value":1260},{"type":21,"tag":22,"props":6400,"children":6401},{},[6402],{"type":26,"value":1265},{"type":21,"tag":42,"props":6404,"children":6407},{"className":6405,"code":6406,"language":47,"meta":8},[45],"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    'protection': {\n        'owner_password': 'owner_password',\n        'user_password': 'user_password',\n        'no_print': True,\n        'no_modify': True\n    }\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",[6408],{"type":21,"tag":34,"props":6409,"children":6410},{"__ignoreMap":8},[6411],{"type":26,"value":6406},{"type":21,"tag":22,"props":6413,"children":6414},{},[6415,6416,6421],{"type":26,"value":1279},{"type":21,"tag":34,"props":6417,"children":6419},{"className":6418},[],[6420],{"type":26,"value":1235},{"type":26,"value":1286},{"type":21,"tag":22,"props":6423,"children":6424},{},[6425,6426,6431],{"type":26,"value":115},{"type":21,"tag":34,"props":6427,"children":6429},{"className":6428},[],[6430],{"type":26,"value":1235},{"type":26,"value":1297},{"type":21,"tag":124,"props":6433,"children":6434},{},[6435,6444,6453,6462,6477,6492],{"type":21,"tag":128,"props":6436,"children":6437},{},[6438,6443],{"type":21,"tag":34,"props":6439,"children":6441},{"className":6440},[],[6442],{"type":26,"value":1309},{"type":26,"value":1311},{"type":21,"tag":128,"props":6445,"children":6446},{},[6447,6452],{"type":21,"tag":34,"props":6448,"children":6450},{"className":6449},[],[6451],{"type":26,"value":1320},{"type":26,"value":1322},{"type":21,"tag":128,"props":6454,"children":6455},{},[6456,6461],{"type":21,"tag":34,"props":6457,"children":6459},{"className":6458},[],[6460],{"type":26,"value":1331},{"type":26,"value":1333},{"type":21,"tag":128,"props":6463,"children":6464},{},[6465,6470,6471,6476],{"type":21,"tag":34,"props":6466,"children":6468},{"className":6467},[],[6469],{"type":26,"value":1342},{"type":26,"value":1344},{"type":21,"tag":34,"props":6472,"children":6474},{"className":6473},[],[6475],{"type":26,"value":613},{"type":26,"value":1351},{"type":21,"tag":128,"props":6478,"children":6479},{},[6480,6485,6486,6491],{"type":21,"tag":34,"props":6481,"children":6483},{"className":6482},[],[6484],{"type":26,"value":1360},{"type":26,"value":1344},{"type":21,"tag":34,"props":6487,"children":6489},{"className":6488},[],[6490],{"type":26,"value":613},{"type":26,"value":1368},{"type":21,"tag":128,"props":6493,"children":6494},{},[6495,6500,6501,6506],{"type":21,"tag":34,"props":6496,"children":6498},{"className":6497},[],[6499],{"type":26,"value":1377},{"type":26,"value":1344},{"type":21,"tag":34,"props":6502,"children":6504},{"className":6503},[],[6505],{"type":26,"value":613},{"type":26,"value":1385},{"type":21,"tag":22,"props":6508,"children":6509},{},[6510,6514],{"type":21,"tag":197,"props":6511,"children":6512},{},[6513],{"type":26,"value":1393},{"type":26,"value":1395},{"title":8,"searchDepth":59,"depth":59,"links":6516},[],"content:guides:python:urllib3:protecting-the-generated-pdf.md","guides/python/urllib3/protecting-the-generated-pdf.md",{"_path":6520,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":1402,"description":6521,"language":11,"library":5357,"property":1404,"output":13,"related":6522,"default":7,"body":6523,"_type":61,"_id":6600,"_source":63,"_file":6601,"_extension":65},"/guides/python/urllib3/receive-a-webhook-event","Receive a notification via a POST request on your server once the conversion was done. This allows you to trigger a massive amount of conversion without having to wait on their results, and get notified once they are done. This guides will show you how to receive webhook events in Python and the urllib3 library to call the PDFShift's API.",[1406,1407],{"type":18,"children":6524,"toc":6598},[6525,6529,6533,6537,6546,6550,6554,6558,6566,6570,6578,6582,6586,6594],{"type":21,"tag":22,"props":6526,"children":6527},{},[6528],{"type":26,"value":1414},{"type":21,"tag":22,"props":6530,"children":6531},{},[6532],{"type":26,"value":1419},{"type":21,"tag":22,"props":6534,"children":6535},{},[6536],{"type":26,"value":1265},{"type":21,"tag":42,"props":6538,"children":6541},{"className":6539,"code":6540,"language":47,"meta":8},[45],"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    'webhook': 'https://enyygzdj8jy9b.x.pipedream.net/'\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\nprint('The PDF document was generated and you will receive an event on your webhook once it is done.')\n",[6542],{"type":21,"tag":34,"props":6543,"children":6544},{"__ignoreMap":8},[6545],{"type":26,"value":6540},{"type":21,"tag":22,"props":6547,"children":6548},{},[6549],{"type":26,"value":1437},{"type":21,"tag":22,"props":6551,"children":6552},{},[6553],{"type":26,"value":1442},{"type":21,"tag":22,"props":6555,"children":6556},{},[6557],{"type":26,"value":1447},{"type":21,"tag":42,"props":6559,"children":6561},{"className":6560,"code":1451,"language":572,"meta":8},[571],[6562],{"type":21,"tag":34,"props":6563,"children":6564},{"__ignoreMap":8},[6565],{"type":26,"value":1451},{"type":21,"tag":22,"props":6567,"children":6568},{},[6569],{"type":26,"value":1461},{"type":21,"tag":42,"props":6571,"children":6573},{"className":6572,"code":1465,"language":572,"meta":8},[571],[6574],{"type":21,"tag":34,"props":6575,"children":6576},{"__ignoreMap":8},[6577],{"type":26,"value":1465},{"type":21,"tag":22,"props":6579,"children":6580},{},[6581],{"type":26,"value":1475},{"type":21,"tag":22,"props":6583,"children":6584},{},[6585],{"type":26,"value":1480},{"type":21,"tag":42,"props":6587,"children":6589},{"className":6588,"code":8,"language":572,"meta":8},[571],[6590],{"type":21,"tag":34,"props":6591,"children":6592},{"__ignoreMap":8},[6593],{"type":26,"value":8},{"type":21,"tag":22,"props":6595,"children":6596},{},[6597],{"type":26,"value":1493},{"title":8,"searchDepth":59,"depth":59,"links":6599},[],"content:guides:python:urllib3:receive-a-webhook-event.md","guides/python/urllib3/receive-a-webhook-event.md",{"_path":6603,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":1500,"description":6604,"language":11,"library":5357,"property":1502,"output":13,"related":6605,"default":7,"body":6606,"_type":61,"_id":6676,"_source":63,"_file":6677,"_extension":65},"/guides/python/urllib3/save-your-pdf-online-and-get-back-a-url","This guides shows you how can generate a PDF document from HTML and get back an URL instead of the raw PDF. This allows you to share the link directly to your users or redirect them to that page. Learn how you can achieve it using Python and the urllib3 library to call PDFShift's API.",[1407,1504],{"type":18,"children":6607,"toc":6674},[6608,6612,6622,6631,6646,6650,6658,6666],{"type":21,"tag":22,"props":6609,"children":6610},{},[6611],{"type":26,"value":1511},{"type":21,"tag":22,"props":6613,"children":6614},{},[6615,6616,6621],{"type":26,"value":1516},{"type":21,"tag":34,"props":6617,"children":6619},{"className":6618},[],[6620],{"type":26,"value":1502},{"type":26,"value":1523},{"type":21,"tag":42,"props":6623,"children":6626},{"className":6624,"code":6625,"language":47,"meta":8},[45],"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    'filename': 'example.pdf'\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\nprint('The PDF document was generated and is available online via the url in the response')\n",[6627],{"type":21,"tag":34,"props":6628,"children":6629},{"__ignoreMap":8},[6630],{"type":26,"value":6625},{"type":21,"tag":22,"props":6632,"children":6633},{},[6634,6635,6640,6641,6645],{"type":26,"value":1537},{"type":21,"tag":34,"props":6636,"children":6638},{"className":6637},[],[6639],{"type":26,"value":1502},{"type":26,"value":1544},{"type":21,"tag":197,"props":6642,"children":6643},{},[6644],{"type":26,"value":1549},{"type":26,"value":1551},{"type":21,"tag":22,"props":6647,"children":6648},{},[6649],{"type":26,"value":1556},{"type":21,"tag":42,"props":6651,"children":6653},{"className":6652,"code":1560,"language":572,"meta":8},[571],[6654],{"type":21,"tag":34,"props":6655,"children":6656},{"__ignoreMap":8},[6657],{"type":26,"value":1560},{"type":21,"tag":22,"props":6659,"children":6660},{},[6661,6665],{"type":21,"tag":197,"props":6662,"children":6663},{},[6664],{"type":26,"value":201},{"type":26,"value":1574},{"type":21,"tag":22,"props":6667,"children":6668},{},[6669,6673],{"type":21,"tag":197,"props":6670,"children":6671},{},[6672],{"type":26,"value":201},{"type":26,"value":1583},{"title":8,"searchDepth":59,"depth":59,"links":6675},[],"content:guides:python:urllib3:save-your-pdf-online-and-get-back-a-url.md","guides/python/urllib3/save-your-pdf-online-and-get-back-a-url.md",{"_path":6679,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":1590,"description":6680,"language":11,"library":5357,"property":1592,"output":13,"related":6681,"default":7,"body":6682,"_type":61,"_id":6769,"_source":63,"_file":6770,"_extension":65},"/guides/python/urllib3/save-your-pdf-to-your-amazon-s3-bucket","This guides shows you how can generate a PDF document from HTML with PDFShift's API and save it to your own Amazon S3 bucket. This allows you to generate document and automate actions once the document has been created on your bucket. This guides explains you how to do it using Python and the urllib3 library.",[1406,1504],{"type":18,"children":6683,"toc":6767},[6684,6688,6692,6696,6704,6714,6723,6733,6741,6745,6753,6757],{"type":21,"tag":22,"props":6685,"children":6686},{},[6687],{"type":26,"value":1600},{"type":21,"tag":22,"props":6689,"children":6690},{},[6691],{"type":26,"value":1605},{"type":21,"tag":22,"props":6693,"children":6694},{},[6695],{"type":26,"value":1610},{"type":21,"tag":42,"props":6697,"children":6699},{"className":6698,"code":1614,"language":572,"meta":8},[571],[6700],{"type":21,"tag":34,"props":6701,"children":6702},{"__ignoreMap":8},[6703],{"type":26,"value":1614},{"type":21,"tag":22,"props":6705,"children":6706},{},[6707,6708,6713],{"type":26,"value":1624},{"type":21,"tag":34,"props":6709,"children":6711},{"className":6710},[],[6712],{"type":26,"value":1592},{"type":26,"value":1631},{"type":21,"tag":42,"props":6715,"children":6718},{"className":6716,"code":6717,"language":47,"meta":8},[45],"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    's3_destination': 's3://DOC-EXAMPLE-BUCKET/test/example.pdf'\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\nprint('The PDF document was generated and saved to your S3 Bucket')\n",[6719],{"type":21,"tag":34,"props":6720,"children":6721},{"__ignoreMap":8},[6722],{"type":26,"value":6717},{"type":21,"tag":22,"props":6724,"children":6725},{},[6726,6727,6732],{"type":26,"value":1645},{"type":21,"tag":34,"props":6728,"children":6730},{"className":6729},[],[6731],{"type":26,"value":1592},{"type":26,"value":1652},{"type":21,"tag":42,"props":6734,"children":6736},{"className":6735,"code":1656,"language":572,"meta":8},[571],[6737],{"type":21,"tag":34,"props":6738,"children":6739},{"__ignoreMap":8},[6740],{"type":26,"value":1656},{"type":21,"tag":22,"props":6742,"children":6743},{},[6744],{"type":26,"value":1666},{"type":21,"tag":42,"props":6746,"children":6748},{"className":6747,"code":1670,"language":572,"meta":8},[571],[6749],{"type":21,"tag":34,"props":6750,"children":6751},{"__ignoreMap":8},[6752],{"type":26,"value":1670},{"type":21,"tag":22,"props":6754,"children":6755},{},[6756],{"type":26,"value":1680},{"type":21,"tag":22,"props":6758,"children":6759},{},[6760,6761,6766],{"type":26,"value":1685},{"type":21,"tag":34,"props":6762,"children":6764},{"className":6763},[],[6765],{"type":26,"value":1404},{"type":26,"value":1692},{"title":8,"searchDepth":59,"depth":59,"links":6768},[],"content:guides:python:urllib3:save-your-pdf-to-your-amazon-s3-bucket.md","guides/python/urllib3/save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":6772,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":1699,"description":6773,"language":11,"library":5357,"property":1701,"output":13,"related":6774,"default":7,"body":6775,"_type":61,"_id":6800,"_source":63,"_file":6801,"_extension":65},"/guides/python/urllib3/send-custom-http-headers","Learn how to add custom HTTP headers when requesting an URL to be converted in PDF with PDFShift's API. It allows you to add specific headers that your backend can check against to authenticate a query before converting it to PDF. This guide explains you how using Python and the urllib3 library.",[16,1703],{"type":18,"children":6776,"toc":6798},[6777,6781,6785,6794],{"type":21,"tag":22,"props":6778,"children":6779},{},[6780],{"type":26,"value":1710},{"type":21,"tag":22,"props":6782,"children":6783},{},[6784],{"type":26,"value":1715},{"type":21,"tag":42,"props":6786,"children":6789},{"className":6787,"code":6788,"language":47,"meta":8},[45],"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    'http_headers': {\n        'x-custom-header': 'custom-value',\n        'Authorization': 'Bearer {token}'  # This allows you to authenticate PDFShift to your service in a custom way\n    }\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",[6790],{"type":21,"tag":34,"props":6791,"children":6792},{"__ignoreMap":8},[6793],{"type":26,"value":6788},{"type":21,"tag":22,"props":6795,"children":6796},{},[6797],{"type":26,"value":1729},{"title":8,"searchDepth":59,"depth":59,"links":6799},[],"content:guides:python:urllib3:send-custom-http-headers.md","guides/python/urllib3/send-custom-http-headers.md",{"_path":6803,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":1736,"description":6804,"language":11,"library":5357,"property":1738,"output":13,"related":6805,"default":7,"body":6806,"_type":61,"_id":6886,"_source":63,"_file":6887,"_extension":65},"/guides/python/urllib3/using-cookies","Learn how to add custom Cookies when requesting an URL to be converted in PDF with PDFShift's API. It allows you to pursue an active session for instance, that will authenticate the request as a specific user before converting the page to PDF. This guide explains you how using Python and the urllib3 library.",[15,1703],{"type":18,"children":6807,"toc":6884},[6808,6812,6822,6831,6841,6880],{"type":21,"tag":22,"props":6809,"children":6810},{},[6811],{"type":26,"value":1746},{"type":21,"tag":22,"props":6813,"children":6814},{},[6815,6816,6821],{"type":26,"value":1751},{"type":21,"tag":34,"props":6817,"children":6819},{"className":6818},[],[6820],{"type":26,"value":1738},{"type":26,"value":1758},{"type":21,"tag":42,"props":6823,"children":6826},{"className":6824,"code":6825,"language":47,"meta":8},[45],"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    # The \"cookies\" parameter expects a list of dictionnary that contains the name and the value of the cookies\n    'cookies': [\n        { 'name': 'PHPSESSID', 'value': 'el4ukv0kqbvoirg7nkp4dncpk3' }\n    ]\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",[6827],{"type":21,"tag":34,"props":6828,"children":6829},{"__ignoreMap":8},[6830],{"type":26,"value":6825},{"type":21,"tag":22,"props":6832,"children":6833},{},[6834,6835,6840],{"type":26,"value":115},{"type":21,"tag":34,"props":6836,"children":6838},{"className":6837},[],[6839],{"type":26,"value":1738},{"type":26,"value":1778},{"type":21,"tag":124,"props":6842,"children":6843},{},[6844,6853,6862,6871],{"type":21,"tag":128,"props":6845,"children":6846},{},[6847,6852],{"type":21,"tag":34,"props":6848,"children":6850},{"className":6849},[],[6851],{"type":26,"value":1790},{"type":26,"value":1792},{"type":21,"tag":128,"props":6854,"children":6855},{},[6856,6861],{"type":21,"tag":34,"props":6857,"children":6859},{"className":6858},[],[6860],{"type":26,"value":1801},{"type":26,"value":1803},{"type":21,"tag":128,"props":6863,"children":6864},{},[6865,6870],{"type":21,"tag":34,"props":6866,"children":6868},{"className":6867},[],[6869],{"type":26,"value":1812},{"type":26,"value":1814},{"type":21,"tag":128,"props":6872,"children":6873},{},[6874,6879],{"type":21,"tag":34,"props":6875,"children":6877},{"className":6876},[],[6878],{"type":26,"value":1823},{"type":26,"value":1825},{"type":21,"tag":22,"props":6881,"children":6882},{},[6883],{"type":26,"value":1830},{"title":8,"searchDepth":59,"depth":59,"links":6885},[],"content:guides:python:urllib3:using-cookies.md","guides/python/urllib3/using-cookies.md",{"_path":6889,"_dir":5357,"_draft":7,"_partial":7,"_locale":8,"title":1837,"description":6890,"language":11,"library":5357,"property":1839,"output":13,"related":6891,"default":7,"body":6892,"_type":61,"_id":7028,"_source":63,"_file":7029,"_extension":65},"/guides/python/urllib3/waiting-for-a-custom-element-to-be-ready","Learn how to set up a custom javascript function that will waits for a specific condition to become true before allowing the conversion to happen. This is very interesting for waiting on charts to be generated, or custom fonts to be loaded. With PDFShift's API, this can easily be done using Python and the urllib3 library.",[1841,74],{"type":18,"children":6893,"toc":7026},[6894,6904,6914,6923,6933,6942,6946,6954,6982,6991,6995,7004],{"type":21,"tag":22,"props":6895,"children":6896},{},[6897,6898,6903],{"type":26,"value":115},{"type":21,"tag":34,"props":6899,"children":6901},{"className":6900},[],[6902],{"type":26,"value":1839},{"type":26,"value":1854},{"type":21,"tag":22,"props":6905,"children":6906},{},[6907,6908,6913],{"type":26,"value":1859},{"type":21,"tag":34,"props":6909,"children":6911},{"className":6910},[],[6912],{"type":26,"value":1839},{"type":26,"value":1866},{"type":21,"tag":22,"props":6915,"children":6916},{},[6917,6918,6922],{"type":26,"value":1871},{"type":21,"tag":104,"props":6919,"children":6920},{},[6921],{"type":26,"value":1876},{"type":26,"value":1878},{"type":21,"tag":22,"props":6924,"children":6925},{},[6926,6927,6932],{"type":26,"value":1883},{"type":21,"tag":34,"props":6928,"children":6930},{"className":6929},[],[6931],{"type":26,"value":1839},{"type":26,"value":1890},{"type":21,"tag":22,"props":6934,"children":6935},{},[6936,6937,6941],{"type":26,"value":1895},{"type":21,"tag":197,"props":6938,"children":6939},{},[6940],{"type":26,"value":1900},{"type":26,"value":181},{"type":21,"tag":22,"props":6943,"children":6944},{},[6945],{"type":26,"value":1906},{"type":21,"tag":42,"props":6947,"children":6949},{"className":6948,"code":1911,"language":1147,"meta":8},[1910],[6950],{"type":21,"tag":34,"props":6951,"children":6952},{"__ignoreMap":8},[6953],{"type":26,"value":1911},{"type":21,"tag":22,"props":6955,"children":6956},{},[6957,6958,6963,6964,6969,6970,6975,6976,6981],{"type":26,"value":1921},{"type":21,"tag":34,"props":6959,"children":6961},{"className":6960},[],[6962],{"type":26,"value":1839},{"type":26,"value":607},{"type":21,"tag":34,"props":6965,"children":6967},{"className":6966},[],[6968],{"type":26,"value":1933},{"type":26,"value":1935},{"type":21,"tag":34,"props":6971,"children":6973},{"className":6972},[],[6974],{"type":26,"value":1933},{"type":26,"value":1942},{"type":21,"tag":34,"props":6977,"children":6979},{"className":6978},[],[6980],{"type":26,"value":642},{"type":26,"value":1949},{"type":21,"tag":42,"props":6983,"children":6986},{"className":6984,"code":6985,"language":47,"meta":8},[45],"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    'wait_for': 'isPageReady'\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",[6987],{"type":21,"tag":34,"props":6988,"children":6989},{"__ignoreMap":8},[6990],{"type":26,"value":6985},{"type":21,"tag":22,"props":6992,"children":6993},{},[6994],{"type":26,"value":1963},{"type":21,"tag":42,"props":6996,"children":6999},{"className":6997,"code":6998,"language":47,"meta":8},[45],"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    'javascript': 'let isFontReady = false; document.fonts.ready.then(() => isFontReady = true); function isPageReady() { return isFontReady; }',\n    'wait_for': 'isPageReady'\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",[7000],{"type":21,"tag":34,"props":7001,"children":7002},{"__ignoreMap":8},[7003],{"type":26,"value":6998},{"type":21,"tag":22,"props":7005,"children":7006},{},[7007,7008,7013,7014,7019,7020,7025],{"type":26,"value":1977},{"type":21,"tag":34,"props":7009,"children":7011},{"className":7010},[],[7012],{"type":26,"value":642},{"type":26,"value":1984},{"type":21,"tag":34,"props":7015,"children":7017},{"className":7016},[],[7018],{"type":26,"value":1933},{"type":26,"value":1991},{"type":21,"tag":34,"props":7021,"children":7023},{"className":7022},[],[7024],{"type":26,"value":1933},{"type":26,"value":1998},{"title":8,"searchDepth":59,"depth":59,"links":7027},[],"content:guides:python:urllib3:waiting-for-a-custom-element-to-be-ready.md","guides/python/urllib3/waiting-for-a-custom-element-to-be-ready.md",1785426825477]