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