[{"data":1,"prerenderedAt":150},["Reactive",2],{"/guides/go/go-resty/loading-css-from-a-string":3,"related:69Mq7O7JoL":68},{"_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":19,"_type":63,"_id":64,"_source":65,"_file":66,"_extension":67},"/guides/go/go-resty/loading-css-from-a-string","go-resty",false,"","Loading CSS from a string","Follow this guide to load custom CSS as a given string when converting an HTML document to PDF with PDFShift's API. This guide provides Go code samples with the Go-Resty library.","Go","Go-Resty","css","pdf",[15,16,17,18],"adding-a-custom-header-or-footer","loading-css-from-a-url","loading-javascript-from-a-string","loading-javascript-from-a-url",{"type":20,"children":21,"toc":60},"root",[22,30,35,48],{"type":23,"tag":24,"props":25,"children":26},"element","p",{},[27],{"type":28,"value":29},"text","In this guide, we'll show you how to load custom CSS as a given string when converting an HTML document to PDF using PDFShift's API. This allows you to add custom CSS to your page to customize the output of your generated PDF.",{"type":23,"tag":24,"props":31,"children":32},{},[33],{"type":28,"value":34},"It can be interesting to be able to set a custom CSS value to adjust the rendering of your page specifically when exporting the document to PDF.\nThis allows you to keep a standard look and feel to your users, but adjust some areas when sending that same document to PDFShift to get back a PDF.",{"type":23,"tag":36,"props":37,"children":42},"pre",{"className":38,"code":40,"language":41,"meta":7},[39],"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        \"css\": \"body { background-color: #f00; }\",\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",[43],{"type":23,"tag":44,"props":45,"children":46},"code",{"__ignoreMap":7},[47],{"type":28,"value":40},{"type":23,"tag":24,"props":49,"children":50},{},[51,53,58],{"type":28,"value":52},"The ",{"type":23,"tag":44,"props":54,"children":56},{"className":55},[],[57],{"type":28,"value":12},{"type":28,"value":59}," parameter accepts either a string or a URL. It will be used as the CSS for the page when converting it to PDF. This allows you to set a custom CSS value to adjust the rendering of your page specifically when exporting the document to PDF.",{"title":7,"searchDepth":61,"depth":61,"links":62},2,[],"markdown","content:guides:go:go-resty:loading-css-from-a-string.md","content","guides/go/go-resty/loading-css-from-a-string.md","md",[69,73,77,81,85,89,93,97,101,105,109,110,114,118,122,126,130,134,138,142,146],{"_path":70,"title":71,"language":10,"library":11,"_id":72},"/guides/go/go-resty/accessing-secured-pages","Accessing secured pages","content:guides:go:go-resty:accessing-secured-pages.md",{"_path":74,"title":75,"language":10,"library":11,"_id":76},"/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":78,"title":79,"language":10,"library":11,"_id":80},"/guides/go/go-resty/adding-a-text-watermark","Adding a text watermark","content:guides:go:go-resty:adding-a-text-watermark.md",{"_path":82,"title":83,"language":10,"library":11,"_id":84},"/guides/go/go-resty/adding-an-image-watermark","Adding an image watermark","content:guides:go:go-resty:adding-an-image-watermark.md",{"_path":86,"title":87,"language":10,"library":11,"_id":88},"/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":90,"title":91,"language":10,"library":11,"_id":92},"/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":94,"title":95,"language":10,"library":11,"_id":96},"/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":98,"title":99,"language":10,"library":11,"_id":100},"/guides/go/go-resty/define-a-time-limit","Define a time limit","content:guides:go:go-resty:define-a-time-limit.md",{"_path":102,"title":103,"language":10,"library":11,"_id":104},"/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":106,"title":107,"language":10,"library":11,"_id":108},"/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":4,"title":8,"language":10,"library":11,"_id":64},{"_path":111,"title":112,"language":10,"library":11,"_id":113},"/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":115,"title":116,"language":10,"library":11,"_id":117},"/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":119,"title":120,"language":10,"library":11,"_id":121},"/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":123,"title":124,"language":10,"library":11,"_id":125},"/guides/go/go-resty/protecting-the-generated-pdf","Protecting the generated PDF","content:guides:go:go-resty:protecting-the-generated-pdf.md",{"_path":127,"title":128,"language":10,"library":11,"_id":129},"/guides/go/go-resty/receive-a-webhook-event","Receive a webhook event","content:guides:go:go-resty:receive-a-webhook-event.md",{"_path":131,"title":132,"language":10,"library":11,"_id":133},"/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":135,"title":136,"language":10,"library":11,"_id":137},"/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":139,"title":140,"language":10,"library":11,"_id":141},"/guides/go/go-resty/send-custom-http-headers","Send custom HTTP headers","content:guides:go:go-resty:send-custom-http-headers.md",{"_path":143,"title":144,"language":10,"library":11,"_id":145},"/guides/go/go-resty/using-cookies","Using cookies to convert HTML documents to PDF","content:guides:go:go-resty:using-cookies.md",{"_path":147,"title":148,"language":10,"library":11,"_id":149},"/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",1785426828783]