All Projects → balacode → One File Pdf

balacode / One File Pdf

Licence: mit
A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to One File Pdf

Svglib
Read SVG files and convert them to other formats.
Stars: ✭ 139 (-67.6%)
Mutual labels:  graphics, pdf, pdf-generation
Graphicsrenderer
A drop-in UIGraphicsRenderer port -- CrossPlatform, Swift 4, Image & PDF
Stars: ✭ 85 (-80.19%)
Mutual labels:  graphics, pdf
Rst2pdf
Use a text editor. Make a PDF.
Stars: ✭ 404 (-5.83%)
Mutual labels:  pdf, pdf-generation
Pris
A language for designing slides
Stars: ✭ 97 (-77.39%)
Mutual labels:  graphics, pdf
Pdf Lib
Create and modify PDF documents in any JavaScript environment
Stars: ✭ 3,426 (+698.6%)
Mutual labels:  pdf, pdf-generation
Pagedjs
Display paginated content in the browser and generate print books using web technology
Stars: ✭ 228 (-46.85%)
Mutual labels:  pdf, printing
Android Pdfmyxml
convert android xml layouts into PDF document, works on all versions of Android.
Stars: ✭ 231 (-46.15%)
Mutual labels:  pdf, pdf-generation
Tea School
Simplified HTML + CSS --> PDF Generator for Nodejs
Stars: ✭ 326 (-24.01%)
Mutual labels:  pdf, pdf-generation
Django Easy Pdf
PDF views, the easy way
Stars: ✭ 324 (-24.48%)
Mutual labels:  pdf, pdf-generation
Pandoc Latex Template
A pandoc LaTeX template to convert markdown files to PDF or LaTeX.
Stars: ✭ 3,750 (+774.13%)
Mutual labels:  pdf, pdf-generation
Printpdf
An easy-to-use library for writing PDF in Rust
Stars: ✭ 404 (-5.83%)
Mutual labels:  pdf, pdf-generation
Md To Pdf
Hackable CLI tool for converting Markdown files to PDF using Node.js and headless Chrome.
Stars: ✭ 374 (-12.82%)
Mutual labels:  pdf, pdf-generation
Asciidoctor Web Pdf
Convert AsciiDoc documents to PDF using web technologies
Stars: ✭ 219 (-48.95%)
Mutual labels:  pdf, pdf-generation
Pdf Bot
🤖 A Node queue API for generating PDFs using headless Chrome. Comes with a CLI, S3 storage and webhooks for notifying subscribers about generated PDFs
Stars: ✭ 2,551 (+494.64%)
Mutual labels:  pdf, pdf-generation
Pdfgen
Simple C PDF Writer/Generation library
Stars: ✭ 200 (-53.38%)
Mutual labels:  pdf, pdf-generation
Markdown Pdf
📄 Markdown to PDF converter
Stars: ✭ 2,365 (+451.28%)
Mutual labels:  pdf, pdf-generation
Chrome Headless Render Pdf
Stars: ✭ 164 (-61.77%)
Mutual labels:  pdf, pdf-generation
Resumake.io
📝 A website for automatically generating elegant LaTeX resumes.
Stars: ✭ 2,277 (+430.77%)
Mutual labels:  pdf, pdf-generation
Hummusrecipe
A powerful PDF tool for NodeJS based on HummusJS.
Stars: ✭ 274 (-36.13%)
Mutual labels:  pdf, pdf-generation
Rinohtype
The Python document processor
Stars: ✭ 365 (-14.92%)
Mutual labels:  pdf, pdf-generation

one-file-pdf - A minimalist PDF generator in <2K lines and 1 file

Go Report Card Build Status Test Coverage Gitter chat godoc License: MIT

The main idea behind this project was:
"How small can I make a PDF generator for it to still be useful for 80% of common PDF generation needs?"

The result is a single .go file with less than 1999 lines of code, about 400 of which are color and glyph-size constants, and ~350 are comments.

  • It's easier to learn about the internals of the PDF format with a small, concise library.
  • The current version of the file is indicated in the header (the timestamp).

Features:

  • The essentials for generating PDF documents, sufficient for common business reports.
  • Use all built-in PDF fonts: Courier, Helvetica, Symbol, Times, ZapfDingbats, and their variants
  • Specify colo(u)rs by name (144 web colors), HTML codes (#RRGGBB) or RGB value
  • Set columns for text (like tab stops on the page)
  • Built-in grid option to help measurement and positioning
  • Metadata properties: author, creator, keywords, subject and title
  • Set the measurement units you want: mm, cm, inches, twips or points
  • Draw lines with different thickness
  • Filled or outline rectangles, circles and ellipses
  • JPEG, GIF and transparent PNG images (filled with specified background color)
  • Stream compression can be turned on or off (PDF files normally compress streams to reduce file size, but turning it off helps in debugging or learning about PDF commands)

Not Yet Supported:

  • Unicode (requires font embedding)
  • Font embedding
  • PDF encryption
  • Paths, curves and complex graphics

Installation:

    go get github.com/balacode/one-file-pdf

Naming Convention:

All types in are prefixed with PDF for public, and 'pdf' for private types. The only type you need to use is PDF, while PDFColorNames are left public for reference.

Hello World:

package main 

import (
	"fmt"
	"github.com/balacode/one-file-pdf"
)

func main() {
    fmt.Println(`Generating a "Hello World" PDF...`)

    // create a new PDF using 'A4' page size
    var pdf = pdf.NewPDF("A4")

    // set the measurement units to centimeters
    pdf.SetUnits("cm")

    // draw a grid to help us align stuff (just a guide, not necessary)
    pdf.DrawUnitGrid()

    // draw the word 'HELLO' in orange, using 100pt bold Helvetica font
    // - text is placed on top of, not below the Y-coordinate
    // - you can use method chaining
    pdf.SetFont("Helvetica-Bold", 100).
        SetXY(5, 5).
        SetColor("Orange").
        DrawText("HELLO")

    // draw the word 'WORLD' in blue-violet, using 100pt Helvetica font
    // note that here we use the colo(u)r hex code instead
    // of its name, using the CSS/HTML format: #RRGGBB
    pdf.SetXY(5, 9).
        SetColor("#8A2BE2").
        SetFont("Helvetica", 100).
        DrawText("WORLD!")

    // draw a flower icon using 300pt Zapf-Dingbats font
    pdf.SetX(7).SetY(17).
        SetColorRGB(255, 0, 0).
        SetFont("ZapfDingbats", 300).
        DrawText("a")

    // save the file:
    // if the file exists, it will be overwritten
    // if the file is in use, prints an error message
    pdf.SaveFile("hello.pdf")
} //                                                                        main

Samples:

Click on a sample to see the PDF in more detail.

"Hello World!" sample image

"Synergy Ipsum" sample image

Changelog:

These are the most recent changes in the functionality of the package, not including internal changes which are best seen in the commits history.

2018-04-14

  • Changed CurrentPage from read-only to read/write property: added SetCurrentPage()
  • Created PageCount() read-only property
  • Created dingbats() demo to generate zapf_dingbats_table.pdf. You can use this table to look up the hex code for each icon.
  • Changed text encoding from /WinAnsiEncoding to /StandardEncoding

See changelog.md for changes made earlier.

Roadmap:

  • Achieve 100% test coverage
  • Create a unit test for every method
  • Unicode support
  • Partial font embedding
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].