[{"data":1,"prerenderedAt":278},["Reactive",2],{"/guides/python/httplib2/protecting-the-generated-pdf":3,"related:LYRd1Ge4Iu":196},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":5,"property":11,"output":12,"related":13,"default":6,"body":16,"_type":191,"_id":192,"_source":193,"_file":194,"_extension":195},"/guides/python/httplib2/protecting-the-generated-pdf","httplib2",false,"","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.","Python","protection","pdf",[14,15],"adding-an-image-watermark","adding-a-text-watermark",{"type":17,"children":18,"toc":188},"root",[19,27,32,45,50,62,74,86,177],{"type":20,"tag":21,"props":22,"children":23},"element","p",{},[24],{"type":25,"value":26},"text","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":20,"tag":21,"props":28,"children":29},{},[30],{"type":25,"value":31},"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":20,"tag":21,"props":33,"children":34},{},[35,37,43],{"type":25,"value":36},"PDFShift allows you to do this easily by adding the ",{"type":20,"tag":38,"props":39,"children":41},"code",{"className":40},[],[42],{"type":25,"value":11},{"type":25,"value":44}," object to your query.",{"type":20,"tag":21,"props":46,"children":47},{},[48],{"type":25,"value":49},"Here's a sample:",{"type":20,"tag":51,"props":52,"children":57},"pre",{"className":53,"code":55,"language":56,"meta":7},[54],"language-python","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","python",[58],{"type":20,"tag":38,"props":59,"children":60},{"__ignoreMap":7},[61],{"type":25,"value":55},{"type":20,"tag":21,"props":63,"children":64},{},[65,67,72],{"type":25,"value":66},"Adding the ",{"type":20,"tag":38,"props":68,"children":70},{"className":69},[],[71],{"type":25,"value":11},{"type":25,"value":73}," object to your query will tell PDFShift to generate a PDF that will be password protected.",{"type":20,"tag":21,"props":75,"children":76},{},[77,79,84],{"type":25,"value":78},"The ",{"type":20,"tag":38,"props":80,"children":82},{"className":81},[],[83],{"type":25,"value":11},{"type":25,"value":85}," object accepts the following parameters:",{"type":20,"tag":87,"props":88,"children":89},"ul",{},[90,102,113,124,143,160],{"type":20,"tag":91,"props":92,"children":93},"li",{},[94,100],{"type":20,"tag":38,"props":95,"children":97},{"className":96},[],[98],{"type":25,"value":99},"author",{"type":25,"value":101}," : The name of the author in the PDF metadata.",{"type":20,"tag":91,"props":103,"children":104},{},[105,111],{"type":20,"tag":38,"props":106,"children":108},{"className":107},[],[109],{"type":25,"value":110},"owner_password",{"type":25,"value":112},": The password set for the owner.",{"type":20,"tag":91,"props":114,"children":115},{},[116,122],{"type":20,"tag":38,"props":117,"children":119},{"className":118},[],[120],{"type":25,"value":121},"user_password",{"type":25,"value":123},": The password set for the user.",{"type":20,"tag":91,"props":125,"children":126},{},[127,133,135,141],{"type":20,"tag":38,"props":128,"children":130},{"className":129},[],[131],{"type":25,"value":132},"no_print",{"type":25,"value":134},": If set to ",{"type":20,"tag":38,"props":136,"children":138},{"className":137},[],[139],{"type":25,"value":140},"True",{"type":25,"value":142},", the user won't be able to print the PDF. (Only the owner)",{"type":20,"tag":91,"props":144,"children":145},{},[146,152,153,158],{"type":20,"tag":38,"props":147,"children":149},{"className":148},[],[150],{"type":25,"value":151},"no_modify",{"type":25,"value":134},{"type":20,"tag":38,"props":154,"children":156},{"className":155},[],[157],{"type":25,"value":140},{"type":25,"value":159},", the user won't be able to modify the PDF. (Only the owner)",{"type":20,"tag":91,"props":161,"children":162},{},[163,169,170,175],{"type":20,"tag":38,"props":164,"children":166},{"className":165},[],[167],{"type":25,"value":168},"no_copy",{"type":25,"value":134},{"type":20,"tag":38,"props":171,"children":173},{"className":172},[],[174],{"type":25,"value":140},{"type":25,"value":176},", the user won't be able to copy the content of the PDF. (Only the owner)",{"type":20,"tag":21,"props":178,"children":179},{},[180,186],{"type":20,"tag":181,"props":182,"children":183},"strong",{},[184],{"type":25,"value":185},"IMPORTANT",{"type":25,"value":187},":\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":7,"searchDepth":189,"depth":189,"links":190},2,[],"markdown","content:guides:python:httplib2:protecting-the-generated-pdf.md","content","guides/python/httplib2/protecting-the-generated-pdf.md","md",[197,201,205,209,213,217,221,225,229,233,237,241,245,249,253,254,258,262,266,270,274],{"_path":198,"title":199,"language":10,"library":5,"_id":200},"/guides/python/httplib2/accessing-secured-pages","Accessing secured pages","content:guides:python:httplib2:accessing-secured-pages.md",{"_path":202,"title":203,"language":10,"library":5,"_id":204},"/guides/python/httplib2/adding-a-custom-header-or-footer","Adding a custom header or footer","content:guides:python:httplib2:adding-a-custom-header-or-footer.md",{"_path":206,"title":207,"language":10,"library":5,"_id":208},"/guides/python/httplib2/adding-a-text-watermark","Adding a text watermark","content:guides:python:httplib2:adding-a-text-watermark.md",{"_path":210,"title":211,"language":10,"library":5,"_id":212},"/guides/python/httplib2/adding-an-image-watermark","Adding an image watermark","content:guides:python:httplib2:adding-an-image-watermark.md",{"_path":214,"title":215,"language":10,"library":5,"_id":216},"/guides/python/httplib2/avoid-conversion-on-error","Avoid the conversion on error when loading the document","content:guides:python:httplib2:avoid-conversion-on-error.md",{"_path":218,"title":219,"language":10,"library":5,"_id":220},"/guides/python/httplib2/convert-html-to-pdf-from-a-url","Convert an HTML document to PDF from a URL","content:guides:python:httplib2:convert-html-to-pdf-from-a-url.md",{"_path":222,"title":223,"language":10,"library":5,"_id":224},"/guides/python/httplib2/convert-html-to-pdf-from-raw-html","Convert an HTML document to PDF from raw HTML","content:guides:python:httplib2:convert-html-to-pdf-from-raw-html.md",{"_path":226,"title":227,"language":10,"library":5,"_id":228},"/guides/python/httplib2/define-a-time-limit","Define a time limit","content:guides:python:httplib2:define-a-time-limit.md",{"_path":230,"title":231,"language":10,"library":5,"_id":232},"/guides/python/httplib2/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","content:guides:python:httplib2:exporting-only-a-specific-set-of-pages.md",{"_path":234,"title":235,"language":10,"library":5,"_id":236},"/guides/python/httplib2/generate-a-document-with-full-height","Generate a document with full height","content:guides:python:httplib2:generate-a-document-with-full-height.md",{"_path":238,"title":239,"language":10,"library":5,"_id":240},"/guides/python/httplib2/loading-css-from-a-string","Loading CSS from a string","content:guides:python:httplib2:loading-css-from-a-string.md",{"_path":242,"title":243,"language":10,"library":5,"_id":244},"/guides/python/httplib2/loading-css-from-a-url","Loading CSS from a URL","content:guides:python:httplib2:loading-css-from-a-url.md",{"_path":246,"title":247,"language":10,"library":5,"_id":248},"/guides/python/httplib2/loading-javascript-from-a-string","Loading Javascript from a string","content:guides:python:httplib2:loading-javascript-from-a-string.md",{"_path":250,"title":251,"language":10,"library":5,"_id":252},"/guides/python/httplib2/loading-javascript-from-a-url","Loading Javascript from a URL","content:guides:python:httplib2:loading-javascript-from-a-url.md",{"_path":4,"title":8,"language":10,"library":5,"_id":192},{"_path":255,"title":256,"language":10,"library":5,"_id":257},"/guides/python/httplib2/receive-a-webhook-event","Receive a webhook event","content:guides:python:httplib2:receive-a-webhook-event.md",{"_path":259,"title":260,"language":10,"library":5,"_id":261},"/guides/python/httplib2/save-your-pdf-online-and-get-back-a-url","Save your PDF online and get back a URL","content:guides:python:httplib2:save-your-pdf-online-and-get-back-a-url.md",{"_path":263,"title":264,"language":10,"library":5,"_id":265},"/guides/python/httplib2/save-your-pdf-to-your-amazon-s3-bucket","Save your PDF to your Amazon S3 Bucket","content:guides:python:httplib2:save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":267,"title":268,"language":10,"library":5,"_id":269},"/guides/python/httplib2/send-custom-http-headers","Send custom HTTP headers","content:guides:python:httplib2:send-custom-http-headers.md",{"_path":271,"title":272,"language":10,"library":5,"_id":273},"/guides/python/httplib2/using-cookies","Using cookies to convert HTML documents to PDF","content:guides:python:httplib2:using-cookies.md",{"_path":275,"title":276,"language":10,"library":5,"_id":277},"/guides/python/httplib2/waiting-for-a-custom-element-to-be-ready","Waiting for a custom element to be ready","content:guides:python:httplib2:waiting-for-a-custom-element-to-be-ready.md",1785426833708]