🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

github.com/enxservices/pdf

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/enxservices/pdf

v0.0.1
Source
Go
Version published
Created
Source

PDF Reader

A simple Go library which enables reading PDF files.

This repository contains merged code from https://github.com/rsc/pdf and https://github.com/ledongthuc/pdf and https://github.com/dslipak/pdf.
Added bugfixs and stabilize error handling.

Features

  • Get plain text content with and without font and formatting information.

TODO

Install:

go get -u github.com/mazeforgit/pdf

Read plain text

package main

import (
	"bytes"
	"fmt"
	"os"
	"strconv"

	"github.com/mazeforgit/pdf"
)

func main() {

	testFile := "./testdata/story_Word2019-2312-1712620132_SaveAs-Standard-PDFA__pdf17_trailer.pdf"
	
	// open file
	fmt.Println(". open testFile = " + testFile)
	f, err := Open(testFile)
	if err != nil {
		os.Exit(-1)
	}
	
	totalPage := f.NumPage()
	fmt.Println(". totalPage = " + strconv.Itoa(totalPage))
	
	for pageIndex := 1; pageIndex <= totalPage; pageIndex++ {
		fmt.Println(". pageIndex = "  + strconv.Itoa(pageIndex))
		var buf bytes.Buffer

		p := f.Page(pageIndex)
		if p.V.IsNull() {
			continue
		}
		
		texts := p.Content().Text
		var lastY = 0.0
		line := ""

		for _, text := range texts {
			if lastY != text.Y {
				if lastY > 0 {
					buf.WriteString(line + "\n")
					line = text.S
				} else {
					line += text.S
				}
			} else {
				line += text.S
			}

			lastY = text.Y
		}
		
		// page content
		fmt.Println(buf.String())
		fmt.Println(". buf.Len() = " + strconv.Itoa(buf.Len()))
	}
	
	// version
	fmt.Println(". version = " + f.Version())
	
	// verdicts
	verdicts = f.Verdicts()
	fmt.Println(". verdicts = " + strconv.Itoa(len(verdicts)))
	for i:=0; i< len(verdicts); i++ {
		fmt.Println(verdicts[i])
	}

	// close file
	f.Close()
}

FAQs

Package last updated on 09 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts