├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── go.mod ├── go.sum ├── img └── sample │ ├── image-00000.jpg │ ├── image-00001.jpg │ ├── image-00002.jpg │ ├── image-00003.jpg │ ├── image-00004.jpg │ ├── image-00005.jpg │ ├── image-00006.jpg │ └── image-00007.jpg ├── main.go └── pdf └── sample.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.log 3 | *.exe 4 | *.exe~ 5 | *.dll 6 | *.so 7 | *.dylib 8 | 9 | # Test binary, built with `go test -c` 10 | *.test 11 | 12 | # Output of the go coverage tool, specifically when used with LiteIDE 13 | *.out 14 | 15 | # Dependency directories (remove the comment below to include it) 16 | # vendor/ 17 | storage/ 18 | vendor/ 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | language: go 3 | 4 | go: 5 | - "1.16" 6 | 7 | os: 8 | - linux 9 | 10 | dist: trusty 11 | sudo: false 12 | install: true 13 | 14 | script: 15 | - unset GOPATH 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 MindInventory 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PDF to Image Converter Using Golang 2 | 3 | 4 | 5 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/mindinventory/Golang-PDF-to-Image-Converter/blob/master/LICENSE) 6 | 7 | This project is meant to be an **support** for implementation of **PDF-to-IMAGES** conversion without any quality compromising. Our goal for the viewer is to understand the core principles that go behind the development of such a complex conversion model and the nuances of training the individual processes for conversion with same quality. Once the core principles are understood, the various parts of the conversion process can be available at any time for usage in any project. 8 | 9 | 10 | ## Contents 11 | - [Contents](#contents) 12 | - [Overview](#overview) 13 | - [Quickstart](#quickstart) 14 | - [PDF Sample](#pdf-sample) 15 | - [Converted Image Sample](#converted-image-sample) 16 | - [LICENSE](#license) 17 | - [Let us know](#let-us-know) 18 | 19 | ## Overview 20 | 21 | Those who have done conversions from PDF to IMAGES, this repo will be very beneficial for them, because it has no quality compromising and we can increase/decrease the quality as per our requirement: 22 | 23 | 1. You have a PDF file as an input which you want to convert in IMAGES. 24 | 2. Add your PDF file in **pdf** folder. 25 | 3. As soon as the conversion program runs the images will generate in **img** folder inside the folder having name same as PDF file name. 26 | 4. Whatever the number of pages in PDF file same number of images will generate inside the **img/{PDF_NAME}** folder. 27 | 28 | Now let us elaborate the Basic setup steps. 29 | 30 | ## Quickstart 31 | 32 | For those who just want to see converted images, follow the overview steps and run the following code (make sure you have installed the stable **go** in your system): 33 | 34 | ```bash 35 | go mod tidy 36 | go run main.go 37 | ``` 38 | 39 | ## PDF Sample 40 | pdf-input 41 | 42 | 43 |

This browser does not support PDFs. Please download the PDF to view it: Download PDF.

44 | 45 |
46 | 47 | ## Converted Image Sample 48 | img-output 49 | 50 | 51 |

Get the image output click here.

52 | 53 |
54 | 55 | ## LICENSE 56 | 57 | Golang HTML to PDF Converter is [MIT-licensed](https://github.com/mindinventory/golang-pdf-to-Image-converter/blob/main/LICENSE) 58 | 59 | ## Let us know 60 | We’d be really happy if you sent us links to your projects where you use our component. Just email to sales@mindinventory.com and do let us know if you have any questions or suggestion regarding our work. 61 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module pdfToImgProject 2 | 3 | go 1.22 4 | 5 | require github.com/gen2brain/go-fitz v1.23.7 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/gen2brain/go-fitz v1.23.7 h1:HPhzEVzmOINvCKqQgB/DwMzYh4ArIgy3tMwq1eJTcbg= 2 | github.com/gen2brain/go-fitz v1.23.7/go.mod h1:HU04vc+RisUh/kvEd2pB0LAxmK1oyXdN4ftyshUr9rQ= 3 | -------------------------------------------------------------------------------- /img/sample/image-00000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mindinventory/Golang-PDF-to-Image-Converter/ffbd7d974d982c786301a89693014a47dbc16576/img/sample/image-00000.jpg -------------------------------------------------------------------------------- /img/sample/image-00001.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mindinventory/Golang-PDF-to-Image-Converter/ffbd7d974d982c786301a89693014a47dbc16576/img/sample/image-00001.jpg -------------------------------------------------------------------------------- /img/sample/image-00002.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mindinventory/Golang-PDF-to-Image-Converter/ffbd7d974d982c786301a89693014a47dbc16576/img/sample/image-00002.jpg -------------------------------------------------------------------------------- /img/sample/image-00003.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mindinventory/Golang-PDF-to-Image-Converter/ffbd7d974d982c786301a89693014a47dbc16576/img/sample/image-00003.jpg -------------------------------------------------------------------------------- /img/sample/image-00004.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mindinventory/Golang-PDF-to-Image-Converter/ffbd7d974d982c786301a89693014a47dbc16576/img/sample/image-00004.jpg -------------------------------------------------------------------------------- /img/sample/image-00005.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mindinventory/Golang-PDF-to-Image-Converter/ffbd7d974d982c786301a89693014a47dbc16576/img/sample/image-00005.jpg -------------------------------------------------------------------------------- /img/sample/image-00006.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mindinventory/Golang-PDF-to-Image-Converter/ffbd7d974d982c786301a89693014a47dbc16576/img/sample/image-00006.jpg -------------------------------------------------------------------------------- /img/sample/image-00007.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mindinventory/Golang-PDF-to-Image-Converter/ffbd7d974d982c786301a89693014a47dbc16576/img/sample/image-00007.jpg -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "image/jpeg" 6 | "os" 7 | "path" 8 | "path/filepath" 9 | "strings" 10 | 11 | "github.com/gen2brain/go-fitz" 12 | ) 13 | 14 | func main() { 15 | 16 | var files []string 17 | 18 | root := "pdf/" 19 | err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { 20 | if filepath.Ext(path) == ".pdf" { 21 | files = append(files, path) 22 | } 23 | return nil 24 | }) 25 | if err != nil { 26 | panic(err) 27 | } 28 | for _, file := range files { 29 | doc, err := fitz.New(file) 30 | if err != nil { 31 | panic(err) 32 | } 33 | folder := strings.TrimSuffix(path.Base(file), filepath.Ext(path.Base(file))) 34 | 35 | // Extract pages as images 36 | for n := 0; n < doc.NumPage(); n++ { 37 | img, err := doc.Image(n) 38 | if err != nil { 39 | panic(err) 40 | } 41 | err = os.MkdirAll("img/"+folder, 0755) 42 | if err != nil { 43 | panic(err) 44 | } 45 | 46 | f, err := os.Create(filepath.Join("img/"+folder+"/", fmt.Sprintf("image-%05d.jpg", n))) 47 | if err != nil { 48 | panic(err) 49 | } 50 | 51 | err = jpeg.Encode(f, img, &jpeg.Options{Quality: jpeg.DefaultQuality}) 52 | if err != nil { 53 | panic(err) 54 | } 55 | 56 | f.Close() 57 | 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /pdf/sample.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mindinventory/Golang-PDF-to-Image-Converter/ffbd7d974d982c786301a89693014a47dbc16576/pdf/sample.pdf --------------------------------------------------------------------------------