pdf document generation library

gopdf

GitHub GitHub GitHub GitHub issues GitHub code size in bytes

项目介绍

gopdf 是一个生成 PDF 文档的 Golang 库. 主要有以下的特点:

  • 支持 Unicode 字符 (包括中文, 日语, 朝鲜语, 等等.)
  • 文档内容的自动定位与分页, 减少用户的工作量.
  • 支持图片插入, 支持多种图片格式, PNG, BMP, JPEG, WEBP, TIFF
  • 支持文档压缩
  • 复杂表格组件, 块文本等
  • markdown 文本可以直接转换成 pdf
  • 手动实现了 markdown 解析库, 可以提供其他 markdown 开发

安装

go get -u github.com/tiechui1994/gopdf

案例展示:

image

代码参考 example/complex_report_test

image

代码参考 example/simple_table_test

image

代码参考 example/mutil_table_test

未来开发计划

  1. 准备尝试开发 Markdown 的语法解析库, 然后通过解析库将 markdown 转换成 pdf, 可以支持定义一些颜色风格. 目前正 在研究 marked.js 前段库, 寻找灵感.

  2. 优化 Markedown 的解析库, 调整 markdown 转 pdf 的参数, 使得 pdf 页面更美观.

  3. 开发更加通俗易用的组件, 比如 paragraph, tablecell 等.

Similar Resources

A general purpose application and library for aligning text.

align A general purpose application that aligns text The focus of this application is to provide a fast, efficient, and useful tool for aligning text.

Sep 27, 2022

A NMEA parser library in pure Go

go-nmea This is a NMEA library for the Go programming language (Golang). Features Parse individual NMEA 0183 sentences Support for sentences with NMEA

Dec 20, 2022

Go library for the TOML language

go-toml Go library for the TOML format. This library supports TOML version v1.0.0-rc.3 Features Go-toml provides the following features for using data

Dec 27, 2022

A Go library to parse and format vCard

go-vcard A Go library to parse and format vCard. Usage f, err := os.Open("cards.vcf") if err != nil { log.Fatal(err) } defer f.Close() dec := vcard.

Dec 26, 2022

A declarative struct-tag-based HTML unmarshaling or scraping package for Go built on top of the goquery library

goq Example import ( "log" "net/http" "astuart.co/goq" ) // Structured representation for github file name table type example struct { Title str

Dec 12, 2022

omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.

omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.

