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