Skip to content

Instantly share code, notes, and snippets.

@mavnn
Created July 6, 2014 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mavnn/6f85ece046dc6636cee8 to your computer and use it in GitHub Desktop.
Save mavnn/6f85ece046dc6636cee8 to your computer and use it in GitHub Desktop.
module PDF
// You can install Pechkin from NuGet
open Pechkin
open System.Drawing.Printing
[<Measure>]
type mm
[<Measure>]
type inch100th
let inch100esPerMillimetre = 3.937<inch100th/mm>
let getBytes (s : string) = System.Text.UTF8Encoding.UTF8.GetBytes s
type PrintArea =
| PaperKind of PaperKind
| CustomSize of float<mm> * float<mm>
let internal baseConfig size =
match size with
| PaperKind kind -> GlobalConfig().SetPaperSize(kind)
| CustomSize(x, y) ->
let (x', y') = inch100esPerMillimetre * x, inch100esPerMillimetre * y
GlobalConfig().SetPaperSize(x' / 1.0<inch100th> |> int, y' / 1.0<inch100th> |> int)
let create size title =
let config =
(baseConfig size)
.SetPaperOrientation(false)
.SetDocumentTitle(title)
.SetMargins(0, 0, 0, 0)
.SetImageQuality(96)
.SetOutputDpi(96)
new SimplePechkin(config)
// Usage
// Create a "Simple Pechkin" with correct paper size and doc title
let pech =
create (PaperKind PaperKind.A4) "My pdf"
// Turn html into pdf...
let writePdf () =
pech.Convert("<html><body><h1>Hello world</h1></body></html>")
|> fun x -> System.IO.File.WriteAllBytes("test.pdf", x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment