Skip to content

Commit

Permalink
🔧 build: updated packages
Browse files Browse the repository at this point in the history
  • Loading branch information
shurco committed May 16, 2024
1 parent 42ab66e commit 5100030
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 238 deletions.
150 changes: 84 additions & 66 deletions cmd/pdf-cert/main.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
package main

import (
"log"

"github.com/google/uuid"
"github.com/signintech/gopdf"
"github.com/skip2/go-qrcode"
)

func main() {
pdf := gopdf.GoPdf{}
pdf := &gopdf.GoPdf{}
pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4})

pdf.AddTTFFont("Arial", "./fonts/Arial.ttf")
pdf.AddTTFFont("Arial-Bold", "./fonts/Arial-Bold.ttf")
if err := pdf.AddTTFFont("Arial", "./fonts/Arial.ttf"); err != nil {
log.Print(err.Error())
return
}

if err := pdf.AddTTFFont("Arial-Bold", "./fonts/Arial-Bold.ttf"); err != nil {
log.Print(err.Error())
return
}

// ---------
pdf.AddPage()
cert := pdf.ImportPage("./img/cert-fon.pdf", 1, "/MediaBox")
pdf.UseImportedTemplate(cert, 0, 0, 0, 0)

// pdf.SetFillColor(59, 157, 79)
// pdf.Rectangle(23, 19, 576, 830, "F", 0, 0)
// pdf.SetFillColor(255, 255, 255)
// pdf.Rectangle(40, 35, 558, 813, "F", 0, 0)
// pdf.SetStrokeColor(59, 157, 79)
// pdf.Rectangle(48, 44, 550, 804, "D", 0, 0)

// ------ START HEADER -----
pdf.SetFillColor(0, 0, 0)
pdf.SetFont("Arial-Bold", "", 20)
pdf.SetXY(80, 80)
pdf.Cell(nil, "Signature Certificate")
Expand Down Expand Up @@ -75,56 +92,54 @@ func main() {
Location: "Barcelona, Spain",
SignerURL: "",
},
/*
{
UserName: "User Name 2",
Email: "user@mail.com",
Sent: "02 Feb 2023 09:59:25 UTC",
Viewed: "02 Feb 2023 10:05:59 UTC",
Signed: "02 Feb 2023 10:06:21 UTC",
EmailVerified: "02 Feb 2023 10:05:59 UTC",
EmailVerifiedStatus: "x",
IP: "79.153.222.202",
Location: "Barcelona, Spain",
SignerURL: "",
},
{
UserName: "User Name 3",
Email: "user@mail.com",
Sent: "02 Feb 2023 09:59:25 UTC",
Viewed: "02 Feb 2023 10:05:59 UTC",
Signed: "02 Feb 2023 10:06:21 UTC",
EmailVerified: "02 Feb 2023 10:05:59 UTC",
EmailVerifiedStatus: "x",
IP: "79.153.222.202",
Location: "Barcelona, Spain",
SignerURL: "",
},
{
UserName: "User Name 4",
Email: "user@mail.com",
Sent: "02 Feb 2023 09:59:25 UTC",
Viewed: "02 Feb 2023 10:05:59 UTC",
Signed: "02 Feb 2023 10:06:21 UTC",
EmailVerified: "02 Feb 2023 10:05:59 UTC",
EmailVerifiedStatus: "x",
IP: "79.153.222.202",
Location: "Barcelona, Spain",
SignerURL: "",
},
{
UserName: "User Name 5",
Email: "user@mail.com",
Sent: "02 Feb 2023 09:59:25 UTC",
Viewed: "02 Feb 2023 10:05:59 UTC",
Signed: "02 Feb 2023 10:06:21 UTC",
EmailVerified: "02 Feb 2023 10:05:59 UTC",
EmailVerifiedStatus: "x",
IP: "79.153.222.202",
Location: "Barcelona, Spain",
SignerURL: "",
},
*/
{
UserName: "User Name 2",
Email: "user@mail.com",
Sent: "02 Feb 2023 09:59:25 UTC",
Viewed: "02 Feb 2023 10:05:59 UTC",
Signed: "02 Feb 2023 10:06:21 UTC",
EmailVerified: "02 Feb 2023 10:05:59 UTC",
EmailVerifiedStatus: "x",
IP: "79.153.222.202",
Location: "Barcelona, Spain",
SignerURL: "",
},
{
UserName: "User Name 3",
Email: "user@mail.com",
Sent: "02 Feb 2023 09:59:25 UTC",
Viewed: "02 Feb 2023 10:05:59 UTC",
Signed: "02 Feb 2023 10:06:21 UTC",
EmailVerified: "02 Feb 2023 10:05:59 UTC",
EmailVerifiedStatus: "x",
IP: "79.153.222.202",
Location: "Barcelona, Spain",
SignerURL: "",
},
{
UserName: "User Name 4",
Email: "user@mail.com",
Sent: "02 Feb 2023 09:59:25 UTC",
Viewed: "02 Feb 2023 10:05:59 UTC",
Signed: "02 Feb 2023 10:06:21 UTC",
EmailVerified: "02 Feb 2023 10:05:59 UTC",
EmailVerifiedStatus: "x",
IP: "79.153.222.202",
Location: "Barcelona, Spain",
SignerURL: "",
},
{
UserName: "User Name 5",
Email: "user@mail.com",
Sent: "02 Feb 2023 09:59:25 UTC",
Viewed: "02 Feb 2023 10:05:59 UTC",
Signed: "02 Feb 2023 10:06:21 UTC",
EmailVerified: "02 Feb 2023 10:05:59 UTC",
EmailVerifiedStatus: "x",
IP: "79.153.222.202",
Location: "Barcelona, Spain",
SignerURL: "",
},
}

