Skip to content

Instantly share code, notes, and snippets.

@pdfcrowd
pdfcrowd / html_to_pdf.cpp
Last active March 30, 2023 07:34
Convert a web page or HTML file to PDF in C++. Complete tutorial: https://pdfcrowd.com/blog/convert-html-to-pdf-in-cpp/
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <curl/curl.h>
const char* api_url = "https://api.pdfcrowd.com/convert/latest/";
const char* username = "demo";
const char* api_key = "ce544b6ea52a5621fb9d55f8b542d14d";
@pdfcrowd
pdfcrowd / html_to_pdf.rs
Created March 16, 2023 07:58
Convert a web page or HTML file to PDF in Rust. Complete tutorial: https://pdfcrowd.com/blog/
use std::fs::File;
use std::error::Error;
use reqwest::blocking::Client;
use reqwest::blocking::multipart::{Form, Part};
// API endpoint and Pdfcrowd credentials
static API_ENDPOINT: &'static str = "https://api.pdfcrowd.com/convert/latest/";
static USERNAME: &'static str = "demo";
static API_KEY: &'static str = "ce544b6ea52a5621fb9d55f8b542d14d";
@pdfcrowd
pdfcrowd / html_to_pdf.c
Last active March 16, 2023 08:20
This code shows how to convert HTML to PDF in C using the Pdfcrowd API. You can find the tutorial here: https://pdfcrowd.com/blog/convert-html-to-pdf-in-c/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#define API_ENDPOINT "https://api.pdfcrowd.com/convert/latest/"
#define USERNAME "demo"
#define API_KEY "ce544b6ea52a5621fb9d55f8b542d14d"
/* structure for conversion options */
@pdfcrowd
pdfcrowd / gcp_ip_ranges.sh
Last active February 24, 2020 14:40
Output Google Cloud IP ranges
#!/bin/bash
dig @8.8.8.8 +short txt _cloud-netblocks.googleusercontent.com | \
sed 's/"//g; s/ip4://g; s/ip6://g;' | \
tr ' ' '\n' | \
grep include | cut -d ':' -f2 | \
xargs dig @8.8.8.8 +short txt | \
sed 's/"//g; s/ip4://g; s/ip6://g;' | tr ' ' '\n' | grep '/'
@pdfcrowd
pdfcrowd / pdfmail2_api_v2.php
Created September 28, 2018 07:05
Generate a PDF using Pdfcrowd API v2 and send it as an email attachment (II.)
<?php
require 'pdfcrowd.php';
try
{
// generate a PDF file
$client = new \Pdfcrowd\HtmlToPdfClient($username, $apikey);
$pdf = $client->convertString('Hello World');
@pdfcrowd
pdfcrowd / pdfmail_api_v2.php
Created September 28, 2018 07:01
Generate PDF using the Pdfcrowd API v2 and send it as an email attachment
// uses the PHP PEAR modules for sending MIME email
// http://pear.php.net/package/Mail
// http://pear.php.net/package/Mail_Mime
<?php
require 'pdfcrowd.php';
require_once('Mail.php');
require_once('Mail/mime.php');
$client = new \Pdfcrowd\HtmlToPdfClient($username, $apikey);
@pdfcrowd
pdfcrowd / pdfcrowd.c
Created October 17, 2012 12:02
A simple C app that creates PDF from a local HTML file
/* compile with: $ gcc pdfcrowd.c -lcurl -o pdfcrowd */
#include <curl/curl.h>
/*
* return values:
* 0 success
* 1 curl fatal error
* 2 curl error
* >399 API error (HTTP status code)
*/
@pdfcrowd
pdfcrowd / pdfmail2.php
Last active February 15, 2020 21:18
generate a PDF using the Pdfcrowd API and send it as an email attachment (II.)
<?php
require 'pdfcrowd.php';
try
{
// generate a PDF file
$client = new Pdfcrowd($username, $apikey);
$pdf = $client->convertHtml("Hello World");
@pdfcrowd
pdfcrowd / pdfmail_api_v1.php
Last active February 15, 2020 21:18
Generate PDF using the Pdfcrowd API v1 and send it as an email attachment
// uses the PHP PEAR modules for sending MIME email
// http://pear.php.net/package/Mail
// http://pear.php.net/package/Mail_Mime
<?php
require 'pdfcrowd.php';
require_once('Mail.php');
require_once('Mail/mime.php');
@pdfcrowd
pdfcrowd / header_and_footer.php
Created June 8, 2011 16:44
Pdfcrowd PHP API - Header & Footer