Skip to content

Commit

Permalink
feat(html): convert html to pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
csabaujvari committed Jan 25, 2023
1 parent 905faf9 commit 7a45315
Show file tree
Hide file tree
Showing 20 changed files with 1,217 additions and 12 deletions.
44 changes: 44 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: 2.1

jobs:
build:
machine:
enabled: true
steps:
- checkout
- run:
name: Start Docker
command: |
sudo service docker start
sudo chmod +x /usr/local/bin/docker-compose
- run:
name: Start Docker Containers
command: |
docker-compose -f docker-compose.test.yml up -d
- run:
name: Stop and remove Docker Containers
command: |
docker-compose -f docker-compose.test.yml down
release:
docker:
- image: cimg/node:18.13.0
steps:
- checkout
- run:
name: Release
command: |
if [[ $(git rev-parse --abbrev-ref HEAD) == "main" ]]; then
npm install -g semantic-release @semantic-release/github @semantic-release/git @semantic-release/commit-analyzer @semantic-release/npm @semantic-release/release-notes-generator
semantic-release
else
echo "Not on main branch, skipping release."
fi
workflows:
version: 2
build_and_test:
jobs:
- build
release:
jobs:
- release
231 changes: 219 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,222 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Created by https://www.toptal.com/developers/gitignore/api/goland,jetbrains,osx
# Edit at https://www.toptal.com/developers/gitignore?templates=goland,jetbrains,osx

# Test binary, built with `go test -c`
*.test
### GoLand ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# User-specific stuff
.idea/
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Dependency directories (remove the comment below to include it)
# vendor/
# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### GoLand Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/

# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/

# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$

# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml

# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml

### JetBrains ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff

# AWS User-specific

# Generated files

# Sensitive or high-churn files

# Gradle

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake

# Mongo Explorer plugin

# File-based project format

# IntelliJ

# mpeltonen/sbt-idea plugin

# JIRA plugin

# Cursive Clojure plugin

# SonarLint plugin

# Crashlytics plugin (for Android Studio and IntelliJ)

# Editor-based Rest Client

# Android studio 3.1+ serialized cache file

### JetBrains Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint

# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin

# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced

# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257

# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream

# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij

### OSX ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# End of https://www.toptal.com/developers/gitignore/api/goland,jetbrains,osx
43 changes: 43 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"branches": ["main"],
"plugins": [
["@semantic-release/commit-analyzer",{
"preset": "angular",
"releaseRules": [
{"type": "docs", "release": "patch"},
{"type": "refactor", "release": "patch"},
{"type": "style", "release": "patch"},
{"type": "chore", "release": "patch"},
{"type": "ci", "release": "patch"}
],
"parserOpts": {
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES"]
}
}],
"@semantic-release/release-notes-generator",
"@semantic-release/git",
"@semantic-release/github"
],
"verifyConditions": [
"@semantic-release/git"
],
"prepare": [
"@semantic-release/git"
],
"publish": [
"@semantic-release/github"
],
"success": [
"@semantic-release/github"
],
"fail": [
"@semantic-release/github"
],
"git": {
"path": ".",
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
},
"github": {
"assets": "dist/*"
}
}
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
**⚠️ Working with Gotenberg >= 7 ⚠️**

# Gotenberg Go client

A simple Go client for interacting with a Gotenberg API.

Inspired by [thecodingmachine/gotenberg-go-client](https://github.com/thecodingmachine/gotenberg-go-client)

## Install

```bash
$ go get -u github.com/commitsmart/gotenberg-go-client
```

## Usage

```golang
ctx := context.Background()
httpClient := &http.Client{
Timeout: time.Duration(5) * time.Second,
}
client := gotenberg.NewClient("localhost:3000", httpClient)

// from a path.
index, err := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
check(err)
// ... or from a string.
// index, err := gotenberg.NewDocumentFromString("index.html", "<html>Foo</html>")
// ... or from bytes.
// index, err := gotenberg.NewDocumentFromBytes("index.html", []byte("<html>Foo</html>"))

header, err := gotenberg.NewDocumentFromPath("header.html", "/path/to/file")
check(err)
footer, err := gotenberg.NewDocumentFromPath("footer.html", "/path/to/file")
check(err)
style, err := gotenberg.NewDocumentFromPath("style.css", "/path/to/file")
check(err)
img, err := gotenberg.NewDocumentFromPath("img.png", "/path/to/file")
check(err)

req := gotenberg.NewConvertHTMLRequest(index)
req.Header(header)
req.Footer(footer)
req.Assets(style, img)
req.PaperSize(gotenberg.A4)
req.Margins(gotenberg.NoMargins)
req.Scale(0.75)
req.PreferCssPageSize(false)
req.OmitBackground(false)
req.PrintBackground(true)
//req.UserAgent("")
req.FailOnConsoleExceptions(true)
req.EmulatedMediaType("print")
req.PDFFormat("PDF/A-1a")
req.ExtraHttpHeaders("{\"MyHeader\": \"MyValue\"}")

// store method allows you to... store the resulting PDF in a particular destination.
client.Store(ctx, req, "path/you/want/the/pdf/to/be/stored.pdf")
// if you wish to redirect the response directly to the browser, you may also use:
resp, err := client.Post(ctx, req)
check(err)

bb, err := io.ReadAll(resp.Body)
check(err)
```

For more complete guides read the [documentation](https://gotenberg.dev/docs/about).
Loading

0 comments on commit 7a45315

Please sign in to comment.