[{"data":1,"prerenderedAt":156},["Reactive",2],{"/guides/go/nethttp/generate-a-document-with-full-height":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":11,"property":12,"output":13,"default":14,"body":15,"_type":151,"_id":152,"_source":153,"_file":154,"_extension":155},"/guides/go/nethttp/generate-a-document-with-full-height","nethttp",false,"","Generate a document with full height","Learn to generate full-height documents dynamically with our step-by-step guide. This will allow you to create documents with a dynamic height, based on the content of the document. This guide provides Go code samples using the Net/HTTP library to help you generate full-height documents with PDFShift's API.","Go","Net/HTTP","format","pdf",true,{"type":16,"children":17,"toc":148},"root",[18,26,47,59,64,75,96,101,112],{"type":19,"tag":20,"props":21,"children":22},"element","p",{},[23],{"type":24,"value":25},"text","In this guide, we'll show you how to generate a document with full height dynamically using Go and the Net/HTTP library to convert them to PDF using PDFShift's API.",{"type":19,"tag":20,"props":27,"children":28},{},[29,31,37,39,45],{"type":24,"value":30},"When you're converting a document, you might want to generate a document with full height dynamically. This can be done by setting the ",{"type":19,"tag":32,"props":33,"children":35},"code",{"className":34},[],[36],{"type":24,"value":12},{"type":24,"value":38}," parameter to the request and passing it a custom \"auto\" value for the ",{"type":19,"tag":32,"props":40,"children":42},{"className":41},[],[43],{"type":24,"value":44},"{height}",{"type":24,"value":46}," part.",{"type":19,"tag":48,"props":49,"children":54},"pre",{"className":50,"code":52,"language":53,"meta":7},[51],"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        \"format\": \"1280xauto\",\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",[55],{"type":19,"tag":32,"props":56,"children":57},{"__ignoreMap":7},[58],{"type":24,"value":52},{"type":19,"tag":20,"props":60,"children":61},{},[62],{"type":24,"value":63},"The format parameter can accept various values, such as 'Letter', 'Legal', 'Tabloid', 'Ledger', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5'.",{"type":19,"tag":20,"props":65,"children":66},{},[67,69],{"type":24,"value":68},"But it can also accept a custom values that is defined per the width and height as follow: ",{"type":19,"tag":32,"props":70,"children":72},{"className":71},[],[73],{"type":24,"value":74},"{width}x{height}",{"type":19,"tag":20,"props":76,"children":77},{},[78,80,86,88,94],{"type":24,"value":79},"Both ",{"type":19,"tag":32,"props":81,"children":83},{"className":82},[],[84],{"type":24,"value":85},"width",{"type":24,"value":87}," and ",{"type":19,"tag":32,"props":89,"children":91},{"className":90},[],[92],{"type":24,"value":93},"height",{"type":24,"value":95}," are pixel value by default, but if you precise the unit (in \"cm\", \"mm\", \"in\" or \"pt\"). That unit will be used instead.",{"type":19,"tag":20,"props":97,"children":98},{},[99],{"type":24,"value":100},"For instance, you can set a format of:",{"type":19,"tag":48,"props":102,"children":107},{"className":103,"code":105,"language":106,"meta":7},[104],"language-json","{\n    \"source\": \"https://www.example.com\",\n    \"format\": \"21cmx29,7cm\"\n}\n","json",[108],{"type":19,"tag":32,"props":109,"children":110},{"__ignoreMap":7},[111],{"type":24,"value":105},{"type":19,"tag":20,"props":113,"children":114},{},[115,117,122,124,130,132,138,140,146],{"type":24,"value":116},"Now, if you want a \"liquid\" height, which will analyze the height of the page and use it as your format, you can set the ",{"type":19,"tag":32,"props":118,"children":120},{"className":119},[],[121],{"type":24,"value":44},{"type":24,"value":123}," value to ",{"type":19,"tag":32,"props":125,"children":127},{"className":126},[],[128],{"type":24,"value":129},"auto",{"type":24,"value":131},".\nSo, instead of setting a fixed height such as ",{"type":19,"tag":32,"props":133,"children":135},{"className":134},[],[136],{"type":24,"value":137},"'format': '1280x1024'",{"type":24,"value":139},", you can set ",{"type":19,"tag":32,"props":141,"children":143},{"className":142},[],[144],{"type":24,"value":145},"'format': '1280xauto'",{"type":24,"value":147}," and the height will be calculated based on the content of the page.",{"title":7,"searchDepth":149,"depth":149,"links":150},2,[],"markdown","content:guides:go:nethttp:generate-a-document-with-full-height.md","content","guides/go/nethttp/generate-a-document-with-full-height.md","md",1785426824631]