Change error log messages to debug

This commit is contained in:
Gunnsteinn Hall 2016-10-31 21:48:25 +00:00
parent be156811fa
commit 42bd1bbded
13 changed files with 113 additions and 97 deletions

View File

@ -57,7 +57,7 @@ func (this *PdfParser) lookupObjectViaOS(sobjNumber int, objNum int) (PdfObject,
if !cached {
soi, err := this.LookupByNumber(sobjNumber)
if err != nil {
common.Log.Error("Missing object stream with number %d", sobjNumber)
common.Log.Debug("Missing object stream with number %d", sobjNumber)
return nil, err
}
@ -74,11 +74,11 @@ func (this *PdfParser) lookupObjectViaOS(sobjNumber int, objNum int) (PdfObject,
common.Log.Debug("so d: %s\n", *sod)
name, ok := (*sod)["Type"].(*PdfObjectName)
if !ok {
common.Log.Error("ERROR: Object stream should always have a Type")
common.Log.Debug("ERROR: Object stream should always have a Type")
return nil, errors.New("Object stream missing Type")
}
if strings.ToLower(string(*name)) != "objstm" {
common.Log.Error("ERROR: Object stream type shall always be ObjStm !")
common.Log.Debug("ERROR: Object stream type shall always be ObjStm !")
return nil, errors.New("Object stream type != ObjStm")
}
@ -162,7 +162,7 @@ func (this *PdfParser) lookupObjectViaOS(sobjNumber int, objNum int) (PdfObject,
val, err := this.parseObject()
if err != nil {
common.Log.Error("Fail to read object (%s)", err)
common.Log.Debug("ERROR Fail to read object (%s)", err)
return nil, err
}
if val == nil {
@ -245,13 +245,13 @@ func (this *PdfParser) lookupByNumber(objNumber int, attemptRepairs bool) (PdfOb
obj, err := this.parseIndirectObject()
if err != nil {
common.Log.Error("Failed reading xref (%s)", err)
common.Log.Debug("ERROR Failed reading xref (%s)", err)
// Offset pointing to a non-object. Try to repair the file.
if attemptRepairs {
common.Log.Error("Attempting to repair xrefs (top down)")
common.Log.Debug("Attempting to repair xrefs (top down)")
xrefTable, err := this.repairRebuildXrefsTopDown()
if err != nil {
common.Log.Error("Failed repair (%s)", err)
common.Log.Debug("ERROR Failed repair (%s)", err)
return nil, false, err
}
this.xrefs = *xrefTable
@ -287,14 +287,14 @@ func (this *PdfParser) lookupByNumber(objNumber int, attemptRepairs bool) (PdfOb
common.Log.Debug("Object stream available in object %d/%d", xref.osObjNumber, xref.osObjIndex)
if xref.osObjNumber == objNumber {
common.Log.Error("Circular reference!?!")
common.Log.Debug("ERROR Circular reference!?!")
return nil, true, errors.New("Xref circular reference")
}
_, exists := this.xrefs[xref.osObjNumber]
if exists {
optr, err := this.lookupObjectViaOS(xref.osObjNumber, objNumber) //xref.osObjIndex)
if err != nil {
common.Log.Error("Returning ERR (%s)", err)
common.Log.Debug("ERROR Returning ERR (%s)", err)
return nil, true, err
}
common.Log.Debug("<Loaded via OS")

View File

@ -81,7 +81,7 @@ func (this *PdfCrypt) LoadCryptFilters(ed *PdfObjectDictionary) error {
}
if name == "Identity" {
common.Log.Error("Cannot overwrite the identity filter")
common.Log.Debug("ERROR - Cannot overwrite the identity filter - Trying next")
continue
}
@ -163,11 +163,11 @@ func PdfCryptMakeNew(ed, trailer *PdfObjectDictionary) (PdfCrypt, error) {
filter, ok := (*ed)["Filter"].(*PdfObjectName)
if !ok {
common.Log.Error("Crypt dictionary missing required Filter field!")
common.Log.Debug("ERROR Crypt dictionary missing required Filter field!")
return crypter, errors.New("Required crypt field Filter missing")
}
if *filter != "Standard" {
common.Log.Error("Unsupported filter (%s)", *filter)
common.Log.Debug("ERROR Unsupported filter (%s)", *filter)
return crypter, errors.New("Unsupported Filter")
}
crypter.Filter = string(*filter)
@ -180,7 +180,7 @@ func PdfCryptMakeNew(ed, trailer *PdfObjectDictionary) (PdfCrypt, error) {
if L, ok := (*ed)["Length"].(*PdfObjectInteger); ok {
if (*L % 8) != 0 {
common.Log.Error("Invalid encryption length")
common.Log.Debug("ERROR Invalid encryption length")
return crypter, errors.New("Invalid encryption length")
}
crypter.length = int(*L)
@ -201,7 +201,7 @@ func PdfCryptMakeNew(ed, trailer *PdfObjectDictionary) (PdfCrypt, error) {
return crypter, err
}
} else {
common.Log.Error("Unsupported encryption algo V = %d", *V)
common.Log.Debug("ERROR Unsupported encryption algo V = %d", *V)
return crypter, errors.New("Unsupported algorithm")
}
} else {
@ -384,7 +384,7 @@ func (this *PdfCrypt) paddedPass(pass []byte) []byte {
func (this *PdfCrypt) makeKey(filter string, objNum, genNum uint32, ekey []byte) ([]byte, error) {
cf, ok := this.cryptFilters[filter]
if !ok {
common.Log.Error("Unsupported crypt filter (%s)", filter)
common.Log.Debug("ERROR Unsupported crypt filter (%s)", filter)
return nil, fmt.Errorf("Unsupported crypt filter (%s)", filter)
}
isAES := false
@ -443,7 +443,7 @@ func (this *PdfCrypt) decryptBytes(buf []byte, filter string, okey []byte) ([]by
common.Log.Debug("Decrypt bytes")
cf, ok := this.cryptFilters[filter]
if !ok {
common.Log.Error("Unsupported crypt filter (%s)", filter)
common.Log.Debug("ERROR Unsupported crypt filter (%s)", filter)
return nil, fmt.Errorf("Unsupported crypt filter (%s)", filter)
}
@ -483,7 +483,7 @@ func (this *PdfCrypt) decryptBytes(buf []byte, filter string, okey []byte) ([]by
// vector is a 16-byte random number that is stored as the first
// 16 bytes of the encrypted stream or string.
if len(buf) < 16 {
common.Log.Error("AES invalid buf %s", buf)
common.Log.Debug("ERROR AES invalid buf %s", buf)
return buf, fmt.Errorf("AES: Buf len < 16 (%d)", len(buf))
}
iv := buf[:16]
@ -690,7 +690,7 @@ func (this *PdfCrypt) encryptBytes(buf []byte, filter string, okey []byte) ([]by
common.Log.Debug("Encrypt bytes")
cf, ok := this.cryptFilters[filter]
if !ok {
common.Log.Error("Unsupported crypt filter (%s)", filter)
common.Log.Debug("ERROR Unsupported crypt filter (%s)", filter)
return nil, fmt.Errorf("Unsupported crypt filter (%s)", filter)
}

17
pdf/font.go Normal file
View File

@ -0,0 +1,17 @@
/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.txt', which is part of this source code package.
*/
//
// Font resources for PDF file creation and manipulations.
//
package pdf
import ()
func loadFont(fontName string) {
// Open the font file.
// Load the widths, other content?
}

View File

@ -40,7 +40,7 @@ func (this DefaultImageHandler) Read(reader io.Reader) (*Image, error) {
// Load the image with the native implementation.
img, _, err := image.Decode(reader)
if err != nil {
common.Log.Error("Error decoding file: %s", err)
common.Log.Debug("Error decoding file: %s", err)
return nil, err
}

View File

@ -20,7 +20,7 @@ func (this *PdfParser) ReadAtLeast(p []byte, n int) (int, error) {
for remaining > 0 {
nRead, err := this.reader.Read(p[start:])
if err != nil {
common.Log.Error("Failed reading (%d;%d) %s", nRead, numRounds, err.Error())
common.Log.Debug("ERROR Failed reading (%d;%d) %s", nRead, numRounds, err.Error())
return start, errors.New("Failed reading")
}
numRounds++

View File

@ -70,7 +70,7 @@ func newPdfOutlineFromDict(dict *PdfObjectDictionary) (*PdfOutline, error) {
typeVal, ok := obj.(*PdfObjectName)
if ok {
if *typeVal != "Outlines" {
common.Log.Error("Type != Outlines (%s)", *typeVal)
common.Log.Debug("ERROR Type != Outlines (%s)", *typeVal)
// Should be "Outlines" if there, but some files have other types
// Log as an error but do not quit.
// Might be a good idea to log this kind of deviation from the standard separately.
@ -172,7 +172,7 @@ func (n *PdfOutlineTreeNode) getOuter() PdfObjectConverter {
return outlineItem
}
common.Log.Error("Invalid outline tree node item") // Should never happen.
common.Log.Debug("ERROR Invalid outline tree node item") // Should never happen.
return nil
}

View File

@ -178,7 +178,7 @@ func (this *PdfObjectName) DefaultWriteString() string {
var output bytes.Buffer
if len(*this) > 127 {
common.Log.Error("Name too long (%s)", *this)
common.Log.Debug("ERROR: Name too long (%s)", *this)
}
output.WriteString("/")

View File

@ -98,7 +98,7 @@ func (this *PdfParser) skipComments() error {
for {
bb, err := this.reader.Peek(1)
if err != nil {
common.Log.Error("Error %s", err.Error())
common.Log.Debug("Error %s", err.Error())
return err
}
if isFirst && bb[0] != '%' {
@ -131,7 +131,7 @@ func (this *PdfParser) readComment() (string, error) {
for {
bb, err := this.reader.Peek(1)
if err != nil {
common.Log.Error("Error %s", err.Error())
common.Log.Debug("Error %s", err.Error())
return commentText, err
}
if isFirst && bb[0] != '%' {
@ -155,7 +155,7 @@ func (this *PdfParser) readTextLine() (string, error) {
for {
bb, err := this.reader.Peek(1)
if err != nil {
common.Log.Error("Error %s", err.Error())
common.Log.Debug("Error %s", err.Error())
return lineStr, err
}
if (bb[0] != '\r') && (bb[0] != '\n') {
@ -190,7 +190,7 @@ func (this *PdfParser) parseName() (PdfObjectName, error) {
this.readComment()
this.skipSpaces()
} else {
common.Log.Error("Name starting with %s (% x)", bb, bb)
common.Log.Debug("ERROR Name starting with %s (% x)", bb, bb)
return PdfObjectName(name), fmt.Errorf("Invalid name: (%c)", bb[0])
}
} else {
@ -253,7 +253,7 @@ func (this *PdfParser) parseNumber() (PdfObject, error) {
break // Handle like EOF
}
if err != nil {
common.Log.Error("ERROR %s", err)
common.Log.Debug("ERROR %s", err)
return nil, err
}
if allowSigns && (bb[0] == '-' || bb[0] == '+') {
@ -466,7 +466,7 @@ func parseReference(refStr string) (PdfObjectReference, error) {
result := reReference.FindStringSubmatch(string(refStr))
if len(result) < 3 {
common.Log.Error("Error parsing reference")
common.Log.Debug("Error parsing reference")
return objref, errors.New("Unable to parse reference")
}
@ -565,7 +565,7 @@ func (this *PdfParser) parseObject() (PdfObject, error) {
return num, err
}
common.Log.Error("ERROR Unknown (peek \"%s\")", peekStr)
common.Log.Debug("ERROR Unknown (peek \"%s\")", peekStr)
return nil, errors.New("Object parsing error - unexpected pattern")
}
}
@ -610,7 +610,7 @@ func (this *PdfParser) parseDict() (*PdfObjectDictionary, error) {
keyName, err := this.parseName()
common.Log.Debug("Key: %s", keyName)
if err != nil {
common.Log.Error("Returning name err %s", err)
common.Log.Debug("ERROR Returning name err %s", err)
return nil, err
}
@ -652,7 +652,7 @@ func (this *PdfParser) parsePdfVersion() (float64, error) {
result1 := rePdfVersion.FindStringSubmatch(string(b))
if len(result1) < 2 {
common.Log.Error("Error: PDF Version not found!")
common.Log.Debug("Error: PDF Version not found!")
return -1, errors.New("PDF version not found")
}
@ -706,7 +706,7 @@ func (this *PdfParser) parseXrefTable() (*PdfObjectDictionary, error) {
result2 := reXrefEntry.FindStringSubmatch(txt)
if len(result2) == 4 {
if insideSubsection == false {
common.Log.Error("Xref invalid format!\n")
common.Log.Debug("ERROR Xref invalid format!\n")
return nil, errors.New("Xref invalid format")
}
@ -755,14 +755,14 @@ func (this *PdfParser) parseXrefTable() (*PdfObjectDictionary, error) {
trailer, err = this.parseDict()
common.Log.Debug("EOF reading trailer dict!")
if err != nil {
common.Log.Error("Error parsing trailer dict (%s)", err)
common.Log.Debug("Error parsing trailer dict (%s)", err)
return nil, err
}
break
}
if txt == "%%EOF" {
common.Log.Error("end of file - trailer not found - error!")
common.Log.Debug("ERROR: end of file - trailer not found - error!")
return nil, errors.New("End of file - trailer not found!")
}
@ -784,14 +784,14 @@ func (this *PdfParser) parseXrefStream(xstm *PdfObjectInteger) (*PdfObjectDictio
xrefObj, err := this.parseIndirectObject()
if err != nil {
common.Log.Error("Failed to read xref object")
common.Log.Debug("ERROR: Failed to read xref object")
return nil, errors.New("Failed to read xref object")
}
common.Log.Debug("XRefStm object: %s", xrefObj)
xs, ok := xrefObj.(*PdfObjectStream)
if !ok {
common.Log.Error("Error, XRefStm pointing to non-stream object!")
common.Log.Debug("ERROR: XRefStm pointing to non-stream object!")
return nil, errors.New("XRefStm pointing to a non-stream object!")
}
@ -799,7 +799,7 @@ func (this *PdfParser) parseXrefStream(xstm *PdfObjectInteger) (*PdfObjectDictio
sizeObj, ok := (*(xs.PdfObjectDictionary))["Size"].(*PdfObjectInteger)
if !ok {
common.Log.Error("Missing size from xref stm")
common.Log.Debug("ERROR: Missing size from xref stm")
return nil, errors.New("Missing Size from xref stm")
}
@ -811,7 +811,7 @@ func (this *PdfParser) parseXrefStream(xstm *PdfObjectInteger) (*PdfObjectDictio
wLen := len(*wArr)
if wLen != 3 {
common.Log.Error("Unsupported xref stm (len(W) != 3 - %d)", wLen)
common.Log.Debug("ERROR: Unsupported xref stm (len(W) != 3 - %d)", wLen)
return nil, errors.New("Unsupported xref stm len(W) != 3")
}
@ -831,7 +831,7 @@ func (this *PdfParser) parseXrefStream(xstm *PdfObjectInteger) (*PdfObjectDictio
ds, err := this.decodeStream(xs)
if err != nil {
common.Log.Error("Unable to decode stream")
common.Log.Debug("ERROR: Unable to decode stream")
return nil, err
}
@ -898,7 +898,7 @@ func (this *PdfParser) parseXrefStream(xstm *PdfObjectInteger) (*PdfObjectDictio
if entries != len(indexList) {
// If mismatch -> error (already allowing mismatch of 1 if Index not specified).
common.Log.Error("xref stm: num entries != len(indices) (%d != %d)", entries, len(indexList))
common.Log.Debug("ERROR: xref stm: num entries != len(indices) (%d != %d)", entries, len(indexList))
return nil, errors.New("Xref stm num entries != len(indices)")
}
@ -962,8 +962,7 @@ func (this *PdfParser) parseXrefStream(xstm *PdfObjectInteger) (*PdfObjectDictio
common.Log.Debug("entry: %s", this.xrefs[objNum])
}
} else {
common.Log.Error("--------INVALID TYPE XrefStm invalid?-------")
common.Log.Error("DEBUG - continuing")
common.Log.Debug("ERROR: --------INVALID TYPE XrefStm invalid?-------")
// Continue, we do not define anything -> null object.
// 7.5.8.3:
//
@ -1001,7 +1000,7 @@ func (this *PdfParser) parseXref() (*PdfObjectDictionary, error) {
return nil, err
}
} else {
common.Log.Error("Invalid xref.... starting with \"%s\"", string(bb))
common.Log.Debug("ERROR: Invalid xref.... starting with \"%s\"", string(bb))
return nil, errors.New("Invalid xref format")
}
@ -1052,7 +1051,7 @@ func (this *PdfParser) loadXrefs() (*PdfObjectDictionary, error) {
common.Log.Debug("Looking for EOF marker: \"%s\"", string(b1))
ind := reEOF.FindAllStringIndex(string(b1), -1)
if ind == nil {
common.Log.Error("Error: EOF marker not found!")
common.Log.Debug("Error: EOF marker not found!")
return nil, errors.New("EOF marker not found")
}
lastInd := ind[len(ind)-1]
@ -1067,23 +1066,23 @@ func (this *PdfParser) loadXrefs() (*PdfObjectDictionary, error) {
result := reStartXref.FindStringSubmatch(string(b2))
if len(result) < 2 {
common.Log.Error("Error: startxref not found!")
common.Log.Debug("Error: startxref not found!")
return nil, errors.New("Startxref not found")
}
if len(result) > 2 {
// GH: Take the last one? Make a test case.
common.Log.Error("Multiple startxref (%s)!", b2)
common.Log.Debug("ERROR: Multiple startxref (%s)!", b2)
return nil, errors.New("Multiple startxref entries?")
}
offsetXref, _ := strconv.ParseInt(result[1], 10, 64)
common.Log.Debug("startxref at %d", offsetXref)
if offsetXref > fSize {
common.Log.Error("Xref offset outside of file")
common.Log.Error("Attempting repair")
common.Log.Debug("ERROR: Xref offset outside of file")
common.Log.Debug("Attempting repair")
offsetXref, err = this.repairLocateXref()
if err != nil {
common.Log.Error("Repair attempt failed (%s)")
common.Log.Debug("ERROR: Repair attempt failed (%s)")
return nil, err
}
}
@ -1133,7 +1132,7 @@ func (this *PdfParser) loadXrefs() (*PdfObjectDictionary, error) {
ptrailerDict, err := this.parseXref()
if err != nil {
common.Log.Error("Failed loading another (Prev) trailer")
common.Log.Debug("ERROR: Failed loading another (Prev) trailer")
return nil, err
}
@ -1142,7 +1141,7 @@ func (this *PdfParser) loadXrefs() (*PdfObjectDictionary, error) {
prevoff := *(xx.(*PdfObjectInteger))
if intInSlice(int64(prevoff), prevList) {
// Prevent circular reference!
common.Log.Error("Preventing circular xref referencing")
common.Log.Debug("Preventing circular xref referencing")
break
}
prevList = append(prevList, int64(prevoff))
@ -1160,14 +1159,14 @@ func (this *PdfParser) parseIndirectObject() (PdfObject, error) {
common.Log.Debug("-Read indirect obj")
bb, err := this.reader.Peek(20)
if err != nil {
common.Log.Error("Fail to read indirect obj")
common.Log.Debug("ERROR: Fail to read indirect obj")
return &indirect, err
}
common.Log.Debug("(indirect obj peek \"%s\"", string(bb))
indices := reIndirectObject.FindStringSubmatchIndex(string(bb))
if len(indices) < 6 {
common.Log.Error("Unable to find object signature (%s)", string(bb))
common.Log.Debug("ERROR: Unable to find object signature (%s)", string(bb))
return &indirect, errors.New("Unable to detect indirect object signature")
}
this.reader.Discard(indices[0]) // Take care of any small offset.
@ -1178,14 +1177,14 @@ func (this *PdfParser) parseIndirectObject() (PdfObject, error) {
hb := make([]byte, hlen)
_, err = this.ReadAtLeast(hb, hlen)
if err != nil {
common.Log.Error("unable to read - %s", err)
common.Log.Debug("ERROR: unable to read - %s", err)
return nil, err
}
common.Log.Debug("textline: %s", hb)
result := reIndirectObject.FindStringSubmatch(string(hb))
if len(result) < 3 {
common.Log.Error("Unable to find object signature (%s)", string(hb))
common.Log.Debug("ERROR: Unable to find object signature (%s)", string(hb))
return &indirect, errors.New("Unable to detect indirect object signature")
}
@ -1298,7 +1297,7 @@ func NewParser(rs io.ReadSeeker) (*PdfParser, error) {
// Start by reading xrefs from bottom
trailer, err := parser.loadXrefs()
if err != nil {
common.Log.Error("Failed to load xref table! %s", err)
common.Log.Debug("ERROR: Failed to load xref table! %s", err)
// Try to rebuild entire xref table?
return nil, err
}

View File

@ -61,7 +61,7 @@ func (this *PdfParser) decodeStream(obj *PdfObjectStream) ([]byte, error) {
if hasbits {
pbits, ok := obits.(*PdfObjectInteger)
if !ok {
common.Log.Error("Invalid BitsPerComponent")
common.Log.Debug("ERROR: Invalid BitsPerComponent")
return nil, fmt.Errorf("Invalid BitsPerComponent")
}
if *pbits != 8 {
@ -92,7 +92,7 @@ func (this *PdfParser) decodeStream(obj *PdfObjectStream) ([]byte, error) {
columns, ok := (*decodeParams)["Columns"].(*PdfObjectInteger)
if !ok {
common.Log.Error("Predictor Column missing\n")
common.Log.Debug("ERROR: Predictor Column missing\n")
return nil, fmt.Errorf("Predictor column missing")
}
@ -107,7 +107,7 @@ func (this *PdfParser) decodeStream(obj *PdfObjectStream) ([]byte, error) {
rowLength := int(*columns) * colors
rows := len(outData) / rowLength
if len(outData)%rowLength != 0 {
common.Log.Error("TIFF encoding: Invalid row length...")
common.Log.Debug("ERROR: TIFF encoding: Invalid row length...")
return nil, fmt.Errorf("Invalid row length (%d/%d)", len(outData), rowLength)
}
@ -139,13 +139,13 @@ func (this *PdfParser) decodeStream(obj *PdfObjectStream) ([]byte, error) {
common.Log.Debug("PNG Encoding")
columns, ok := (*decodeParams)["Columns"].(*PdfObjectInteger)
if !ok {
common.Log.Error("Predictor Column missing\n")
common.Log.Debug("ERROR: Predictor Column missing\n")
return nil, fmt.Errorf("Predictor column missing")
}
rowLength := int(*columns + 1) // 1 byte to specify predictor algorithms per row.
rows := len(outData) / rowLength
if len(outData)%rowLength != 0 {
common.Log.Error("Invalid row length...")
common.Log.Debug("ERROR: Invalid row length...")
return nil, fmt.Errorf("Invalid row length (%d/%d)", len(outData), rowLength)
}
@ -176,7 +176,7 @@ func (this *PdfParser) decodeStream(obj *PdfObjectStream) ([]byte, error) {
rowData[j] = byte(int(rowData[j]+prevRowData[j]) % 256)
}
default:
common.Log.Error("Invalid filter byte (%d)", fb)
common.Log.Debug("ERROR: Invalid filter byte (%d)", fb)
return nil, fmt.Errorf("Invalid filter byte (%d)", fb)
}
@ -188,7 +188,7 @@ func (this *PdfParser) decodeStream(obj *PdfObjectStream) ([]byte, error) {
pOutData := pOutBuffer.Bytes()
return pOutData, nil
} else {
common.Log.Error("Unsupported predictor (%d)", predictor)
common.Log.Debug("ERROR: Unsupported predictor (%d)", predictor)
return nil, fmt.Errorf("Unsupported predictor (%d)", predictor)
}
}
@ -211,7 +211,7 @@ func (this *PdfParser) decodeStream(obj *PdfObjectStream) ([]byte, error) {
if (b >= 'a' && b <= 'f') || (b >= 'A' && b <= 'F') || (b >= '0' && b <= '9') {
inb = append(inb, b)
} else {
common.Log.Error("Invalid ascii hex character (%c)", b)
common.Log.Debug("ERROR: Invalid ascii hex character (%c)", b)
return nil, fmt.Errorf("Invalid ascii hex character (%c)", b)
}
}
@ -227,6 +227,6 @@ func (this *PdfParser) decodeStream(obj *PdfObjectStream) ([]byte, error) {
return outb, nil
}
common.Log.Error("Unsupported encoding method!")
common.Log.Debug("ERROR: Unsupported encoding method!")
return nil, fmt.Errorf("Unsupported encoding method")
}

View File

@ -74,7 +74,7 @@ func (this *PdfReader) Decrypt(password []byte) (bool, error) {
err = this.loadStructure()
if err != nil {
common.Log.Error("Fail to load structure (%s)", err)
common.Log.Debug("ERROR: Fail to load structure (%s)", err)
return false, err
}
@ -94,17 +94,17 @@ func (this *PdfReader) loadStructure() error {
}
oc, err := this.parser.LookupByReference(*root)
if err != nil {
common.Log.Error("Failed to read root element catalog: %s", err)
common.Log.Debug("ERROR: Failed to read root element catalog: %s", err)
return err
}
pcatalog, ok := oc.(*PdfIndirectObject)
if !ok {
common.Log.Error("Missing catalog: (root %q) (trailer %s)", oc, *(this.parser.trailer))
common.Log.Debug("ERROR: Missing catalog: (root %q) (trailer %s)", oc, *(this.parser.trailer))
return errors.New("Missing catalog")
}
catalog, ok := (*pcatalog).PdfObject.(*PdfObjectDictionary)
if !ok {
common.Log.Error("Invalid catalog (%s)", pcatalog.PdfObject)
common.Log.Debug("ERROR: Invalid catalog (%s)", pcatalog.PdfObject)
return errors.New("Invalid catalog")
}
common.Log.Debug("Catalog: %s", catalog)
@ -116,23 +116,23 @@ func (this *PdfReader) loadStructure() error {
}
op, err := this.parser.LookupByReference(*pagesRef)
if err != nil {
common.Log.Error("Failed to read pages")
common.Log.Debug("ERROR: Failed to read pages")
return err
}
ppages, ok := op.(*PdfIndirectObject)
if !ok {
common.Log.Error("Pages object invalid")
common.Log.Error("op: %p", ppages)
common.Log.Debug("ERROR: Pages object invalid")
common.Log.Debug("op: %p", ppages)
return errors.New("Pages object invalid")
}
pages, ok := ppages.PdfObject.(*PdfObjectDictionary)
if !ok {
common.Log.Error("Pages object invalid (%s)", ppages)
common.Log.Debug("ERROR: Pages object invalid (%s)", ppages)
return errors.New("Pages object invalid")
}
pageCount, ok := (*pages)["Count"].(*PdfObjectInteger)
if !ok {
common.Log.Error("Pages count object invalid")
common.Log.Debug("ERROR: Pages count object invalid")
return errors.New("Pages count invalid")
}
@ -154,7 +154,7 @@ func (this *PdfReader) loadStructure() error {
// Outlines.
this.outlineTree, err = this.loadOutlines()
if err != nil {
common.Log.Error("Failed to build outline tree (%s)", err)
common.Log.Debug("ERROR: Failed to build outline tree (%s)", err)
return err
}
@ -216,7 +216,7 @@ func (this *PdfReader) loadOutlines() (*PdfOutlineTreeNode, error) {
// Trace references to the object.
outlineRootObj, err := this.traceToObject(outlinesObj)
if err != nil {
common.Log.Error("Failed to read outlines")
common.Log.Debug("ERROR: Failed to read outlines")
return nil, err
}
common.Log.Debug("Outline root: %v", outlineRootObj)
@ -342,7 +342,7 @@ func (this *PdfReader) GetOutlinesFlattened() ([]*PdfOutlineTreeNode, []string,
return
}
if node.context == nil {
common.Log.Error("Missing node.context") // Should not happen ever.
common.Log.Debug("ERROR: Missing node.context") // Should not happen ever.
return
}
@ -382,7 +382,7 @@ func (this *PdfReader) GetForms() (*PdfObjectDictionary, error) {
common.Log.Debug("Has Acro forms - Indirect object")
formsObj, err := this.parser.LookupByReference(*formsRef)
if err != nil {
common.Log.Error("Failed to read forms")
common.Log.Debug("ERROR: Failed to read forms")
return nil, err
}
if iobj, ok := formsObj.(*PdfIndirectObject); ok {
@ -400,7 +400,7 @@ func (this *PdfReader) GetForms() (*PdfObjectDictionary, error) {
common.Log.Debug("Traverse the Acroforms structure")
err := this.traverseObjectData(formsDict)
if err != nil {
common.Log.Error("Unable to traverse AcroForms (%s)", err)
common.Log.Debug("ERROR: Unable to traverse AcroForms (%s)", err)
return nil, err
}
@ -447,7 +447,7 @@ func (this *PdfReader) buildPageList(node *PdfIndirectObject, parent *PdfIndirec
return nil
}
if *objType != "Pages" {
common.Log.Error("Table of content containing non Page/Pages object! (%s)", objType)
common.Log.Debug("ERROR: Table of content containing non Page/Pages object! (%s)", objType)
return errors.New("Table of content containing non Page/Pages object!")
}
@ -464,7 +464,7 @@ func (this *PdfReader) buildPageList(node *PdfIndirectObject, parent *PdfIndirec
kidsObj, err := this.parser.Trace((*nodeDict)["Kids"])
if err != nil {
common.Log.Error("Failed loading Kids object")
common.Log.Debug("ERROR: Failed loading Kids object")
return err
}
@ -484,7 +484,7 @@ func (this *PdfReader) buildPageList(node *PdfIndirectObject, parent *PdfIndirec
for idx, child := range *kids {
child, ok := child.(*PdfIndirectObject)
if !ok {
common.Log.Error("Page not indirect object - (%s)", child)
common.Log.Debug("ERROR: Page not indirect object - (%s)", child)
return errors.New("Page not indirect object")
}
(*kids)[idx] = child
@ -594,7 +594,7 @@ func (this *PdfReader) traverseObjectData(o PdfObject) error {
}
if _, isRef := o.(*PdfObjectReference); isRef {
common.Log.Error("Reader tracing a reference!")
common.Log.Debug("ERROR: Reader tracing a reference!")
return errors.New("Reader tracing a reference!")
}

View File

@ -33,7 +33,7 @@ func (this *PdfParser) repairLocateXref() (int64, error) {
results := repairReXrefTable.FindAllStringIndex(string(b2), -1)
if len(results) < 1 {
common.Log.Error("Repair: xref not found!")
common.Log.Debug("ERROR: Repair: xref not found!")
return 0, errors.New("Repair: xref not found")
}
@ -50,11 +50,11 @@ func (this *PdfParser) rebuildXrefTable() error {
for objNum, xref := range this.xrefs {
obj, _, err := this.lookupByNumberWrapper(objNum, false)
if err != nil {
common.Log.Error("Unable to look up object (%s)", err)
common.Log.Error("Xref table completely broken - attempting to repair ")
common.Log.Debug("ERROR: Unable to look up object (%s)", err)
common.Log.Debug("ERROR: Xref table completely broken - attempting to repair ")
xrefTable, err := this.repairRebuildXrefsTopDown()
if err != nil {
common.Log.Error("Failed xref rebuild repair (%s)", err)
common.Log.Debug("ERROR: Failed xref rebuild repair (%s)", err)
return err
}
this.xrefs = *xrefTable
@ -108,7 +108,7 @@ func (this *PdfParser) repairRebuildXrefsTopDown() (*XrefTable, error) {
if len(results) > 0 {
obj, err := this.parseIndirectObject()
if err != nil {
common.Log.Error("Unable to parse indirect object (%s)", err)
common.Log.Debug("ERROR: Unable to parse indirect object (%s)", err)
return nil, err
}

View File

@ -48,7 +48,7 @@ func (this *PdfParser) inspect() {
common.Log.Debug("Looking up object number: %d", xref.objectNumber)
o, err := this.LookupByNumber(xref.objectNumber)
if err != nil {
common.Log.Error("Fail to lookup obj %d (%s)", xref.objectNumber, err)
common.Log.Debug("ERROR: Fail to lookup obj %d (%s)", xref.objectNumber, err)
failedCount++
continue
}
@ -108,7 +108,7 @@ func (this *PdfParser) inspect() {
common.Log.Debug("=======")
if len(this.xrefs) < 1 {
common.Log.Error("This document is invalid (xref table missing!)")
common.Log.Debug("ERROR: This document is invalid (xref table missing!)")
return
}
fontObjs, ok := objTypes["Font"]

View File

@ -191,7 +191,7 @@ func (this *PdfWriter) addObjects(obj PdfObject) error {
// Could refer to somewhere outside of the scope of the output doc.
// Should be done by the reader already.
// -> ERROR.
common.Log.Error("Parent is a reference object - Cannot be in writer (needs to be resolved)")
common.Log.Debug("ERROR: Parent is a reference object - Cannot be in writer (needs to be resolved)")
return fmt.Errorf("Parent is a reference object - Cannot be in writer (needs to be resolved) - %s", parentObj)
}
}
@ -213,7 +213,7 @@ func (this *PdfWriter) addObjects(obj PdfObject) error {
if _, isReference := obj.(*PdfObjectReference); isReference {
// Should never be a reference, should already be resolved.
common.Log.Error("Cannot be a reference!")
common.Log.Debug("ERROR: Cannot be a reference!")
return errors.New("Reference not allowed")
}
@ -407,7 +407,7 @@ func (this *PdfWriter) AddForms(forms *PdfObjectDictionary) error {
return errors.New("P pointing outside of write pages")
}
} else {
common.Log.Error("P entry not an indirect object (%T)", p)
common.Log.Debug("ERROR: P entry not an indirect object (%T)", p)
}
}
@ -508,14 +508,14 @@ func (this *PdfWriter) Encrypt(userPass, ownerPass []byte, options *EncryptOptio
// Make the O and U objects.
O, err := crypter.alg3(userPass, ownerPass)
if err != nil {
common.Log.Error("Error generating O for encryption (%s)", err)
common.Log.Debug("ERROR: Error generating O for encryption (%s)", err)
return err
}
crypter.O = []byte(O)
common.Log.Debug("gen O: % x", O)
U, key, err := crypter.alg5(userPass)
if err != nil {
common.Log.Error("Error generating O for encryption (%s)", err)
common.Log.Debug("ERROR: Error generating O for encryption (%s)", err)
return err
}
common.Log.Debug("gen U: % x", U)
@ -596,7 +596,7 @@ func (this *PdfWriter) Write(ws io.WriteSeeker) error {
if this.crypter != nil && obj != this.encryptObj {
err := this.crypter.Encrypt(obj, int64(idx+1), 0)
if err != nil {
common.Log.Error("Failed encrypting (%s)", err)
common.Log.Debug("ERROR: Failed encrypting (%s)", err)
return err
}