var shiftSignerBlock float64
Expand All @@ -138,8 +153,8 @@ func main() {

pdf.SetFillColor(255, 255, 255)
pdf.SetTransparency(gopdf.Transparency{
Alpha: 0.8,
BlendModeType: gopdf.SoftLight,
Alpha: 0.6,
BlendModeType: gopdf.Overlay,
})
pdf.Rectangle(75, 69+shiftSignerBlock, 525, 167+shiftSignerBlock, "F", 0, 0)
pdf.ClearTransparency()
Expand Down Expand Up @@ -172,23 +187,26 @@ func main() {
pdf.SetXY(83, 142+shiftSignerBlock)
pdf.Cell(nil, "Recipient Verification:")
pdf.SetFont("Arial", "", 7)
pdf.SetXY(90, 152+shiftSignerBlock)
pdf.SetXY(90, 153+shiftSignerBlock)
pdf.Cell(nil, "Email verified")
pdf.SetXY(83, 152+shiftSignerBlock)
pdf.SetXY(83, 153+shiftSignerBlock)
pdf.Cell(nil, signer.EmailVerifiedStatus)
pdf.SetXY(225, 152+shiftSignerBlock)
pdf.SetXY(225, 153+shiftSignerBlock)
pdf.Cell(nil, signer.EmailVerified)

// signature
pdf.Rectangle(370, 77+shiftSignerBlock, 515, 132+shiftSignerBlock, "D", 0, 0)
pdf.SetFillColor(255, 255, 255)
pdf.SetLineWidth(0.5)
pdf.SetLineType("dotted")
pdf.Rectangle(370, 77+shiftSignerBlock, 515, 132+shiftSignerBlock, "FD", 0, 0)

pdf.SetXY(370, 142+shiftSignerBlock)
pdf.SetXY(370, 143+shiftSignerBlock)
pdf.Cell(nil, "IP address:")
pdf.SetXY(407, 142+shiftSignerBlock)
pdf.SetXY(408, 143+shiftSignerBlock)
pdf.Cell(nil, signer.IP)
pdf.SetXY(370, 152+shiftSignerBlock)
pdf.SetXY(370, 153+shiftSignerBlock)
pdf.Cell(nil, "Location:")
pdf.SetXY(400, 152+shiftSignerBlock)
pdf.SetXY(400, 153+shiftSignerBlock)
pdf.Cell(nil, signer.Location)
}

Expand Down Expand Up @@ -216,8 +234,6 @@ func main() {
pdf.SetXY(160, 747)
pdf.Text("and secure document signing with eSignature.")

// pdf.SetFillColor(255, 255, 255)
// pdf.Rectangle(465, 705, 525, 765, "F", 0, 0)
qrCode, _ := qrcode.Encode("https://github.com/shurco/goSign", qrcode.Medium, 256) // dynamic
imgQRCode, _ := gopdf.ImageHolderByBytes(qrCode)
pdf.ImageByHolder(imgQRCode, 460, 700, &gopdf.Rect{W: 65, H: 65})
Expand All @@ -232,5 +248,7 @@ func main() {
Producer: "goSign (https://github.com/shurco/goSign)",
})

pdf.WritePdf("example.pdf")
if err := pdf.WritePdf("example.pdf"); err != nil {
log.Fatal(err)
}
}
Binary file modified cmd/pdf-cert2/cert.pdf
Binary file not shown.
54 changes: 39 additions & 15 deletions cmd/pdf-cert2/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package main

