[{"data":1,"prerenderedAt":227},["Reactive",2],{"/guides/go/go-resty/adding-an-image-watermark":3,"related:mowrcKnOXO":145},{"_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":140,"_id":141,"_source":142,"_file":143,"_extension":144},"/guides/go/go-resty/adding-an-image-watermark","go-resty",false,"","Adding an image watermark","Discover how to effortlessly add image watermarks to PDFs using Go and the Go-Resty 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.","Go","Go-Resty","watermark","pdf",[15,16],"protecting-the-generated-pdf","adding-a-text-watermark",{"type":18,"children":19,"toc":137},"root",[20,28,41,53,58,73,86,91,116,121,126],{"type":21,"tag":22,"props":23,"children":24},"element","p",{},[25],{"type":26,"value":27},"text","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":29,"children":30},{},[31,33,39],{"type":26,"value":32},"Adding a watermark to your PDF can be done by adding the ",{"type":21,"tag":34,"props":35,"children":37},"code",{"className":36},[],[38],{"type":26,"value":12},{"type":26,"value":40}," 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":43,"children":48},"pre",{"className":44,"code":46,"language":47,"meta":7},[45],"language-go","package main\n\nimport (\n    \"encoding/json\"\n    \"fmt\"\n    \"io/ioutil\"\n    \"github.com/go-resty/resty/v2\"\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            \"image\":       \"https://placekitten.com/200/300\",\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    // Create a new Resty client\n    client := resty.New()\n\n    // Perform the request\n    resp, err := client.R().\n        SetHeader(\"Content-Type\", \"application/json\").\n        SetHeader(\"X-API-Key\", apiKey).\n        SetBody(jsonParams).\n        Post(\"https://api.pdfshift.io/v3/convert/pdf\")\n\n    if err != nil {\n        fmt.Println(\"Error performing request:\", 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(resp.Body()))\n        return\n    }\n\n    // Save the PDF document\n    err = ioutil.WriteFile(\"result.pdf\", resp.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",[49],{"type":21,"tag":34,"props":50,"children":51},{"__ignoreMap":7},[52],{"type":26,"value":46},{"type":21,"tag":22,"props":54,"children":55},{},[56],{"type":26,"value":57},"The \"image\" parameter for the watermark can be used in two different values:",{"type":21,"tag":59,"props":60,"children":61},"ul",{},[62,68],{"type":21,"tag":63,"props":64,"children":65},"li",{},[66],{"type":26,"value":67},"URL : A full URL to an image that will be used as the watermark.",{"type":21,"tag":63,"props":69,"children":70},{},[71],{"type":26,"value":72},"Base64 : A base64 encoded image that will be used as the watermark.",{"type":21,"tag":22,"props":74,"children":75},{},[76,78,84],{"type":26,"value":77},"Note that you can also rotate the image by passing the ",{"type":21,"tag":34,"props":79,"children":81},{"className":80},[],[82],{"type":26,"value":83},"rotate",{"type":26,"value":85}," parameter as a degree (or negative degree)",{"type":21,"tag":22,"props":87,"children":88},{},[89],{"type":26,"value":90},"You can also customize the position of the text watermark by applying the following properties:",{"type":21,"tag":59,"props":92,"children":93},{},[94,105],{"type":21,"tag":63,"props":95,"children":96},{},[97,103],{"type":21,"tag":34,"props":98,"children":100},{"className":99},[],[101],{"type":26,"value":102},"offset_x",{"type":26,"value":104},": The horizontal position of the text. Can be 'left', 'center', 'right', or a specific value in pixels. Defaults to 'center'.",{"type":21,"tag":63,"props":106,"children":107},{},[108,114],{"type":21,"tag":34,"props":109,"children":111},{"className":110},[],[112],{"type":26,"value":113},"offset_y",{"type":26,"value":115},": 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":117,"children":118},{},[119],{"type":26,"value":120},"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":122,"children":123},{},[124],{"type":26,"value":125},"For example:",{"type":21,"tag":42,"props":127,"children":132},{"className":128,"code":130,"language":131,"meta":7},[129],"language-json","params = {\n    \"source\": \"https://www.example.com\",\n    \"watermark\": {\n        \"text\": \"PROTECTED DOCUMENT\",\n        \"offset_x\": \"5cm\",\n        \"offset_top\": \"15mm\"\n    }\n}\n","json",[133],{"type":21,"tag":34,"props":134,"children":135},{"__ignoreMap":7},[136],{"type":26,"value":130},{"title":7,"searchDepth":138,"depth":138,"links":139},2,[],"markdown","content:guides:go:go-resty:adding-an-image-watermark.md","content","guides/go/go-resty/adding-an-image-watermark.md","md",[146,150,154,158,159,163,167,171,175,179,183,187,191,195,199,203,207,211,215,219,223],{"_path":147,"title":148,"language":10,"library":11,"_id":149},"/guides/go/go-resty/accessing-secured-pages","Accessing secured pages","content:guides:go:go-resty:accessing-secured-pages.md",{"_path":151,"title":152,"language":10,"library":11,"_id":153},"/guides/go/go-resty/adding-a-custom-header-or-footer","Adding a custom header or footer","content:guides:go:go-resty:adding-a-custom-header-or-footer.md",{"_path":155,"title":156,"language":10,"library":11,"_id":157},"/guides/go/go-resty/adding-a-text-watermark","Adding a text watermark","content:guides:go:go-resty:adding-a-text-watermark.md",{"_path":4,"title":8,"language":10,"library":11,"_id":141},{"_path":160,"title":161,"language":10,"library":11,"_id":162},"/guides/go/go-resty/avoid-conversion-on-error","Avoid the conversion on error when loading the document","content:guides:go:go-resty:avoid-conversion-on-error.md",{"_path":164,"title":165,"language":10,"library":11,"_id":166},"/guides/go/go-resty/convert-html-to-pdf-from-a-url","Convert an HTML document to PDF from a URL","content:guides:go:go-resty:convert-html-to-pdf-from-a-url.md",{"_path":168,"title":169,"language":10,"library":11,"_id":170},"/guides/go/go-resty/convert-html-to-pdf-from-raw-html","Convert an HTML document to PDF from raw HTML","content:guides:go:go-resty:convert-html-to-pdf-from-raw-html.md",{"_path":172,"title":173,"language":10,"library":11,"_id":174},"/guides/go/go-resty/define-a-time-limit","Define a time limit","content:guides:go:go-resty:define-a-time-limit.md",{"_path":176,"title":177,"language":10,"library":11,"_id":178},"/guides/go/go-resty/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","content:guides:go:go-resty:exporting-only-a-specific-set-of-pages.md",{"_path":180,"title":181,"language":10,"library":11,"_id":182},"/guides/go/go-resty/generate-a-document-with-full-height","Generate a document with full height","content:guides:go:go-resty:generate-a-document-with-full-height.md",{"_path":184,"title":185,"language":10,"library":11,"_id":186},"/guides/go/go-resty/loading-css-from-a-string","Loading CSS from a string","content:guides:go:go-resty:loading-css-from-a-string.md",{"_path":188,"title":189,"language":10,"library":11,"_id":190},"/guides/go/go-resty/loading-css-from-a-url","Loading CSS from a URL","content:guides:go:go-resty:loading-css-from-a-url.md",{"_path":192,"title":193,"language":10,"library":11,"_id":194},"/guides/go/go-resty/loading-javascript-from-a-string","Loading Javascript from a string","content:guides:go:go-resty:loading-javascript-from-a-string.md",{"_path":196,"title":197,"language":10,"library":11,"_id":198},"/guides/go/go-resty/loading-javascript-from-a-url","Loading Javascript from a URL","content:guides:go:go-resty:loading-javascript-from-a-url.md",{"_path":200,"title":201,"language":10,"library":11,"_id":202},"/guides/go/go-resty/protecting-the-generated-pdf","Protecting the generated PDF","content:guides:go:go-resty:protecting-the-generated-pdf.md",{"_path":204,"title":205,"language":10,"library":11,"_id":206},"/guides/go/go-resty/receive-a-webhook-event","Receive a webhook event","content:guides:go:go-resty:receive-a-webhook-event.md",{"_path":208,"title":209,"language":10,"library":11,"_id":210},"/guides/go/go-resty/save-your-pdf-online-and-get-back-a-url","Save your PDF online and get back a URL","content:guides:go:go-resty:save-your-pdf-online-and-get-back-a-url.md",{"_path":212,"title":213,"language":10,"library":11,"_id":214},"/guides/go/go-resty/save-your-pdf-to-your-amazon-s3-bucket","Save your PDF to your Amazon S3 Bucket","content:guides:go:go-resty:save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":216,"title":217,"language":10,"library":11,"_id":218},"/guides/go/go-resty/send-custom-http-headers","Send custom HTTP headers","content:guides:go:go-resty:send-custom-http-headers.md",{"_path":220,"title":221,"language":10,"library":11,"_id":222},"/guides/go/go-resty/using-cookies","Using cookies to convert HTML documents to PDF","content:guides:go:go-resty:using-cookies.md",{"_path":224,"title":225,"language":10,"library":11,"_id":226},"/guides/go/go-resty/waiting-for-a-custom-element-to-be-ready","Waiting for a custom element to be ready","content:guides:go:go-resty:waiting-for-a-custom-element-to-be-ready.md",1785426828702]