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