[{"data":1,"prerenderedAt":198},["Reactive",2],{"/guides/ruby/restclient/save-your-pdf-online-and-get-back-a-url":3,"related:JV438gTgwV":116},{"_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":111,"_id":112,"_source":113,"_file":114,"_extension":115},"/guides/ruby/restclient/save-your-pdf-online-and-get-back-a-url","restclient",false,"","Save your PDF online and get back a URL","This guides shows you how can generate a PDF document from HTML and get back an URL instead of the raw PDF. This allows you to share the link directly to your users or redirect them to that page. Learn how you can achieve it using Ruby and the RestClient library to call PDFShift's API.","Ruby","RestClient","filename","pdf",[15,16],"save-your-pdf-to-your-amazon-s3-bucket","receive-a-webhook-event",{"type":18,"children":19,"toc":108},"root",[20,28,41,53,73,78,89,99],{"type":21,"tag":22,"props":23,"children":24},"element","p",{},[25],{"type":26,"value":27},"text","In this guide, we'll show you how you can generate a PDF document from HTML and get back an URL instead of the raw PDF. This allows you to share the link directly to your users or redirect them to that page.",{"type":21,"tag":22,"props":29,"children":30},{},[31,33,39],{"type":26,"value":32},"To do so, we are going to pass the ",{"type":21,"tag":34,"props":35,"children":37},"code",{"className":36},[],[38],{"type":26,"value":12},{"type":26,"value":40}," parameter to the request. It expects a string that will be the name of the file once it is saved on our servers.",{"type":21,"tag":42,"props":43,"children":48},"pre",{"className":44,"code":46,"language":47,"meta":7},[45],"language-ruby","require 'rest-client'\nrequire 'json'\n\n# You can get an API key at https://pdfshift.io\napi_key = 'sk_xxxxxxxxxxxx'\n\nparams = {\n    'source' => 'https://www.example.com',\n    'filename' => 'example.pdf'\n}\n\n# Make the POST request\nresponse = RestClient.post(\"https://api.pdfshift.io/v3/convert/pdf\", params.to_json, {\n    'Content-Type' => 'application/json',\n    'X-API-Key' => api_key\n})\n\n# Check for successful response\nunless response.code == 200\n    raise \"Request failed with status code #{response.code}: #{response.body}\"\nend\n\nputs 'The PDF document was generated and saved to result.pdf'\n","ruby",[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,58,63,65,71],{"type":26,"value":57},"In the above example, we used the ",{"type":21,"tag":34,"props":59,"children":61},{"className":60},[],[62],{"type":26,"value":12},{"type":26,"value":64}," parameter to specify the name of the file once it is saved on our servers. The response will convert the document ",{"type":21,"tag":66,"props":67,"children":68},"strong",{},[69],{"type":26,"value":70},"but return a JSON response",{"type":26,"value":72}," instead of the raw PDF.",{"type":21,"tag":22,"props":74,"children":75},{},[76],{"type":26,"value":77},"The body of the response will be similar to this:",{"type":21,"tag":42,"props":79,"children":84},{"className":80,"code":82,"language":83,"meta":7},[81],"language-json","{\n    \"success\": true,\n    \"url\": \"https://pdfshift.s3.amazonaws.com/d/2/2024-03/c9c2d3e536ff42d892f06fdda6bb1ff7/example.pdf\",\n    \"filesize\": 34980,\n    \"duration\": 1237,\n    \"response\": {\n        \"status-code\": 200,\n        \"content-length\": 0,\n        \"requests\": 0,\n        \"duration\": 1085.6739225387573\n    },\n    \"executed\": \"2024-03-06T10:05:51.516413\",\n    \"pdf_pages\": 1\n}\n","json",[85],{"type":21,"tag":34,"props":86,"children":87},{"__ignoreMap":7},[88],{"type":26,"value":82},{"type":21,"tag":22,"props":90,"children":91},{},[92,97],{"type":21,"tag":66,"props":93,"children":94},{},[95],{"type":26,"value":96},"NOTE",{"type":26,"value":98},": Using the filename does save your document on our S3 storage for 2 days. After two days, the document is automatically deleted.",{"type":21,"tag":22,"props":100,"children":101},{},[102,106],{"type":21,"tag":66,"props":103,"children":104},{},[105],{"type":26,"value":96},{"type":26,"value":107},": Since we store your documents on our server, this command is not recommended if you want to be HIPAA compliant.",{"title":7,"searchDepth":109,"depth":109,"links":110},2,[],"markdown","content:guides:ruby:restclient:save-your-pdf-online-and-get-back-a-url.md","content","guides/ruby/restclient/save-your-pdf-online-and-get-back-a-url.md","md",[117,121,125,129,133,137,141,145,149,153,157,161,165,169,173,177,181,182,186,190,194],{"_path":118,"title":119,"language":10,"library":11,"_id":120},"/guides/ruby/restclient/accessing-secured-pages","Accessing secured pages","content:guides:ruby:restclient:accessing-secured-pages.md",{"_path":122,"title":123,"language":10,"library":11,"_id":124},"/guides/ruby/restclient/adding-a-custom-header-or-footer","Adding a custom header or footer","content:guides:ruby:restclient:adding-a-custom-header-or-footer.md",{"_path":126,"title":127,"language":10,"library":11,"_id":128},"/guides/ruby/restclient/adding-a-text-watermark","Adding a text watermark","content:guides:ruby:restclient:adding-a-text-watermark.md",{"_path":130,"title":131,"language":10,"library":11,"_id":132},"/guides/ruby/restclient/adding-an-image-watermark","Adding an image watermark","content:guides:ruby:restclient:adding-an-image-watermark.md",{"_path":134,"title":135,"language":10,"library":11,"_id":136},"/guides/ruby/restclient/avoid-conversion-on-error","Avoid the conversion on error when loading the document","content:guides:ruby:restclient:avoid-conversion-on-error.md",{"_path":138,"title":139,"language":10,"library":11,"_id":140},"/guides/ruby/restclient/convert-html-to-pdf-from-a-url","Convert an HTML document to PDF from a URL","content:guides:ruby:restclient:convert-html-to-pdf-from-a-url.md",{"_path":142,"title":143,"language":10,"library":11,"_id":144},"/guides/ruby/restclient/convert-html-to-pdf-from-raw-html","Convert an HTML document to PDF from raw HTML","content:guides:ruby:restclient:convert-html-to-pdf-from-raw-html.md",{"_path":146,"title":147,"language":10,"library":11,"_id":148},"/guides/ruby/restclient/define-a-time-limit","Define a time limit","content:guides:ruby:restclient:define-a-time-limit.md",{"_path":150,"title":151,"language":10,"library":11,"_id":152},"/guides/ruby/restclient/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","content:guides:ruby:restclient:exporting-only-a-specific-set-of-pages.md",{"_path":154,"title":155,"language":10,"library":11,"_id":156},"/guides/ruby/restclient/generate-a-document-with-full-height","Generate a document with full height","content:guides:ruby:restclient:generate-a-document-with-full-height.md",{"_path":158,"title":159,"language":10,"library":11,"_id":160},"/guides/ruby/restclient/loading-css-from-a-string","Loading CSS from a string","content:guides:ruby:restclient:loading-css-from-a-string.md",{"_path":162,"title":163,"language":10,"library":11,"_id":164},"/guides/ruby/restclient/loading-css-from-a-url","Loading CSS from a URL","content:guides:ruby:restclient:loading-css-from-a-url.md",{"_path":166,"title":167,"language":10,"library":11,"_id":168},"/guides/ruby/restclient/loading-javascript-from-a-string","Loading Javascript from a string","content:guides:ruby:restclient:loading-javascript-from-a-string.md",{"_path":170,"title":171,"language":10,"library":11,"_id":172},"/guides/ruby/restclient/loading-javascript-from-a-url","Loading Javascript from a URL","content:guides:ruby:restclient:loading-javascript-from-a-url.md",{"_path":174,"title":175,"language":10,"library":11,"_id":176},"/guides/ruby/restclient/protecting-the-generated-pdf","Protecting the generated PDF","content:guides:ruby:restclient:protecting-the-generated-pdf.md",{"_path":178,"title":179,"language":10,"library":11,"_id":180},"/guides/ruby/restclient/receive-a-webhook-event","Receive a webhook event","content:guides:ruby:restclient:receive-a-webhook-event.md",{"_path":4,"title":8,"language":10,"library":11,"_id":112},{"_path":183,"title":184,"language":10,"library":11,"_id":185},"/guides/ruby/restclient/save-your-pdf-to-your-amazon-s3-bucket","Save your PDF to your Amazon S3 Bucket","content:guides:ruby:restclient:save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":187,"title":188,"language":10,"library":11,"_id":189},"/guides/ruby/restclient/send-custom-http-headers","Send custom HTTP headers","content:guides:ruby:restclient:send-custom-http-headers.md",{"_path":191,"title":192,"language":10,"library":11,"_id":193},"/guides/ruby/restclient/using-cookies","Using cookies to convert HTML documents to PDF","content:guides:ruby:restclient:using-cookies.md",{"_path":195,"title":196,"language":10,"library":11,"_id":197},"/guides/ruby/restclient/waiting-for-a-custom-element-to-be-ready","Waiting for a custom element to be ready","content:guides:ruby:restclient:waiting-for-a-custom-element-to-be-ready.md",1785426835592]