[{"data":1,"prerenderedAt":123},["Reactive",2],{"/guides/go/nethttp/exporting-only-a-specific-set-of-pages":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":118,"_id":119,"_source":120,"_file":121,"_extension":122},"/guides/go/nethttp/exporting-only-a-specific-set-of-pages","nethttp",false,"","Exporting only a specific set of pages","Learn how to export only a specific set of pages from a document using Go and the Net/HTTP library. This guide offers detailed steps with code samples in Go and the Net/HTTP library, highlighting how you can export only a specific set of pages from a document using PDFShift's API.","Go","Net/HTTP","pages","pdf",true,{"type":16,"children":17,"toc":115},"root",[18,26,39,44,49,93,98,103],{"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 export only a specific set of pages from a document 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],{"type":24,"value":30},"When you're converting a document, you might want to export only a specific set of pages from a document. 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.",{"type":19,"tag":20,"props":40,"children":41},{},[42],{"type":24,"value":43},"It behaves exactly like the page parameter you can see when you print a document from your browser.",{"type":19,"tag":20,"props":45,"children":46},{},[47],{"type":24,"value":48},"It accepts the following pattern:",{"type":19,"tag":50,"props":51,"children":52},"ul",{},[53,67,80],{"type":19,"tag":54,"props":55,"children":56},"li",{},[57,59,65],{"type":24,"value":58},"A number, such as ",{"type":19,"tag":32,"props":60,"children":62},{"className":61},[],[63],{"type":24,"value":64},"2",{"type":24,"value":66},". This will print the page 2",{"type":19,"tag":54,"props":68,"children":69},{},[70,72,78],{"type":24,"value":71},"A range, such as ",{"type":19,"tag":32,"props":73,"children":75},{"className":74},[],[76],{"type":24,"value":77},"2-4",{"type":24,"value":79},". This will print the pages 2 to 4 (2, 3 and 4)",{"type":19,"tag":54,"props":81,"children":82},{},[83,85,91],{"type":24,"value":84},"A list, such as ",{"type":19,"tag":32,"props":86,"children":88},{"className":87},[],[89],{"type":24,"value":90},"2,4,5,9",{"type":24,"value":92},". This will print the pages 2, 4, 5 and 9",{"type":19,"tag":20,"props":94,"children":95},{},[96],{"type":24,"value":97},"This way, you can only export the pages that you really need and get immediately the result you want in the PDF, without having to edit it.",{"type":19,"tag":20,"props":99,"children":100},{},[101],{"type":24,"value":102},"Here's an example:",{"type":19,"tag":104,"props":105,"children":110},"pre",{"className":106,"code":108,"language":109,"meta":7},[107],"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://en.wikipedia.org/wiki/PDF\",\n        \"pages\":  \"2-4\",\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",[111],{"type":19,"tag":32,"props":112,"children":113},{"__ignoreMap":7},[114],{"type":24,"value":108},{"title":7,"searchDepth":116,"depth":116,"links":117},2,[],"markdown","content:guides:go:nethttp:exporting-only-a-specific-set-of-pages.md","content","guides/go/nethttp/exporting-only-a-specific-set-of-pages.md","md",1785426824629]