[{"data":1,"prerenderedAt":227},["Reactive",2],{"/guides/php/guzzle/adding-an-image-watermark":3,"related:EfK0MIdVk4":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/php/guzzle/adding-an-image-watermark","guzzle",false,"","Adding an image watermark","Discover how to effortlessly add image watermarks to PDFs using PHP and the Guzzle 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.","PHP","Guzzle","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-php","use GuzzleHttp\\Client;\nuse GuzzleHttp\\Exception\\RequestException;\n\n# You can get an API key at https://pdfshift.io\n$api_key = 'sk_xxxxxxxxxxxx'\n\n$params = array (\n    'source' => 'https://www.example.com',\n    'watermark' => array (\n        'image' => 'https://placekitten.com/200/300',\n        'offset_x' => 'center',\n        'offset_top' => 'top'\n    )\n)\n\n// Create a Guzzle client\n$client = new Client();\ntry {\n    // Make the POST request\n    $response = $client->post('https://api.pdfshift.io/v3/convert/pdf', [\n        'headers' => [\n            'Content-Type' => 'application/json',\n            'X-API-Key' => $api_key\n        ],\n        'json' => $params\n    ]);\n\n    // Get the response body\n    $body = $response->getBody()->getContents();\n\n    // Save the file to result.pdf\n    file_put_contents('result.pdf', $body);\n\n    echo 'The PDF document was generated and saved to result.pdf';\n} catch (RequestException $e) {\n    if ($e->hasResponse()) {\n        $statusCode = $e->getResponse()->getStatusCode();\n        $reasonPhrase = $e->getResponse()->getReasonPhrase();\n        throw new Exception(\"Request failed with status code $statusCode: $reasonPhrase\");\n    } else {\n        throw new Exception(\"Request failed: \" . $e->getMessage());\n    }\n}\n","php",[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 = array (\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:php:guzzle:adding-an-image-watermark.md","content","guides/php/guzzle/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/php/guzzle/accessing-secured-pages","Accessing secured pages","content:guides:php:guzzle:accessing-secured-pages.md",{"_path":151,"title":152,"language":10,"library":11,"_id":153},"/guides/php/guzzle/adding-a-custom-header-or-footer","Adding a custom header or footer","content:guides:php:guzzle:adding-a-custom-header-or-footer.md",{"_path":155,"title":156,"language":10,"library":11,"_id":157},"/guides/php/guzzle/adding-a-text-watermark","Adding a text watermark","content:guides:php:guzzle: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/php/guzzle/avoid-conversion-on-error","Avoid the conversion on error when loading the document","content:guides:php:guzzle:avoid-conversion-on-error.md",{"_path":164,"title":165,"language":10,"library":11,"_id":166},"/guides/php/guzzle/convert-html-to-pdf-from-a-url","Convert an HTML document to PDF from a URL","content:guides:php:guzzle:convert-html-to-pdf-from-a-url.md",{"_path":168,"title":169,"language":10,"library":11,"_id":170},"/guides/php/guzzle/convert-html-to-pdf-from-raw-html","Convert an HTML document to PDF from raw HTML","content:guides:php:guzzle:convert-html-to-pdf-from-raw-html.md",{"_path":172,"title":173,"language":10,"library":11,"_id":174},"/guides/php/guzzle/define-a-time-limit","Define a time limit","content:guides:php:guzzle:define-a-time-limit.md",{"_path":176,"title":177,"language":10,"library":11,"_id":178},"/guides/php/guzzle/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","content:guides:php:guzzle:exporting-only-a-specific-set-of-pages.md",{"_path":180,"title":181,"language":10,"library":11,"_id":182},"/guides/php/guzzle/generate-a-document-with-full-height","Generate a document with full height","content:guides:php:guzzle:generate-a-document-with-full-height.md",{"_path":184,"title":185,"language":10,"library":11,"_id":186},"/guides/php/guzzle/loading-css-from-a-string","Loading CSS from a string","content:guides:php:guzzle:loading-css-from-a-string.md",{"_path":188,"title":189,"language":10,"library":11,"_id":190},"/guides/php/guzzle/loading-css-from-a-url","Loading CSS from a URL","content:guides:php:guzzle:loading-css-from-a-url.md",{"_path":192,"title":193,"language":10,"library":11,"_id":194},"/guides/php/guzzle/loading-javascript-from-a-string","Loading Javascript from a string","content:guides:php:guzzle:loading-javascript-from-a-string.md",{"_path":196,"title":197,"language":10,"library":11,"_id":198},"/guides/php/guzzle/loading-javascript-from-a-url","Loading Javascript from a URL","content:guides:php:guzzle:loading-javascript-from-a-url.md",{"_path":200,"title":201,"language":10,"library":11,"_id":202},"/guides/php/guzzle/protecting-the-generated-pdf","Protecting the generated PDF","content:guides:php:guzzle:protecting-the-generated-pdf.md",{"_path":204,"title":205,"language":10,"library":11,"_id":206},"/guides/php/guzzle/receive-a-webhook-event","Receive a webhook event","content:guides:php:guzzle:receive-a-webhook-event.md",{"_path":208,"title":209,"language":10,"library":11,"_id":210},"/guides/php/guzzle/save-your-pdf-online-and-get-back-a-url","Save your PDF online and get back a URL","content:guides:php:guzzle:save-your-pdf-online-and-get-back-a-url.md",{"_path":212,"title":213,"language":10,"library":11,"_id":214},"/guides/php/guzzle/save-your-pdf-to-your-amazon-s3-bucket","Save your PDF to your Amazon S3 Bucket","content:guides:php:guzzle:save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":216,"title":217,"language":10,"library":11,"_id":218},"/guides/php/guzzle/send-custom-http-headers","Send custom HTTP headers","content:guides:php:guzzle:send-custom-http-headers.md",{"_path":220,"title":221,"language":10,"library":11,"_id":222},"/guides/php/guzzle/using-cookies","Using cookies to convert HTML documents to PDF","content:guides:php:guzzle:using-cookies.md",{"_path":224,"title":225,"language":10,"library":11,"_id":226},"/guides/php/guzzle/waiting-for-a-custom-element-to-be-ready","Waiting for a custom element to be ready","content:guides:php:guzzle:waiting-for-a-custom-element-to-be-ready.md",1785426828034]