[{"data":1,"prerenderedAt":269},["Reactive",2],{"/guides/go/nethttp/adding-a-text-watermark":3,"related:TKiIx1b05G":187},{"_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":182,"_id":183,"_source":184,"_file":185,"_extension":186},"/guides/go/nethttp/adding-a-text-watermark","nethttp",false,"","Adding a text watermark","Learn how to add text watermarks to your generated PDF document using Go and the Net/HTTP 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.","Go","Net/HTTP","watermark","pdf",[15,16],"adding-an-image-watermark","protecting-the-generated-pdf",true,{"type":19,"children":20,"toc":179},"root",[21,29,42,54,59,130,135,160,165,170],{"type":22,"tag":23,"props":24,"children":25},"element","p",{},[26],{"type":27,"value":28},"text","In this guide, we'll walk you through the process of adding text watermarks to your PDF files, using PDFShift's API.",{"type":22,"tag":23,"props":30,"children":31},{},[32,34,40],{"type":27,"value":33},"Adding a watermark to your PDF can be done by adding the ",{"type":22,"tag":35,"props":36,"children":38},"code",{"className":37},[],[39],{"type":27,"value":12},{"type":27,"value":41}," 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":22,"tag":43,"props":44,"children":49},"pre",{"className":45,"code":47,"language":48,"meta":7},[46],"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        \"watermark\": map[string]string{\n            \"text\":       \"PROTECTED DOCUMENT\",\n            \"offset_x\":   \"center\",\n            \"offset_top\": \"top\",\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",[50],{"type":22,"tag":35,"props":51,"children":52},{"__ignoreMap":7},[53],{"type":27,"value":47},{"type":22,"tag":23,"props":55,"children":56},{},[57],{"type":27,"value":58},"You can customize the text watermark by applying the following properties:",{"type":22,"tag":60,"props":61,"children":62},"ul",{},[63,75,86,97,108,119],{"type":22,"tag":64,"props":65,"children":66},"li",{},[67,73],{"type":22,"tag":35,"props":68,"children":70},{"className":69},[],[71],{"type":27,"value":72},"font_size",{"type":27,"value":74},": The size of the text. An integer value in pixels. Defaults to 16.",{"type":22,"tag":64,"props":76,"children":77},{},[78,84],{"type":22,"tag":35,"props":79,"children":81},{"className":80},[],[82],{"type":27,"value":83},"font_family",{"type":27,"value":85}," : The font family to be used. Defaults to Helvetica.",{"type":22,"tag":64,"props":87,"children":88},{},[89,95],{"type":22,"tag":35,"props":90,"children":92},{"className":91},[],[93],{"type":27,"value":94},"font_color",{"type":27,"value":96}," : The color of the text. A hexadecimal color value. Defaults to '000000'.",{"type":22,"tag":64,"props":98,"children":99},{},[100,106],{"type":22,"tag":35,"props":101,"children":103},{"className":102},[],[104],{"type":27,"value":105},"font_opacity",{"type":27,"value":107}," : The opacity of the text. A float value between 0 and 100. Defaults to 100.",{"type":22,"tag":64,"props":109,"children":110},{},[111,117],{"type":22,"tag":35,"props":112,"children":114},{"className":113},[],[115],{"type":27,"value":116},"font_bold",{"type":27,"value":118},": A boolean to set the text as bold. Defaults to false.",{"type":22,"tag":64,"props":120,"children":121},{},[122,128],{"type":22,"tag":35,"props":123,"children":125},{"className":124},[],[126],{"type":27,"value":127},"font_italic",{"type":27,"value":129},": A boolean to set the text as italic. Defaults to false.",{"type":22,"tag":23,"props":131,"children":132},{},[133],{"type":27,"value":134},"You can also customize the position of the text watermark by applying the following properties:",{"type":22,"tag":60,"props":136,"children":137},{},[138,149],{"type":22,"tag":64,"props":139,"children":140},{},[141,147],{"type":22,"tag":35,"props":142,"children":144},{"className":143},[],[145],{"type":27,"value":146},"offset_x",{"type":27,"value":148},": The horizontal position of the text. Can be 'left', 'center', 'right', or a specific value in pixels. Defaults to 'center'.",{"type":22,"tag":64,"props":150,"children":151},{},[152,158],{"type":22,"tag":35,"props":153,"children":155},{"className":154},[],[156],{"type":27,"value":157},"offset_y",{"type":27,"value":159},": The vertical position of the text. Can be 'top', 'middle', 'bottom', or a specific value in pixels. Defaults to 'center'.",{"type":22,"tag":23,"props":161,"children":162},{},[163],{"type":27,"value":164},"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":22,"tag":23,"props":166,"children":167},{},[168],{"type":27,"value":169},"For example:",{"type":22,"tag":43,"props":171,"children":174},{"className":172,"code":173,"language":48,"meta":7},[46],"params = {\n    \"source\": \"https://www.example.com\",\n    \"watermark\": {\n        \"text\": \"PROTECTED DOCUMENT\",\n        \"offset_x\": \"5cm\",\n        \"offset_top\": \"15mm\"\n    }\n}\n",[175],{"type":22,"tag":35,"props":176,"children":177},{"__ignoreMap":7},[178],{"type":27,"value":173},{"title":7,"searchDepth":180,"depth":180,"links":181},2,[],"markdown","content:guides:go:nethttp:adding-a-text-watermark.md","content","guides/go/nethttp/adding-a-text-watermark.md","md",[188,192,196,197,201,205,209,213,217,221,225,229,233,237,241,245,249,253,257,261,265],{"_path":189,"title":190,"language":10,"library":11,"_id":191},"/guides/go/nethttp/accessing-secured-pages","Accessing secured pages","content:guides:go:nethttp:accessing-secured-pages.md",{"_path":193,"title":194,"language":10,"library":11,"_id":195},"/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":4,"title":8,"language":10,"library":11,"_id":183},{"_path":198,"title":199,"language":10,"library":11,"_id":200},"/guides/go/nethttp/adding-an-image-watermark","Adding an image watermark","content:guides:go:nethttp:adding-an-image-watermark.md",{"_path":202,"title":203,"language":10,"library":11,"_id":204},"/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":206,"title":207,"language":10,"library":11,"_id":208},"/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":210,"title":211,"language":10,"library":11,"_id":212},"/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":214,"title":215,"language":10,"library":11,"_id":216},"/guides/go/nethttp/define-a-time-limit","Define a time limit","content:guides:go:nethttp:define-a-time-limit.md",{"_path":218,"title":219,"language":10,"library":11,"_id":220},"/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":222,"title":223,"language":10,"library":11,"_id":224},"/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":226,"title":227,"language":10,"library":11,"_id":228},"/guides/go/nethttp/loading-css-from-a-string","Loading CSS from a string","content:guides:go:nethttp:loading-css-from-a-string.md",{"_path":230,"title":231,"language":10,"library":11,"_id":232},"/guides/go/nethttp/loading-css-from-a-url","Loading CSS from a URL","content:guides:go:nethttp:loading-css-from-a-url.md",{"_path":234,"title":235,"language":10,"library":11,"_id":236},"/guides/go/nethttp/loading-javascript-from-a-string","Loading Javascript from a string","content:guides:go:nethttp:loading-javascript-from-a-string.md",{"_path":238,"title":239,"language":10,"library":11,"_id":240},"/guides/go/nethttp/loading-javascript-from-a-url","Loading Javascript from a URL","content:guides:go:nethttp:loading-javascript-from-a-url.md",{"_path":242,"title":243,"language":10,"library":11,"_id":244},"/guides/go/nethttp/protecting-the-generated-pdf","Protecting the generated PDF","content:guides:go:nethttp:protecting-the-generated-pdf.md",{"_path":246,"title":247,"language":10,"library":11,"_id":248},"/guides/go/nethttp/receive-a-webhook-event","Receive a webhook event","content:guides:go:nethttp:receive-a-webhook-event.md",{"_path":250,"title":251,"language":10,"library":11,"_id":252},"/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":254,"title":255,"language":10,"library":11,"_id":256},"/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":258,"title":259,"language":10,"library":11,"_id":260},"/guides/go/nethttp/send-custom-http-headers","Send custom HTTP headers","content:guides:go:nethttp:send-custom-http-headers.md",{"_path":262,"title":263,"language":10,"library":11,"_id":264},"/guides/go/nethttp/using-cookies","Using cookies to convert HTML documents to PDF","content:guides:go:nethttp:using-cookies.md",{"_path":266,"title":267,"language":10,"library":11,"_id":268},"/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",1785426824563]