Skip to content

ansufw/gopdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoPDF

**

codecov

Introduction

Providing tooling to work with PDF documents, usually in the form of an API.

Specification

  • HTTP Protocols
  • Integration Test
  • Echo Framework

Features

  • show PDF description detail
  • split PDF
  • trim PDF
  • remove PDF
  • merge PDF (combine multiple PDF)
  • convert JPG to PDF
  • compress PDF
  • reorder PDF pages
  • lock PDF

How to Use

Command

  • to run the API use go run cmd/api/*.go or make api
  • to test run go test -v ./... or make test
  • to see test coverage, run test makec and go tool cover -html=coverage.out

Example Request

  1. Get PDF file info

This example request shows information about the pdf file

http://localhost:1323/api/v1/pdf/info?path=/storage/testPdf&name=camry_ebrochure.pdf
  1. Split PDF

This example request generates single or multiples splitted pdf files based on selected_pages field input

curl -X POST http://localhost:1323/api/v1/pdf/split \
-H 'Content-Type: application/json' \
-d '{
    "name": "yle-flyers-sample.pdf",
    "path": "/storage/testPdf",
    "selected_pages": ["3-29","1-2","32-36"]
}'
  1. Trim PDF

This example request generates a single pdf file that contains all of the targeted files.

curl -X POST http://localhost:1323/api/v1/pdf/trim \
-H 'Content-Type: application/json' \
-d '{
    "inname": "yle-flyers-sample.pdf",
    "inpath": "/storage/testPdf",
    "outname": "yle-flyers-sample_trimmed.pdf",
    "outpath": "/storage/testPdf",
    "target_pages": ["1-3","8-9"]
}'
  1. Remove PDF

This example request generates a new copy of the pdf with the removed pages listed on 'target_pages' field

curl -X POST http://localhost:1323/api/v1/pdf/remove \
-H 'Content-Type: application/json' \
-d '{
    "inname": "yle-flyers-sample.pdf",
    "inpath": "/storage/testPdf",
    "outname": "yle-flyers-sample_removed.pdf",
    "outpath": "/storage/testPdf",
    "target_pages": ["1-3","5","8-9"]
}'
  1. Merge PDFs

This example request merges two or more pdf files

curl -X POST http://localhost:1323/api/v1/pdf/merge \
-H 'Content-Type: application/json' \
-d '{
  "infiles": [
    {
      "name": "camry_ebrochure.pdf",
      "path": "/storage/testPdf"
    },
    {
      "name": "mirai_ebrochure.pdf",
      "path": "/storage/testPdf"
    }
  ],
  "outfile": "camry_mirai_ebrochure.pdf"
}'

  1. Convert JPG to PDF

This example request creates a single pdf file from single or multiple image(s)

curl -X POST http://localhost:1323/api/v1/pdf/jpg-to-pdf \
-H 'Content-Type: application/json' \
-d '{
  "infiles": [
    {
      "name": "dhiva-krishna-YApS6TjKJ9c-unsplash.jpg",
      "path": "/storage/testImage"
    },
    {
      "name": "dima-panyukov-DwxlhTvC16Q-unsplash.jpg",
      "path": "/storage/testImage"
    },
    {
      "name": "kenny-eliason-FcyipqujfGg-unsplash.jpg",
      "path": "/storage/testImage"
    }
  ],
  "outfile": "jpg-to-pdf-output.pdf",
  "outpath": "/storage/testImage",
  "configs": {
    "page_size": "A4",
    "scale": 0.95
  }
}'

  1. Compress PDF

This example request generates a new compressed pdf file from the original pdf

curl -X POST http://localhost:1323/api/v1/pdf/compress \
-H 'Content-Type: application/json' \
-d '{
    "infile": "camry_ebrochure.pdf",
    "inpath": "/storage/testPdf",
    "outfile": "camry_ebrochure_compressed.pdf",
    "outpath": "/storage/testPdf"
}'
  1. Reorder PDF pages*

This request example generates new pdf file containing pages that have been sorted based on new_page_order field input.

curl -X POST http://localhost:1323/api/v1/pdf/reorder \
-H 'Content-Type: application/json' \
-d '{
    "inname": "yle-flyers-sample.pdf",
    "inpath": "/storage/testPdf",
    "outname": "yle-flyers-sample_reordered.pdf",
    "outpath": "/storage/testPdf",
    "new_page_order": ["3-31","1-2","32-36"]
}'

issue: pdfcpu/pdfcpu#687

Credits

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published