Skip to content

Commit

Permalink
add Encrypt to xref
Browse files Browse the repository at this point in the history
  • Loading branch information
oneplus1000 committed Sep 27, 2016
1 parent 2e88656 commit 064b15c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 23 additions & 1 deletion gopdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,23 @@ func (gp *GoPdf) prepare() {
}
}

func (gp *GoPdf) xref(linelens []int, buff *bytes.Buffer, i *int) {
func (gp *GoPdf) xref(linelens []int, buff *bytes.Buffer, i *int) error {

isPDFProtection := false
idPDFProtection := -1
if gp.pdfProtection != nil {
isPDFProtection = true
idPDFProtection = *i + 1
var enObj EncryptionObj
if err := enObj.build(); err != nil {
return err
}
buff.WriteString(strconv.Itoa(idPDFProtection) + " 0 obj\n")
buff.Write(enObj.getObjBuff().Bytes())
buff.WriteString("endobj\n\n")
(*i)++
}

xrefbyteoffset := buff.Len()
buff.WriteString("xref\n")
buff.WriteString("0 " + strconv.Itoa((*i)+1) + "\n")
Expand All @@ -637,13 +653,19 @@ func (gp *GoPdf) xref(linelens []int, buff *bytes.Buffer, i *int) {
buff.WriteString("<<\n")
buff.WriteString("/Size " + strconv.Itoa(max+1) + "\n")
buff.WriteString("/Root 1 0 R\n")
if isPDFProtection {
buff.WriteString(fmt.Sprintf("/Encrypt %d 0 R\n", idPDFProtection))
buff.WriteString("/ID [()()]\n")
}
buff.WriteString(">>\n")

buff.WriteString("startxref\n")
buff.WriteString(strconv.Itoa(xrefbyteoffset))
buff.WriteString("\n%%EOF\n")

(*i)++

return nil
}

//ปรับ xref ให้เป็น 10 หลัก
Expand Down
2 changes: 0 additions & 2 deletions pdf_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ func (p *PDFProtection) generateencryptionkey(userPass []byte, ownerPass []byte,
}
p.uValue = uValue
p.pValue = -((protection ^ 255) + 1)
//fmt.Printf("%d\n", p.pValue)
//fmt.Printf("%#v\n", uValue)

return nil
}
Expand Down

0 comments on commit 064b15c

Please sign in to comment.