mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
Cleaning up logging, more debug -> trace log level
This commit is contained in:
parent
79655b0b0d
commit
6516adddc4
@ -342,13 +342,13 @@ func (this *PdfCrypt) authenticate(password []byte) (bool, error) {
|
||||
this.Authenticated = false
|
||||
|
||||
// Try user password.
|
||||
common.Log.Debug("Debugging authentication - user pass")
|
||||
common.Log.Trace("Debugging authentication - user pass")
|
||||
authenticated, err := this.Alg6(password)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if authenticated {
|
||||
common.Log.Debug("this.Authenticated = True")
|
||||
common.Log.Trace("this.Authenticated = True")
|
||||
this.Authenticated = true
|
||||
return true, nil
|
||||
}
|
||||
@ -356,13 +356,13 @@ func (this *PdfCrypt) authenticate(password []byte) (bool, error) {
|
||||
// Try owner password also.
|
||||
// May not be necessary if only want to get all contents.
|
||||
// (user pass needs to be known or empty).
|
||||
common.Log.Debug("Debugging authentication - owner pass")
|
||||
common.Log.Trace("Debugging authentication - owner pass")
|
||||
authenticated, err = this.Alg7(password, password)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if authenticated {
|
||||
common.Log.Debug("this.Authenticated = True")
|
||||
common.Log.Trace("this.Authenticated = True")
|
||||
this.Authenticated = true
|
||||
return true, nil
|
||||
}
|
||||
@ -438,17 +438,17 @@ func (this *PdfCrypt) makeKey(filter string, objNum, genNum uint32, ekey []byte)
|
||||
func (this *PdfCrypt) isDecrypted(obj PdfObject) bool {
|
||||
_, ok := this.DecryptedObjects[obj]
|
||||
if ok {
|
||||
common.Log.Debug("Already decrypted")
|
||||
common.Log.Trace("Already decrypted")
|
||||
return true
|
||||
} else {
|
||||
common.Log.Debug("Not decrypted yet")
|
||||
common.Log.Trace("Not decrypted yet")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Decrypt a buffer with a selected crypt filter.
|
||||
func (this *PdfCrypt) decryptBytes(buf []byte, filter string, okey []byte) ([]byte, error) {
|
||||
common.Log.Debug("Decrypt bytes")
|
||||
common.Log.Trace("Decrypt bytes")
|
||||
cf, ok := this.CryptFilters[filter]
|
||||
if !ok {
|
||||
common.Log.Debug("ERROR Unsupported crypt filter (%s)", filter)
|
||||
@ -462,9 +462,9 @@ func (this *PdfCrypt) decryptBytes(buf []byte, filter string, okey []byte) ([]by
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
common.Log.Debug("RC4 Decrypt: % x", buf)
|
||||
common.Log.Trace("RC4 Decrypt: % x", buf)
|
||||
ciph.XORKeyStream(buf, buf)
|
||||
common.Log.Debug("to: % x", buf)
|
||||
common.Log.Trace("to: % x", buf)
|
||||
return buf, nil
|
||||
} else if cfMethod == "AESV2" {
|
||||
// Strings and streams encrypted with AES shall use a padding
|
||||
@ -505,10 +505,10 @@ func (this *PdfCrypt) decryptBytes(buf []byte, filter string, okey []byte) ([]by
|
||||
|
||||
mode := cipher.NewCBCDecrypter(ciph, iv)
|
||||
|
||||
common.Log.Debug("AES Decrypt (%d): % x", len(buf), buf)
|
||||
common.Log.Debug("chop AES Decrypt (%d): % x", len(buf), buf)
|
||||
common.Log.Trace("AES Decrypt (%d): % x", len(buf), buf)
|
||||
common.Log.Trace("chop AES Decrypt (%d): % x", len(buf), buf)
|
||||
mode.CryptBlocks(buf, buf)
|
||||
common.Log.Debug("to (%d): % x", len(buf), buf)
|
||||
common.Log.Trace("to (%d): % x", len(buf), buf)
|
||||
//copy(buf[0:], buf[16:])
|
||||
//common.Log.Debug("chop to (%d): % x", len(buf), buf)
|
||||
return buf, nil
|
||||
@ -530,7 +530,7 @@ func (this *PdfCrypt) Decrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
if io, isIndirect := obj.(*PdfIndirectObject); isIndirect {
|
||||
this.DecryptedObjects[io] = true
|
||||
|
||||
common.Log.Debug("Decrypting indirect %d %d obj!", io.ObjectNumber, io.GenerationNumber)
|
||||
common.Log.Trace("Decrypting indirect %d %d obj!", io.ObjectNumber, io.GenerationNumber)
|
||||
|
||||
objNum := (*io).ObjectNumber
|
||||
genNum := (*io).GenerationNumber
|
||||
@ -548,7 +548,7 @@ func (this *PdfCrypt) Decrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
this.DecryptedObjects[so] = true
|
||||
objNum := (*so).ObjectNumber
|
||||
genNum := (*so).GenerationNumber
|
||||
common.Log.Debug("Decrypting stream %d %d !", objNum, genNum)
|
||||
common.Log.Trace("Decrypting stream %d %d !", objNum, genNum)
|
||||
|
||||
// TODO: Check for crypt filter (V4).
|
||||
// The Crypt filter shall be the first filter in the Filter array entry.
|
||||
@ -558,7 +558,7 @@ func (this *PdfCrypt) Decrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
streamFilter := "Default" // Default RC4.
|
||||
if this.V >= 4 {
|
||||
streamFilter = this.StreamFilter
|
||||
common.Log.Debug("this.StreamFilter = %s", this.StreamFilter)
|
||||
common.Log.Trace("this.StreamFilter = %s", this.StreamFilter)
|
||||
|
||||
if filters, ok := (*dict)["Filter"].(*PdfObjectArray); ok {
|
||||
// Crypt filter can only be the first entry.
|
||||
@ -572,7 +572,7 @@ func (this *PdfCrypt) Decrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
if decodeParams, ok := (*dict)["DecodeParms"].(*PdfObjectDictionary); ok {
|
||||
if filterName, ok := (*decodeParams)["Name"].(*PdfObjectName); ok {
|
||||
if _, ok := this.CryptFilters[string(*filterName)]; ok {
|
||||
common.Log.Debug("Using stream filter %s", *filterName)
|
||||
common.Log.Trace("Using stream filter %s", *filterName)
|
||||
streamFilter = string(*filterName)
|
||||
}
|
||||
}
|
||||
@ -581,7 +581,7 @@ func (this *PdfCrypt) Decrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
}
|
||||
}
|
||||
|
||||
common.Log.Debug("with %s filter", streamFilter)
|
||||
common.Log.Trace("with %s filter", streamFilter)
|
||||
if streamFilter == "Identity" {
|
||||
// Identity: pass unchanged.
|
||||
return nil
|
||||
@ -608,12 +608,12 @@ func (this *PdfCrypt) Decrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
return nil
|
||||
}
|
||||
if s, isString := obj.(*PdfObjectString); isString {
|
||||
common.Log.Debug("Decrypting string!")
|
||||
common.Log.Trace("Decrypting string!")
|
||||
|
||||
stringFilter := "Default"
|
||||
if this.V >= 4 {
|
||||
// Currently only support Identity / RC4.
|
||||
common.Log.Debug("with %s filter", this.StringFilter)
|
||||
common.Log.Trace("with %s filter", this.StringFilter)
|
||||
if this.StringFilter == "Identity" {
|
||||
// Identity: pass unchanged: No action.
|
||||
return nil
|
||||
@ -632,7 +632,7 @@ func (this *PdfCrypt) Decrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
for i := 0; i < len(*s); i++ {
|
||||
decrypted[i] = (*s)[i]
|
||||
}
|
||||
common.Log.Debug("Decrypt string: %s : % x", decrypted, decrypted)
|
||||
common.Log.Trace("Decrypt string: %s : % x", decrypted, decrypted)
|
||||
decrypted, err = this.decryptBytes(decrypted, stringFilter, key)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -685,17 +685,17 @@ func (this *PdfCrypt) Decrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
func (this *PdfCrypt) isEncrypted(obj PdfObject) bool {
|
||||
_, ok := this.EncryptedObjects[obj]
|
||||
if ok {
|
||||
common.Log.Debug("Already encrypted")
|
||||
common.Log.Trace("Already encrypted")
|
||||
return true
|
||||
} else {
|
||||
common.Log.Debug("Not encrypted yet")
|
||||
common.Log.Trace("Not encrypted yet")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Encrypt a buffer with the specified crypt filter and key.
|
||||
func (this *PdfCrypt) encryptBytes(buf []byte, filter string, okey []byte) ([]byte, error) {
|
||||
common.Log.Debug("Encrypt bytes")
|
||||
common.Log.Trace("Encrypt bytes")
|
||||
cf, ok := this.CryptFilters[filter]
|
||||
if !ok {
|
||||
common.Log.Debug("ERROR Unsupported crypt filter (%s)", filter)
|
||||
@ -709,9 +709,9 @@ func (this *PdfCrypt) encryptBytes(buf []byte, filter string, okey []byte) ([]by
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
common.Log.Debug("RC4 Encrypt: % x", buf)
|
||||
common.Log.Trace("RC4 Encrypt: % x", buf)
|
||||
ciph.XORKeyStream(buf, buf)
|
||||
common.Log.Debug("to: % x", buf)
|
||||
common.Log.Trace("to: % x", buf)
|
||||
return buf, nil
|
||||
} else if cfMethod == "AESV2" {
|
||||
// Strings and streams encrypted with AES shall use a padding
|
||||
@ -732,7 +732,7 @@ func (this *PdfCrypt) encryptBytes(buf []byte, filter string, okey []byte) ([]by
|
||||
return nil, err
|
||||
}
|
||||
|
||||
common.Log.Debug("AES Encrypt (%d): % x", len(buf), buf)
|
||||
common.Log.Trace("AES Encrypt (%d): % x", len(buf), buf)
|
||||
|
||||
// If using the AES algorithm, the Cipher Block Chaining (CBC)
|
||||
// mode, which requires an initialization vector, is used. The
|
||||
@ -743,7 +743,7 @@ func (this *PdfCrypt) encryptBytes(buf []byte, filter string, okey []byte) ([]by
|
||||
for i := 0; i < pad; i++ {
|
||||
buf = append(buf, byte(pad))
|
||||
}
|
||||
common.Log.Debug("Padded to %d bytes", len(buf))
|
||||
common.Log.Trace("Padded to %d bytes", len(buf))
|
||||
|
||||
// Generate random 16 bytes, place in beginning of buffer.
|
||||
ciphertext := make([]byte, 16+len(buf))
|
||||
@ -756,7 +756,7 @@ func (this *PdfCrypt) encryptBytes(buf []byte, filter string, okey []byte) ([]by
|
||||
mode.CryptBlocks(ciphertext[aes.BlockSize:], buf)
|
||||
|
||||
buf = ciphertext
|
||||
common.Log.Debug("to (%d): % x", len(buf), buf)
|
||||
common.Log.Trace("to (%d): % x", len(buf), buf)
|
||||
|
||||
return buf, nil
|
||||
}
|
||||
@ -777,7 +777,7 @@ func (this *PdfCrypt) Encrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
if io, isIndirect := obj.(*PdfIndirectObject); isIndirect {
|
||||
this.EncryptedObjects[io] = true
|
||||
|
||||
common.Log.Debug("Encrypting indirect %d %d obj!", io.ObjectNumber, io.GenerationNumber)
|
||||
common.Log.Trace("Encrypting indirect %d %d obj!", io.ObjectNumber, io.GenerationNumber)
|
||||
|
||||
objNum := (*io).ObjectNumber
|
||||
genNum := (*io).GenerationNumber
|
||||
@ -794,7 +794,7 @@ func (this *PdfCrypt) Encrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
this.EncryptedObjects[so] = true
|
||||
objNum := (*so).ObjectNumber
|
||||
genNum := (*so).GenerationNumber
|
||||
common.Log.Debug("Encrypting stream %d %d !", objNum, genNum)
|
||||
common.Log.Trace("Encrypting stream %d %d !", objNum, genNum)
|
||||
|
||||
// TODO: Check for crypt filter (V4).
|
||||
// The Crypt filter shall be the first filter in the Filter array entry.
|
||||
@ -806,7 +806,7 @@ func (this *PdfCrypt) Encrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
// For now. Need to change when we add support for more than
|
||||
// Identity / RC4.
|
||||
streamFilter = this.StreamFilter
|
||||
common.Log.Debug("this.StreamFilter = %s", this.StreamFilter)
|
||||
common.Log.Trace("this.StreamFilter = %s", this.StreamFilter)
|
||||
|
||||
if filters, ok := (*dict)["Filter"].(*PdfObjectArray); ok {
|
||||
// Crypt filter can only be the first entry.
|
||||
@ -820,7 +820,7 @@ func (this *PdfCrypt) Encrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
if decodeParams, ok := (*dict)["DecodeParms"].(*PdfObjectDictionary); ok {
|
||||
if filterName, ok := (*decodeParams)["Name"].(*PdfObjectName); ok {
|
||||
if _, ok := this.CryptFilters[string(*filterName)]; ok {
|
||||
common.Log.Debug("Using stream filter %s", *filterName)
|
||||
common.Log.Trace("Using stream filter %s", *filterName)
|
||||
streamFilter = string(*filterName)
|
||||
}
|
||||
}
|
||||
@ -829,7 +829,7 @@ func (this *PdfCrypt) Encrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
}
|
||||
}
|
||||
|
||||
common.Log.Debug("with %s filter", streamFilter)
|
||||
common.Log.Trace("with %s filter", streamFilter)
|
||||
if streamFilter == "Identity" {
|
||||
// Identity: pass unchanged.
|
||||
return nil
|
||||
@ -856,11 +856,11 @@ func (this *PdfCrypt) Encrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
return nil
|
||||
}
|
||||
if s, isString := obj.(*PdfObjectString); isString {
|
||||
common.Log.Debug("Encrypting string!")
|
||||
common.Log.Trace("Encrypting string!")
|
||||
|
||||
stringFilter := "Default"
|
||||
if this.V >= 4 {
|
||||
common.Log.Debug("with %s filter", this.StringFilter)
|
||||
common.Log.Trace("with %s filter", this.StringFilter)
|
||||
if this.StringFilter == "Identity" {
|
||||
// Identity: pass unchanged: No action.
|
||||
return nil
|
||||
@ -878,7 +878,7 @@ func (this *PdfCrypt) Encrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
for i := 0; i < len(*s); i++ {
|
||||
encrypted[i] = (*s)[i]
|
||||
}
|
||||
common.Log.Debug("Encrypt string: %s : % x", encrypted, encrypted)
|
||||
common.Log.Trace("Encrypt string: %s : % x", encrypted, encrypted)
|
||||
encrypted, err = this.encryptBytes(encrypted, stringFilter, key)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -929,7 +929,7 @@ func (this *PdfCrypt) Encrypt(obj PdfObject, parentObjNum, parentGenNum int64) e
|
||||
|
||||
// Algorithm 2: Computing an encryption key.
|
||||
func (this *PdfCrypt) Alg2(pass []byte) []byte {
|
||||
common.Log.Debug("Alg2")
|
||||
common.Log.Trace("Alg2")
|
||||
key := this.paddedPass(pass)
|
||||
|
||||
h := md5.New()
|
||||
@ -945,12 +945,12 @@ func (this *PdfCrypt) Alg2(pass []byte) []byte {
|
||||
pb = append(pb, byte(((p >> uint(8*i)) & 0xff)))
|
||||
}
|
||||
h.Write(pb)
|
||||
common.Log.Debug("go P: % x", pb)
|
||||
common.Log.Trace("go P: % x", pb)
|
||||
|
||||
// Pass ID[0] from the trailer
|
||||
h.Write([]byte(this.Id0))
|
||||
|
||||
common.Log.Debug("this.R = %d encryptMetadata %v", this.R, this.EncryptMetadata)
|
||||
common.Log.Trace("this.R = %d encryptMetadata %v", this.R, this.EncryptMetadata)
|
||||
if (this.R >= 4) && !this.EncryptMetadata {
|
||||
h.Write([]byte{0xff, 0xff, 0xff, 0xff})
|
||||
}
|
||||
@ -1065,9 +1065,9 @@ func (this *PdfCrypt) Alg5(upass []byte) (PdfObjectString, []byte, error) {
|
||||
h.Write([]byte(this.Id0))
|
||||
hash := h.Sum(nil)
|
||||
|
||||
common.Log.Debug("Alg5")
|
||||
common.Log.Debug("ekey: % x", ekey)
|
||||
common.Log.Debug("ID: % x", this.Id0)
|
||||
common.Log.Trace("Alg5")
|
||||
common.Log.Trace("ekey: % x", ekey)
|
||||
common.Log.Trace("ID: % x", this.Id0)
|
||||
|
||||
if len(hash) != 16 {
|
||||
return U, ekey, errors.New("Hash length not 16 bytes")
|
||||
@ -1096,8 +1096,8 @@ func (this *PdfCrypt) Alg5(upass []byte) (PdfObjectString, []byte, error) {
|
||||
return U, ekey, errors.New("Failed rc4 ciph")
|
||||
}
|
||||
ciph.XORKeyStream(encrypted, encrypted)
|
||||
common.Log.Debug("i = %d, ekey: % x", i, ekey2)
|
||||
common.Log.Debug("i = %d -> % x", i, encrypted)
|
||||
common.Log.Trace("i = %d, ekey: % x", i, ekey2)
|
||||
common.Log.Trace("i = %d -> % x", i, encrypted)
|
||||
}
|
||||
|
||||
bb := make([]byte, 32)
|
||||
@ -1134,7 +1134,7 @@ func (this *PdfCrypt) Alg6(upass []byte) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
common.Log.Debug("check: % x == % x ?", string(uo), string(this.U))
|
||||
common.Log.Trace("check: % x == % x ?", string(uo), string(this.U))
|
||||
|
||||
uGen := string(uo) // Generated U from specified pass.
|
||||
uDoc := string(this.U) // U from the document.
|
||||
|
@ -27,8 +27,8 @@ func getUniDocVersion() string {
|
||||
* Mostly for debugging purposes and inspecting odd PDF files.
|
||||
*/
|
||||
func (this *PdfParser) inspect() (map[string]int, error) {
|
||||
common.Log.Debug("--------INSPECT ----------")
|
||||
common.Log.Debug("Xref table:")
|
||||
common.Log.Trace("--------INSPECT ----------")
|
||||
common.Log.Trace("Xref table:")
|
||||
|
||||
objTypes := map[string]int{}
|
||||
objCount := 0
|
||||
@ -47,26 +47,26 @@ func (this *PdfParser) inspect() (map[string]int, error) {
|
||||
continue
|
||||
}
|
||||
objCount++
|
||||
common.Log.Debug("==========")
|
||||
common.Log.Debug("Looking up object number: %d", xref.objectNumber)
|
||||
common.Log.Trace("==========")
|
||||
common.Log.Trace("Looking up object number: %d", xref.objectNumber)
|
||||
o, err := this.LookupByNumber(xref.objectNumber)
|
||||
if err != nil {
|
||||
common.Log.Debug("ERROR: Fail to lookup obj %d (%s)", xref.objectNumber, err)
|
||||
common.Log.Trace("ERROR: Fail to lookup obj %d (%s)", xref.objectNumber, err)
|
||||
failedCount++
|
||||
continue
|
||||
}
|
||||
|
||||
common.Log.Debug("obj: %s", o)
|
||||
common.Log.Trace("obj: %s", o)
|
||||
|
||||
iobj, isIndirect := o.(*PdfIndirectObject)
|
||||
if isIndirect {
|
||||
common.Log.Debug("IND OOBJ %d: %s", xref.objectNumber, iobj)
|
||||
common.Log.Trace("IND OOBJ %d: %s", xref.objectNumber, iobj)
|
||||
dict, isDict := iobj.PdfObject.(*PdfObjectDictionary)
|
||||
if isDict {
|
||||
// Check if has Type parameter.
|
||||
if ot, has := (*dict)["Type"].(*PdfObjectName); has {
|
||||
otype := string(*ot)
|
||||
common.Log.Debug("---> Obj type: %s", otype)
|
||||
common.Log.Trace("---> Obj type: %s", otype)
|
||||
_, isDefined := objTypes[otype]
|
||||
if isDefined {
|
||||
objTypes[otype]++
|
||||
@ -76,7 +76,7 @@ func (this *PdfParser) inspect() (map[string]int, error) {
|
||||
} else if ot, has := (*dict)["Subtype"].(*PdfObjectName); has {
|
||||
// Check if subtype
|
||||
otype := string(*ot)
|
||||
common.Log.Debug("---> Obj subtype: %s", otype)
|
||||
common.Log.Trace("---> Obj subtype: %s", otype)
|
||||
_, isDefined := objTypes[otype]
|
||||
if isDefined {
|
||||
objTypes[otype]++
|
||||
@ -97,7 +97,7 @@ func (this *PdfParser) inspect() (map[string]int, error) {
|
||||
}
|
||||
} else if sobj, isStream := o.(*PdfObjectStream); isStream {
|
||||
if otype, ok := (*(sobj.PdfObjectDictionary))["Type"].(*PdfObjectName); ok {
|
||||
common.Log.Debug("--> Stream object type: %s", *otype)
|
||||
common.Log.Trace("--> Stream object type: %s", *otype)
|
||||
k := string(*otype)
|
||||
if _, isDefined := objTypes[k]; isDefined {
|
||||
objTypes[k]++
|
||||
@ -111,23 +111,23 @@ func (this *PdfParser) inspect() (map[string]int, error) {
|
||||
ot, isName := (*dict)["Type"].(*PdfObjectName)
|
||||
if isName {
|
||||
otype := string(*ot)
|
||||
common.Log.Debug("--- obj type %s", otype)
|
||||
common.Log.Trace("--- obj type %s", otype)
|
||||
objTypes[otype]++
|
||||
}
|
||||
}
|
||||
common.Log.Debug("DIRECT OBJ %d: %s", xref.objectNumber, o)
|
||||
common.Log.Trace("DIRECT OBJ %d: %s", xref.objectNumber, o)
|
||||
}
|
||||
|
||||
i++
|
||||
}
|
||||
common.Log.Debug("--------EOF INSPECT ----------")
|
||||
common.Log.Debug("=======")
|
||||
common.Log.Debug("Object count: %d", objCount)
|
||||
common.Log.Debug("Failed lookup: %d", failedCount)
|
||||
common.Log.Trace("--------EOF INSPECT ----------")
|
||||
common.Log.Trace("=======")
|
||||
common.Log.Trace("Object count: %d", objCount)
|
||||
common.Log.Trace("Failed lookup: %d", failedCount)
|
||||
for t, c := range objTypes {
|
||||
common.Log.Debug("%s: %d", t, c)
|
||||
common.Log.Trace("%s: %d", t, c)
|
||||
}
|
||||
common.Log.Debug("=======")
|
||||
common.Log.Trace("=======")
|
||||
|
||||
if len(this.xrefs) < 1 {
|
||||
common.Log.Debug("ERROR: This document is invalid (xref table missing!)")
|
||||
@ -136,9 +136,9 @@ func (this *PdfParser) inspect() (map[string]int, error) {
|
||||
|
||||
fontObjs, ok := objTypes["Font"]
|
||||
if !ok || fontObjs < 2 {
|
||||
common.Log.Debug("This document is probably scanned!")
|
||||
common.Log.Trace("This document is probably scanned!")
|
||||
} else {
|
||||
common.Log.Debug("This document is valid for extraction!")
|
||||
common.Log.Trace("This document is valid for extraction!")
|
||||
}
|
||||
|
||||
return objTypes, nil
|
||||
|
@ -343,12 +343,12 @@ func (r *PdfReader) newPdfAnnotationFromIndirectObject(container *PdfIndirectObj
|
||||
if obj, has := (*d)["Type"]; has {
|
||||
str, ok := obj.(*PdfObjectName)
|
||||
if !ok {
|
||||
common.Log.Debug("Incompatibility! Invalid type of Type (%T) - should be Name", obj)
|
||||
common.Log.Trace("Incompatibility! Invalid type of Type (%T) - should be Name", obj)
|
||||
} else {
|
||||
if *str != "Annot" {
|
||||
// Log a debug message.
|
||||
// Not returning an error on this.
|
||||
common.Log.Debug("Unsuspected Type != Annot (%s)", *str)
|
||||
common.Log.Trace("Unsuspected Type != Annot (%s)", *str)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -441,9 +441,9 @@ func (r *PdfReader) newPdfAnnotationFromIndirectObject(container *PdfIndirectObj
|
||||
}
|
||||
ctx.PdfAnnotation = annot
|
||||
annot.context = ctx
|
||||
common.Log.Debug("LINE ANNOTATION: annot (%T): %+v\n", annot, annot)
|
||||
common.Log.Debug("LINE ANNOTATION: ctx (%T): %+v\n", ctx, ctx)
|
||||
common.Log.Debug("LINE ANNOTATION Markup: ctx (%T): %+v\n", ctx.PdfAnnotationMarkup, ctx.PdfAnnotationMarkup)
|
||||
common.Log.Trace("LINE ANNOTATION: annot (%T): %+v\n", annot, annot)
|
||||
common.Log.Trace("LINE ANNOTATION: ctx (%T): %+v\n", ctx, ctx)
|
||||
common.Log.Trace("LINE ANNOTATION Markup: ctx (%T): %+v\n", ctx.PdfAnnotationMarkup, ctx.PdfAnnotationMarkup)
|
||||
|
||||
return annot, nil
|
||||
case "Square":
|
||||
|
@ -1217,13 +1217,13 @@ func newPdfColorspaceSpecialIndexedFromPdfObject(obj PdfObject) (*PdfColorspaceS
|
||||
if str, ok := obj.(*PdfObjectString); ok {
|
||||
data = []byte(*str)
|
||||
} else if stream, ok := obj.(*PdfObjectStream); ok {
|
||||
common.Log.Debug("Indexed stream: %s", obj.String())
|
||||
common.Log.Debug("Encoded (%d) : %# x", len(stream.Stream), stream.Stream)
|
||||
common.Log.Trace("Indexed stream: %s", obj.String())
|
||||
common.Log.Trace("Encoded (%d) : %# x", len(stream.Stream), stream.Stream)
|
||||
decoded, err := DecodeStream(stream)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
common.Log.Debug("Decoded (%d) : % X", len(decoded), decoded)
|
||||
common.Log.Trace("Decoded (%d) : % X", len(decoded), decoded)
|
||||
data = decoded
|
||||
} else {
|
||||
return nil, fmt.Errorf("Indexed CS: Invalid table format")
|
||||
|
@ -441,7 +441,7 @@ func newPdfFunctionType2FromPdfObject(obj PdfObject) (*PdfFunctionType2, error)
|
||||
return nil, errors.New("Type check error")
|
||||
}
|
||||
|
||||
common.Log.Debug("FUNC2: %s", dict.String())
|
||||
common.Log.Trace("FUNC2: %s", dict.String())
|
||||
|
||||
// Domain
|
||||
array, has := TraceToDirectObject((*dict)["Domain"]).(*PdfObjectArray)
|
||||
|
@ -65,32 +65,32 @@ func (this *PSParser) parseFunction() (*PSProgram, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
common.Log.Debug("Peek string: %s", string(bb))
|
||||
common.Log.Trace("Peek string: %s", string(bb))
|
||||
// Determine type.
|
||||
if bb[0] == '}' {
|
||||
common.Log.Debug("EOF function")
|
||||
common.Log.Trace("EOF function")
|
||||
this.reader.ReadByte()
|
||||
break
|
||||
} else if bb[0] == '{' {
|
||||
common.Log.Debug("Function!")
|
||||
common.Log.Trace("Function!")
|
||||
inlineF, err := this.parseFunction()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
function.Append(inlineF)
|
||||
} else if pdfcore.IsDecimalDigit(bb[0]) || (bb[0] == '-' && pdfcore.IsDecimalDigit(bb[1])) {
|
||||
common.Log.Debug("->Number!")
|
||||
common.Log.Trace("->Number!")
|
||||
number, err := this.parseNumber()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
function.Append(number)
|
||||
} else {
|
||||
common.Log.Debug("->Operand or bool?")
|
||||
common.Log.Trace("->Operand or bool?")
|
||||
// Let's peek farther to find out.
|
||||
bb, _ = this.reader.Peek(5)
|
||||
peekStr := string(bb)
|
||||
common.Log.Debug("Peek str: %s", peekStr)
|
||||
common.Log.Trace("Peek str: %s", peekStr)
|
||||
|
||||
if (len(peekStr) > 4) && (peekStr[:5] == "false") {
|
||||
b, err := this.parseBool()
|
||||
@ -144,7 +144,7 @@ func (this *PSParser) parseNumber() (PSObject, error) {
|
||||
allowSigns := true
|
||||
numStr := ""
|
||||
for {
|
||||
common.Log.Debug("Parsing number \"%s\"", numStr)
|
||||
common.Log.Trace("Parsing number \"%s\"", numStr)
|
||||
bb, err := this.reader.Peek(1)
|
||||
if err == io.EOF {
|
||||
// GH: EOF handling. Handle EOF like end of line. Can happen with
|
||||
|
Loading…
x
Reference in New Issue
Block a user