[{"data":1,"prerenderedAt":156},["Reactive",2],{"/guides/go/nethttp/loading-css-from-a-url":3,"related:a5h3FqL1gh":74},{"_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":19,"body":20,"_type":69,"_id":70,"_source":71,"_file":72,"_extension":73},"/guides/go/nethttp/loading-css-from-a-url","nethttp",false,"","Loading CSS from a URL","This guides shows you how to add a custom CSS from an URL onto your document to customize the output of your generated PDF. Follow this guides to learn how to do it using Go and the Net/HTTP library and see how it can quickly be implemented using the PDFShift's API.","Go","Net/HTTP","css","pdf",[15,16,17,18],"adding-a-custom-header-or-footer","loading-css-from-a-string","loading-javascript-from-a-string","loading-javascript-from-a-url",true,{"type":21,"children":22,"toc":66},"root",[23,31,36,41,54],{"type":24,"tag":25,"props":26,"children":27},"element","p",{},[28],{"type":29,"value":30},"text","In this guide, we'll show you how to load custom CSS as a URL 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":24,"tag":25,"props":32,"children":33},{},[34],{"type":29,"value":35},"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":24,"tag":25,"props":37,"children":38},{},[39],{"type":29,"value":40},"Moreover, adding a URL can be easier to do than passing the raw CSS content, as it allows you to later modify that CSS without having to modify the query made to PDFShift.",{"type":24,"tag":42,"props":43,"children":48},"pre",{"className":44,"code":46,"language":47,"meta":7},[45],"language-go","package main\n\nimport (\n    \"bytes\"\n    \"encoding/json\"\n    \"fmt\"\n    \"io/ioutil\"\n    \"net/http\"\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\": \"https://www.example.com/public/style/print.css\",\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\n    // Create a new HTTP client\n    client := &http.Client{}\n\n    // Create a new request\n    req, err := http.NewRequest(\"POST\", \"https://api.pdfshift.io/v3/convert/pdf\", bytes.NewBuffer(jsonParams))\n    if err != nil {\n        fmt.Println(\"Error creating request:\", err)\n        return\n    }\n\n    // Set request headers\n    req.Header.Set(\"Content-Type\", \"application/json\")\n\n    // Set basic authentication header\n    req.Header.Set(\"X-API-Key\", apiKey)\n\n    // Perform the request\n    resp, err := client.Do(req)\n    if err != nil {\n        fmt.Println(\"Error performing request:\", err)\n        return\n    }\n    defer resp.Body.Close()\n\n    // Read response body\n    body, err := ioutil.ReadAll(resp.Body)\n    if err != nil {\n        fmt.Println(\"Error reading response body:\", 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(body))\n        return\n    }\n\n    // Save the PDF document\n    err = ioutil.WriteFile(\"result.pdf\", 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":24,"tag":50,"props":51,"children":52},"code",{"__ignoreMap":7},[53],{"type":29,"value":46},{"type":24,"tag":25,"props":55,"children":56},{},[57,59,64],{"type":29,"value":58},"The ",{"type":24,"tag":50,"props":60,"children":62},{"className":61},[],[63],{"type":29,"value":12},{"type":29,"value":65}," 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":67,"depth":67,"links":68},2,[],"markdown","content:guides:go:nethttp:loading-css-from-a-url.md","content","guides/go/nethttp/loading-css-from-a-url.md","md",[75,79,83,87,91,95,99,103,107,111,115,119,120,124,128,132,136,140,144,148,152],{"_path":76,"title":77,"language":10,"library":11,"_id":78},"/guides/go/nethttp/accessing-secured-pages","Accessing secured pages","content:guides:go:nethttp:accessing-secured-pages.md",{"_path":80,"title":81,"language":10,"library":11,"_id":82},"/guides/go/nethttp/adding-a-custom-header-or-footer","Adding a custom header or footer","content:guides:go:nethttp:adding-a-custom-header-or-footer.md",{"_path":84,"title":85,"language":10,"library":11,"_id":86},"/guides/go/nethttp/adding-a-text-watermark","Adding a text watermark","content:guides:go:nethttp:adding-a-text-watermark.md",{"_path":88,"title":89,"language":10,"library":11,"_id":90},"/guides/go/nethttp/adding-an-image-watermark","Adding an image watermark","content:guides:go:nethttp:adding-an-image-watermark.md",{"_path":92,"title":93,"language":10,"library":11,"_id":94},"/guides/go/nethttp/avoid-conversion-on-error","Avoid the conversion on error when loading the document","content:guides:go:nethttp:avoid-conversion-on-error.md",{"_path":96,"title":97,"language":10,"library":11,"_id":98},"/guides/go/nethttp/convert-html-to-pdf-from-a-url","Convert an HTML document to PDF from a URL","content:guides:go:nethttp:convert-html-to-pdf-from-a-url.md",{"_path":100,"title":101,"language":10,"library":11,"_id":102},"/guides/go/nethttp/convert-html-to-pdf-from-raw-html","Convert an HTML document to PDF from raw HTML","content:guides:go:nethttp:convert-html-to-pdf-from-raw-html.md",{"_path":104,"title":105,"language":10,"library":11,"_id":106},"/guides/go/nethttp/define-a-time-limit","Define a time limit","content:guides:go:nethttp:define-a-time-limit.md",{"_path":108,"title":109,"language":10,"library":11,"_id":110},"/guides/go/nethttp/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","content:guides:go:nethttp:exporting-only-a-specific-set-of-pages.md",{"_path":112,"title":113,"language":10,"library":11,"_id":114},"/guides/go/nethttp/generate-a-document-with-full-height","Generate a document with full height","content:guides:go:nethttp:generate-a-document-with-full-height.md",{"_path":116,"title":117,"language":10,"library":11,"_id":118},"/guides/go/nethttp/loading-css-from-a-string","Loading CSS from a string","content:guides:go:nethttp:loading-css-from-a-string.md",{"_path":4,"title":8,"language":10,"library":11,"_id":70},{"_path":121,"title":122,"language":10,"library":11,"_id":123},"/guides/go/nethttp/loading-javascript-from-a-string","Loading Javascript from a string","content:guides:go:nethttp:loading-javascript-from-a-string.md",{"_path":125,"title":126,"language":10,"library":11,"_id":127},"/guides/go/nethttp/loading-javascript-from-a-url","Loading Javascript from a URL","content:guides:go:nethttp:loading-javascript-from-a-url.md",{"_path":129,"title":130,"language":10,"library":11,"_id":131},"/guides/go/nethttp/protecting-the-generated-pdf","Protecting the generated PDF","content:guides:go:nethttp:protecting-the-generated-pdf.md",{"_path":133,"title":134,"language":10,"library":11,"_id":135},"/guides/go/nethttp/receive-a-webhook-event","Receive a webhook event","content:guides:go:nethttp:receive-a-webhook-event.md",{"_path":137,"title":138,"language":10,"library":11,"_id":139},"/guides/go/nethttp/save-your-pdf-online-and-get-back-a-url","Save your PDF online and get back a URL","content:guides:go:nethttp:save-your-pdf-online-and-get-back-a-url.md",{"_path":141,"title":142,"language":10,"library":11,"_id":143},"/guides/go/nethttp/save-your-pdf-to-your-amazon-s3-bucket","Save your PDF to your Amazon S3 Bucket","content:guides:go:nethttp:save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":145,"title":146,"language":10,"library":11,"_id":147},"/guides/go/nethttp/send-custom-http-headers","Send custom HTTP headers","content:guides:go:nethttp:send-custom-http-headers.md",{"_path":149,"title":150,"language":10,"library":11,"_id":151},"/guides/go/nethttp/using-cookies","Using cookies to convert HTML documents to PDF","content:guides:go:nethttp:using-cookies.md",{"_path":153,"title":154,"language":10,"library":11,"_id":155},"/guides/go/nethttp/waiting-for-a-custom-element-to-be-ready","Waiting for a custom element to be ready","content:guides:go:nethttp:waiting-for-a-custom-element-to-be-ready.md",1785426824694]