Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@illbzo1
illbzo1 / nodejs_example.js
Created June 9, 2015 18:54
An example Node.js implementation for DocRaptor, that does not rely on any external dependencies.
var https = require("https"),
fs = require("fs");
var payload = JSON.stringify({
user_credentials: "YOUR_API_KEY_HERE",
doc: {
document_content: "<!DOCTYPE html><html><head><title>Javascript PDF Sample</title></head><body>Hello from Javascript!</body></html>",
name: "test.pdf",
document_type: "pdf",
test: true
@illbzo1
illbzo1 / node_request_example.js
Last active August 29, 2015 14:22
An example for making POST requests to DocRaptor in Node.js, using request instead of restler
var request = require('request');
var fs = require('fs');
var content = "<html><body>TEST!</body></html>";
config = {
url: 'https://docraptor.com/docs',
encoding: null, //IMPORTANT! This produces a binary body response instead of text
headers: {
'Content-Type': 'application/json'
},
@illbzo1
illbzo1 / doc_raptor_async_example.sh
Last active August 29, 2015 14:18
Asynchronous Curl example for DocRaptor
#This example will create a sample asynchronous pdf document with the authentication information as part of the POST data
curl -H "Content-Type:application/json" -d'{"user_credentials":"YOUR_API_KEY_HERE", "doc":{"name":"async_example.pdf", "document_type":"pdf", "async":"true", "test":"true", "document_url":"https://docraptor.com"}}' http://docraptor.com/docs > async_example.pdf
#Making an asynchronous request will return some JSON with a status_id key like '{"status_id":"123454321"}'
cat async_example.pdf
#You can then use the status_id key to check the status of your asynchronous job
curl http://docraptor.com/status/123454321 -H "Content-Type:application/json" -d '{"user_credentials":"YOUR_API_KEY_HERE"}'
#Once your job has completed, you will recieve a response that contains the download_url for your document
@illbzo1
illbzo1 / random.pdf.erb
Created April 24, 2014 16:00
A step by step Ruby on Rails implementation for DocRaptor
<style type="text/css">
/* setup the page */
@page {
size: US-Letter;
margin: 0 0 35mm 0;
background: #ffffff;
}
/* setup the footer */
@page {
@illbzo1
illbzo1 / random.pdf.erb
Created April 23, 2014 19:09
A sample template for creating PDFs with DocRaptor.
<style type="text/css">
/* setup the page */
@page {
size: US-Letter;
margin: 0 0 35mm 0;
background: #ffffff;
}
/* setup the footer */
@page {
@illbzo1
illbzo1 / show.html.erb
Created April 23, 2014 19:03
Adding some code to a view file for generating a PDF using DocRaptor.
<%= show_for @random do |s| %>
<%= s.attribute :title %>
<% end %>
<%= link_to 'Edit', edit_random_path(@random) %> |
<%= link_to 'Back', randoms_path %>
<%= link_to("Download Random PDF", random_path(@random, format: :pdf)) %>
@illbzo1
illbzo1 / random_controller.rb
Created April 23, 2014 19:01
An update to our random_controller for sending HTML to DocRaptor.
def show
@random = Random.find(params[:id])
respond_to do |format|
format.html
format.pdf { doc_raptor_send }
end
end
def doc_raptor_send(options = { })
default_options = {
@illbzo1
illbzo1 / random_controller.rb
Created April 23, 2014 18:49
A sample controller action for creating PDFs with DocRaptor.
def show
@random = Random.find(params[:id])
respond_to do |format|
format.html
format.pdf { doc_raptor_send }
end
end
@illbzo1
illbzo1 / Foo.html
Last active August 29, 2015 14:00
A sample model using the doc_raptor gem for PDF generation.
asdf