[{"data":1,"prerenderedAt":136},["Reactive",2],{"/guides/ruby/restclient/convert-html-to-pdf-from-a-url":3,"related:p0KHKqS2bv":54},{"_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":49,"_id":50,"_source":51,"_file":52,"_extension":53},"/guides/ruby/restclient/convert-html-to-pdf-from-a-url","restclient",false,"","Convert an HTML document to PDF from a URL","Learn how to easily convert HTML documents to PDF from a URL using Ruby and the RestClient library. This how-to guide offers clear Ruby code examples that show developers how to implement this using the PDFShift API.","Ruby","RestClient","source","pdf",[15,16],"convert-html-to-pdf-from-raw-html","avoid-conversion-on-error",{"type":18,"children":19,"toc":46},"root",[20,28,41],{"type":21,"tag":22,"props":23,"children":24},"element","p",{},[25],{"type":26,"value":27},"text","In this guide, we'll show you how to convert HTML documents to PDFs using PDFShift's API. This is a straightforward process that can be accomplished with just a few lines of Ruby code.",{"type":21,"tag":29,"props":30,"children":35},"pre",{"className":31,"code":33,"language":34,"meta":7},[32],"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}\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\n# write response to a file nammed \"result.pdf\"\nFile.open('result.pdf', 'wb') { |f| f.write(response.body) }\n\n# Print a success message\nputs 'The PDF document was generated and saved to result.pdf'\n","ruby",[36],{"type":21,"tag":37,"props":38,"children":39},"code",{"__ignoreMap":7},[40],{"type":26,"value":33},{"type":21,"tag":22,"props":42,"children":43},{},[44],{"type":26,"value":45},"With this Ruby script, you can effortlessly convert HTML documents from a URL to PDF files using PDFShift's API. Happy coding!",{"title":7,"searchDepth":47,"depth":47,"links":48},2,[],"markdown","content:guides:ruby:restclient:convert-html-to-pdf-from-a-url.md","content","guides/ruby/restclient/convert-html-to-pdf-from-a-url.md","md",[55,59,63,67,71,75,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132],{"_path":56,"title":57,"language":10,"library":11,"_id":58},"/guides/ruby/restclient/accessing-secured-pages","Accessing secured pages","content:guides:ruby:restclient:accessing-secured-pages.md",{"_path":60,"title":61,"language":10,"library":11,"_id":62},"/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":64,"title":65,"language":10,"library":11,"_id":66},"/guides/ruby/restclient/adding-a-text-watermark","Adding a text watermark","content:guides:ruby:restclient:adding-a-text-watermark.md",{"_path":68,"title":69,"language":10,"library":11,"_id":70},"/guides/ruby/restclient/adding-an-image-watermark","Adding an image watermark","content:guides:ruby:restclient:adding-an-image-watermark.md",{"_path":72,"title":73,"language":10,"library":11,"_id":74},"/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":4,"title":8,"language":10,"library":11,"_id":50},{"_path":77,"title":78,"language":10,"library":11,"_id":79},"/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":81,"title":82,"language":10,"library":11,"_id":83},"/guides/ruby/restclient/define-a-time-limit","Define a time limit","content:guides:ruby:restclient:define-a-time-limit.md",{"_path":85,"title":86,"language":10,"library":11,"_id":87},"/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":89,"title":90,"language":10,"library":11,"_id":91},"/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":93,"title":94,"language":10,"library":11,"_id":95},"/guides/ruby/restclient/loading-css-from-a-string","Loading CSS from a string","content:guides:ruby:restclient:loading-css-from-a-string.md",{"_path":97,"title":98,"language":10,"library":11,"_id":99},"/guides/ruby/restclient/loading-css-from-a-url","Loading CSS from a URL","content:guides:ruby:restclient:loading-css-from-a-url.md",{"_path":101,"title":102,"language":10,"library":11,"_id":103},"/guides/ruby/restclient/loading-javascript-from-a-string","Loading Javascript from a string","content:guides:ruby:restclient:loading-javascript-from-a-string.md",{"_path":105,"title":106,"language":10,"library":11,"_id":107},"/guides/ruby/restclient/loading-javascript-from-a-url","Loading Javascript from a URL","content:guides:ruby:restclient:loading-javascript-from-a-url.md",{"_path":109,"title":110,"language":10,"library":11,"_id":111},"/guides/ruby/restclient/protecting-the-generated-pdf","Protecting the generated PDF","content:guides:ruby:restclient:protecting-the-generated-pdf.md",{"_path":113,"title":114,"language":10,"library":11,"_id":115},"/guides/ruby/restclient/receive-a-webhook-event","Receive a webhook event","content:guides:ruby:restclient:receive-a-webhook-event.md",{"_path":117,"title":118,"language":10,"library":11,"_id":119},"/guides/ruby/restclient/save-your-pdf-online-and-get-back-a-url","Save your PDF online and get back a URL","content:guides:ruby:restclient:save-your-pdf-online-and-get-back-a-url.md",{"_path":121,"title":122,"language":10,"library":11,"_id":123},"/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":125,"title":126,"language":10,"library":11,"_id":127},"/guides/ruby/restclient/send-custom-http-headers","Send custom HTTP headers","content:guides:ruby:restclient:send-custom-http-headers.md",{"_path":129,"title":130,"language":10,"library":11,"_id":131},"/guides/ruby/restclient/using-cookies","Using cookies to convert HTML documents to PDF","content:guides:ruby:restclient:using-cookies.md",{"_path":133,"title":134,"language":10,"library":11,"_id":135},"/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",1785426835288]