GemDocs is a service that converts HTML to PDF. To create a PDF file is required: html code, which you want to convert your image token the authentication request to the server.

1. How to get a token?

Login to customer zone and select a service GemDocs. From the left menu, select "Generate a new token." Your token pojewi in the box below.

Once generated token is valid for one year.

2. How to convert a file?

The following code examples present functions of transmitting the html code to the server GemDocs and drawing the resulting PDF file in a variable.
PHP
RUBY
PYTHON 2
PYTHON 3
JAVA
function get_pdf($gemdocs) { $token = '[token_gemdocs]'; $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_POST => 1, CURLOPT_URL => 'https://gemdocs.pl/api/generate', CURLOPT_POSTFIELDS => array('html'=>$gemdocs), CURLOPT_HTTPHEADER => array('Authorization: Bearer '.$token), CURLOPT_RETURNTRANSFER => true )); $result = curl_exec($ch); curl_close($ch); return $result; }
class Gemdocs require 'uri' require 'net/http' require 'net/https' uri = URI.parse("https://gemdocs.pl/api/generate") headers = {'Authorization' =>'Bearer [token_gemdocs]'} html = "html=..." http = Net::HTTP.new(uri.host, uri.port) resp = http.post(uri.path, html, headers) puts resp.body end
import urllib import urllib2 code = '...' url = 'https://gemdocs.pl/api/generate' values = {'html': code} headers = { 'Authorization' : 'Bearer [token_gemdocs]' } data = urllib.urlencode(values) req = urllib2.Request(url, data, headers) response = urllib2.urlopen(req) the_page = response.read() print(the_page)
import urllib.parse import urllib.request document = '..' url = 'https://gemdocs.pl/api/generate' values = {'html' : document} headers = { 'Authorization' : 'Bearer [token_gembit]' } data = urllib.parse.urlencode(values) data = data.encode('utf-8') req = urllib.request.Request(url, data, headers) with urllib.request.urlopen(req) as response: the_page = response.read() print(the_page)
package gemdocs; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; public class GemDocs { public static void main(String[] args) throws Exception { String data = URLEncoder.encode("html", "UTF-8") + "=" + URLEncoder.encode("...", "UTF-8"); URL url = new URL("https://gemdocs.pl/api/generate"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); conn.setRequestProperty( "Authorization", "Bearer [token_gembit]"); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { System.out.println(line); } wr.close(); rd.close(); } }

The HTML code for the server pass the POST method, by setting "html".

Then I send in the header token. The header should be titled Authorization. Token should be preceded by a string: Bearer

Authorization: Bearer [token]

Remember to include a space before token.

The result of this query will be a PDF file ready for download or display.

Copyright © 2015 Gembit