Created
July 6, 2014 22:34
-
-
Save mavnn/6f85ece046dc6636cee8 to your computer and use it in GitHub Desktop.
PDF generation: https://github.com/gmanny/Pechkin#usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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