/*
import (
"bytes"
"encoding/json"
"log"
"os"
"github.com/google/uuid"
"github.com/pdfcpu/pdfcpu/pkg/api"
"github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
"github.com/pdfcpu/pdfcpu/pkg/pdfcpu/create"
"github.com/pdfcpu/pdfcpu/pkg/pdfcpu/model"
"github.com/pdfcpu/pdfcpu/pkg/pdfcpu/primitives"
"github.com/pdfcpu/pdfcpu/pkg/pdfcpu/types"
"github.com/skip2/go-qrcode"
)
Expand All @@ -21,9 +23,7 @@ func main() {
log.Fatal(err)
}
model.VersionStr = "goSign"

certData := primitives.PDF{
rootPDF := &primitives.PDF{
Origin: "UpperLeft",
Debug: false,
ContentBox: false,
Expand Down Expand Up @@ -56,6 +56,7 @@ func main() {
// BackgroundColor: "#C1C1C1",
TextBoxes: []*primitives.TextBox{
{
Name: "test",
Value: "Signature Certificate",
Position: [2]float64{80, 100},
Font: &primitives.FormFont{Name: "$helvetica-bold", Size: 20},
Expand Down Expand Up @@ -219,35 +220,58 @@ func main() {
},
},
},
XRefTable: &model.XRefTable{
Author: "goSign (https://github.com/shurco/goSign)",
Creator: "goSign (https://github.com/shurco/goSign)",
Producer: "goSign",
},
}
certBytes, err := json.Marshal(certData)
conf := model.NewDefaultConfiguration()
conf.Cmd = model.CREATE
ctx, err := pdfcpu.CreateContextWithXRefTable(conf, types.PaperSize["A4"])
if err != nil {
log.Fatal(err)
}
substrate, err := os.ReadFile("./img/substrate.pdf")
rootPDF.Conf = ctx.Configuration
rootPDF.XRefTable = ctx.XRefTable
rootPDF.Optimize = ctx.Optimize
if err := rootPDF.Validate(); err != nil {
log.Fatal(err)
}
pages, fontMap, err := rootPDF.RenderPages()
if err != nil {
log.Fatal(err)
}
if _, _, err := create.UpdatePageTree(ctx, pages, fontMap); err != nil {
log.Fatal(err)
}
if err = api.ValidateContext(ctx); err != nil {
log.Fatal(err)
}
// ctx.EmptyPage(nil, nil)
//ctx.XRefTable.
//_, err := api.Ima
//if err != nil {
// log.Fatal(err)
//}
// save certificate
fileName := "cert.pdf"
certFile, err := os.Create(fileName)
if err != nil {
log.Fatal(err)
}
defer certFile.Close()
if err = api.Create(bytes.NewReader(substrate), bytes.NewReader(certBytes), certFile, nil); err != nil {
log.Fatal(err)
}
model.VersionStr = "goSign"
api.WriteContext(ctx, certFile)
// remove tmp qrcode file
if err := os.Remove(fileUUID); err != nil {
log.Fatal(err)
}
}
*/
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ require (
github.com/signintech/gopdf v0.25.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/spf13/cobra v1.8.0
golang.org/x/crypto v0.22.0
golang.org/x/text v0.14.0
golang.org/x/crypto v0.23.0
golang.org/x/text v0.15.0
)

require (
Expand Down Expand Up @@ -52,14 +52,14 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/tinylib/msgp v1.1.9 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.52.0 // indirect
github.com/valyala/fasthttp v1.53.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/image v0.15.0 // indirect
golang.org/x/image v0.16.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/sys v0.20.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b // indirect
modernc.org/libc v1.50.5 // indirect
modernc.org/sqlite v1.29.8 // indirect
modernc.org/libc v1.50.6 // indirect
modernc.org/sqlite v1.29.9 // indirect
)
Loading

0 comments on commit 5100030

Please sign in to comment.