Convert URL to PDF

If you find any problem with API, please make an issue at GitHub


2.6 How to convert url or web page to PDF using API Rest


URL

To convert an url or web page to PDF using our API Rest is necessary to perform a POST call to the following URL (ENDPOINT):

https://getoutpdf.com/api/convert/url-to-pdf


GET Parameters

Our Rest API does not have operations via GET parameters


POST Parameters

  • api_keyApi key generated for your license. You can see your api key
    (string, required)
  • urlURL to convert to PDF
    (string, required)
  • page_predefinedPredefined page size
    (string, optional, default: A4, values:A1 | A2 | A3 | A4 | Dle | Executive | Folio | Ledger | Legal | Letter)
  • page_widthPage width in millimeters (mm)
    (numeric, optional, min: 1)
  • page_heightPage height in millimeters (mm)
    (numeric, optional, min: 1)
  • The paramater "pagePredefined" will not take effect if not present, and "pageWidth" and "pageHeight" if present. In any other case, "pagePredefined" takes precedence over "pageWidth" and "pageHeight"
  • page_orientationPage orientation
    (string, optional, default: portrait, values: portrait | landscape)
  • page_numberAdd page numbers
    (boolean, optional, default: false)
  • grayscaleGrayscale PDF
    (boolean, optional, default: false)
  • margin_leftLeft margin in millimeters (mm)
    (numeric, optional, default: 0, min: 0)
  • margin_topTop margin in millimeters (mm)
    (numeric, optional, default: 0, min: 0)
  • margin_rightRight margin in millimeters (mm)
    (numeric, optional, default: 0, min: 0)
  • margin_bottomBottom margin in millimeters (mm)
    (numeric, optional, default: 0, min: 0)
  • html_disable_javascriptDo not run JavaScript
    (boolean, optional, default: false)
  • html_hide_imagesDo not print images
    (boolean, optional, default: false)
  • html_hide_backgroundsDo not print backgrounds
    (boolean, optional, default: false)
  • html_disable_hyperlinksDo not make hyperlinks
    (boolean, optional, default: false)
  • html_zoomPage zoom
    (numeric, optional, default: 100, min: 0)

You can make a POST call using the HTML Header application/x-www-form-urlencoded, with the parameters described above.

Or you can send parameters via the JSON format, using the HTML Header application/json:

{
    "api_key" : "...",                  //string, required
    "url" : "...",                      //string, required
    "page_predefined" : "...",          //string, optional, default: A4, values:A1|A2|A3|A4|Dle|Executive|Folio|Ledger|Legal|Letter
    "page_width" : "...",               //string, optional, min: 1
    "page_height" : "...",              //string, optional, min: 1
    "page_orientation" : "...",         //string, optional, default: portrait, values:portrait|landscape
    "page_number" : "...",              //string, optional, default: false
    "grayscale" : "...",                //string, optional, default: false
    "margin_left" : "...",              //string, optional, default: 0, min: 0
    "margin_top" : "...",               //string, optional, default: 0, min: 0
    "margin_right" : "...",             //string, optional, default: 0, min: 0
    "margin_bottom" : "...",            //string, optional, default: 0, min: 0
    "html_disable_javascript" : "...",  //string, optional, default: false
    "html_hide_images" : "...",         //string, optional, default: false
    "html_hide_backgrounds" : "...",    //string, optional, default: false
    "html_disable_hyperlinks" : "...",  //string, optional, default: false
    "html_zoom" : "..."                 //string, optional, default: 100, min: 0
}

Example

{
    "api_key" : "64b5d1054b69e676b9984d8406c5209a6ba78",
    "url" : "http://www.getoutpdf.com",
    "page_predefined" : "A4",
    "page_width" : 200.55,
    "page_height" : 300.75,
    "page_orientation" : "portrait",
    "page_number" : false,
    "grayscale" : false,
    "margin_left" : 2.45,
    "margin_top" : 2.45,
    "margin_right" : 2.45,
    "margin_bottom" : 2.45,
    "html_disable_javascript" : true,
    "html_hide_images" : false,
    "html_hide_backgrounds" : true,
    "html_disable_hyperlinks" : false,
    "html_zoom" : 50
}

Response

If the operation is successful the response is a JSON with the following structure:

{
    "api_key": "...",       // string - Api key used for your license
    "pdf_base64": "...",    // string - PDF file encoded in base64
    "tokens_used": "...",   // integer - Tokens used in operation
    "tokens_left": "..."    // integer - Tokens left
}

Errors

If an error in sending parameters occurs, the response is a JSON with the following structure:

{
    "errors": {
        "param1": [     // string - Parameter name that generated the error
            "message"   // string - Error description
        ],
        "param2": [
            "message"
        ],
        ...
        "paramN": [
            "message"
        ]
    }
}

If a operation error occurs, the answer will be a JSON with the following structure:

{
    "errors": [
        "message1",
        "message2",
        ...
        "messageN"
    ]
}