omniparser Omniparser is a native Golang ETL parser that ingests input data of various formats (CSV, txt, fixed length/width, XML, EDI/X12/EDIFACT, JS

Jan 4, 2023

The Go library for working with delimited separated value (DSV).

Package dsv is a Go library for working with delimited separated value (DSV). NOTE: This package has been deprecated. See https://github.com/shuLhan/s

Sep 15, 2021

Upskirt markdown library bindings for Go

Goskirt Package goskirt provides Go-bindings for the excellent Sundown Markdown parser. (F/K/A Upskirt). To use goskirt, create a new Goskirt-value wi

Oct 23, 2022

Golang HTML to plaintext conversion library

html2text Converts HTML into text of the markdown-flavored variety Introduction Ensure your emails are readable by all! Turns HTML into raw text, usef

Dec 28, 2022
Comments
  • 请求帮助 invalid memory address or nil pointer dereference

    请求帮助 invalid memory address or nil pointer dereference

    如何复现:如下所示,把示例文件 simple_table_test.go 的一部分注释掉了。 期望的结果:只生成0-0,0-1,0-3,1-0四个单元格。

    package example
    
    import (
    	"fmt"
    	"github.com/tiechui1994/gopdf"
    	"github.com/tiechui1994/gopdf/core"
    	"testing"
    )
    
    const (
    	TABLE_IG = "IPAexG"
    	TABLE_MD = "MPBOLD"
    	TABLE_MY = "微软雅黑"
    )
    
    func SimpleTable() {
    	r := core.CreateReport()
    	font3 := core.FontMap{
    		FontName: TABLE_MY,
    		FileName: "D:/microsoft.ttf",
    	}
    	r.SetFonts([]*core.FontMap{&font3})
    	r.SetPage("A4", "P")
    
    	r.RegisterExecutor(core.Executor(SimpleTableExecutor), core.Detail)
    
    	r.Execute("D:/simple_table.pdf")
    	fmt.Println(r.GetCurrentPageNo())
    }
    func SimpleTableExecutor(report *core.Report) {
    	lineSpace := 1.0
    	lineHeight := 18.0
    
    	table := gopdf.NewTable(5, 100, 415, lineHeight, report)
    	table.SetMargin(core.Scope{})
    
    	// 先把当前的行设置完毕, 然后才能添加单元格内容.
    	c00 := table.NewCellByRange(1, 1)
    	c01 := table.NewCellByRange(2, 1)
    	c03 := table.NewCellByRange(2, 2)
    	c10 := table.NewCellByRange(3, 1)
    
    	f1 := core.Font{Family: TABLE_MY, Size: 15, Style: ""}
    	border := core.NewScope(4.0, 4.0, 4.0, 3.0)
    	c00.SetElement(gopdf.NewTextCell(table.GetColWidth(0, 0), lineHeight, lineSpace, report).SetFont(f1).SetBorder(border).HorizontalCentered().SetContent("0-0"))
    	c01.SetElement(gopdf.NewTextCell(table.GetColWidth(0, 1), lineHeight, lineSpace, report).SetFont(f1).SetBorder(border).RightAlign().SetContent("0-1"))
    	c03.SetElement(gopdf.NewTextCell(table.GetColWidth(0, 3), lineHeight, lineSpace, report).SetFont(f1).SetBorder(border).RightAlign().SetContent("0-3近日,江苏苏州市姑苏区市场监督管理局向苏州定园旅游服务有限公司送达行政处罚决定书,对定园进行处罚,吊销其营业执照,此举开创了我国旅游景点因虚假宣传被吊销营业执照的先河"))
    	c10.SetElement(gopdf.NewTextCell(table.GetColWidth(1, 0), lineHeight, lineSpace, report).SetFont(f1).SetBorder(border).VerticalCentered().SetContent("1-0近日,江苏苏州市姑苏区市场监督管理局向苏州定园旅游服务有限公司送达行政处罚决定书了我国旅游景点因虚假宣传被吊销营业执照的先河"))
    
    	//f1 = core.Font{Family: TABLE_MY, Size: 10}
    	//border = core.NewScope(4.0, 4.0, 0, 0)
    	//
    	//for i := 0; i < 98; i++ {
    	//	cells := make([]*gopdf.TableCell, 5)
    	//	for j := 0; j < 5; j++ {
    	//		cells[j] = table.NewCell()
    	//	}
    	//
    	//	for j := 0; j < 5; j++ {
    	//		str := `有限公司送达行政处罚决定书`
    	//		s := fmt.Sprintf("%v-%v", i+2, str)
    	//		w := table.GetColWidth(i+2, j)
    	//		e := gopdf.NewTextCell(w, lineHeight, lineSpace, report)
    	//		e.SetFont(f1)
    	//		if i%2 == 0 {
    	//			e.SetBackColor("255,192,203")
    	//		}
    	//		e.SetBorder(border)
    	//		e.SetContent(s)
    	//		cells[j].SetElement(e)
    	//	}
    	//}
    
    	table.GenerateAtomicCell()
    }
    
    func TestSimpleTable(t *testing.T) {
    	SimpleTable()
    }
    
  • markdown file contains table,  fails to resolve them.

    markdown file contains table, fails to resolve them.

    |四个单词|四个单词|四个单词|四个单词|四个单词|四个单词|四个单词|四个单词|四个单词|四个单词| |:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:| |2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10| |2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|2020-01-10 10:10:10|

    结果如下 18:09:17 markdown.go:1017: children 0

golang 在线预览word,excel,pdf,MarkDown(Online Preview Word,Excel,PPT,PDF,Image by Golang)
golang 在线预览word,excel,pdf,MarkDown(Online Preview Word,Excel,PPT,PDF,Image by Golang)

Go View File 在线体验地址 http://39.97.98.75:8082/view/upload (不会经常更新,保留最基本的预览功能。服务器配置较低,如果出现链接超时请等待几秒刷新重试,或者换Chrome) 目前已经完成 docker部署 (不用为运行环境烦恼) Wor

Dec 26, 2022
pdfcpu is a PDF processor written in Go.
pdfcpu is a PDF processor written in Go.

pdfcpu is a PDF processing library written in Go supporting encryption. It provides both an API and a CLI. Supported are all versions up to PDF 1.7 (ISO-32000).

Jan 4, 2023
Take screenshots of websites and create PDF from HTML pages using chromium and docker

gochro is a small docker image with chromium installed and a golang based webserver to interact wit it. It can be used to take screenshots of w

Nov 23, 2022
A PDF renderer for the goldmark markdown parser.
A PDF renderer for the goldmark markdown parser.

goldmark-pdf goldmark-pdf is a renderer for goldmark that allows rendering to PDF. Reference See https://pkg.go.dev/github.com/stephenafamo/goldmark-p

Jan 7, 2023
Convert your markdown files to PDF instantly
Convert your markdown files to PDF instantly

Will take a markdown file as input and then create a PDF file with the markdown formatting.

Nov 7, 2022
Produces a set of tags from given source. Source can be either an HTML page, Markdown document or a plain text. Supports English, Russian, Chinese, Hindi, Spanish, Arabic, Japanese, German, Hebrew, French and Korean languages.
Produces a set of tags from given source. Source can be either an HTML page, Markdown document or a plain text. Supports English, Russian, Chinese, Hindi, Spanish, Arabic, Japanese, German, Hebrew, French and Korean languages.

Tagify Gets STDIN, file or HTTP address as an input and returns a list of most popular words ordered by popularity as an output. More info about what

Dec 19, 2022
Convert Microsoft Word Document to Markdown
Convert Microsoft Word Document to Markdown

docx2md Convert Microsoft Word Document to Markdown Usage $ docx2md NewDocument.docx Installation $ go get github.com/mattn/docx2md Supported Styles

Jan 4, 2023
Online server tool to made markdown document.

An authenticated(basic auth with digest) docsify server for private markdown documents. Embedded docsify-mermaid as UML tool.

Oct 16, 2021
Mdlinks - Markdown cross-document links checker

mdlinks This repository provides Go package, command-line tool, and a GitHub Action that can verify cross-document links in a collection of markdown f

Mar 19, 2022
A targeted word list generation tool
A targeted word list generation tool

dirtywords Inspired by gau, dirtywords builds targeted wordlists for a given domain using "dirty" knowledge from AlienVault's Open Threat Exchange, th

Dec 3, 2022