Skip to content

Commit

Permalink
Merge pull request #4 from postprime/minh/refactor-text-length
Browse files Browse the repository at this point in the history
Change background size when text isn't fitted with backgound size
  • Loading branch information
chunvv authored Apr 25, 2024
2 parents b2d06db + c007451 commit 4f6c6cb
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
9 changes: 8 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ func (d *Document) appendTitle(pdf *gofpdf.Fpdf) {
title := d.typeAsString()
pdf.SetXY(120, BaseMarginTop)
pdf.SetFillColor(DarkBgColor[0], DarkBgColor[1], DarkBgColor[2])
pdf.Rect(120, BaseMarginTop, 80, 10, "F")
titleCharacters := []rune(title)
if len(titleCharacters) >= 13 {
// in case: [調整ロイヤリティ支払報告書]
pdf.Rect(110, BaseMarginTop, 100, 10, "F")
} else {
// in case: [ロイヤリティ支払報告書]
pdf.Rect(120, BaseMarginTop, 80, 10, "F")
}
d.pdf.SetFont("deja", "", 20)
pdf.CellFormat(80, 10, title, "0", 0, "C", false, 0, "")
}
Expand Down
57 changes: 57 additions & 0 deletions generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,60 @@ func TestNew(t *testing.T) {
t.Errorf(err.Error())
}
}

func TestWithLongTitle(t *testing.T) {
doc, _ := New(Invoice, &Options{
TextTypeInvoice: "調整ロイヤリティ支払報告書",
AutoPrint: true,
})

doc.SetFooter(&HeaderFooter{
Text: "<center>*ロイヤリティは所得税法上の源泉徴収の対象となる使用料の支払に該当し、所定の源泉徴収税率を乗じて算出しています。</center>\n" +
"<center>*上記を確認の上、内容に異議がある場合には2週間以内に連絡下さいますようお願い致します。</center>",
Pagination: true,
})

doc.SetVersion(GenerateInvoiceNumber())

doc.SetDescription("対象期間:2021年5月1日~2021年5月31日")

doc.SetDate("2021/07/10")

doc.SetCompany(&Contact{
Name: "PostPrime(DKT株式会社)",
Address: &Address{Country: " ", City: " ", Address: " ", Address2: " ", PostalCode: " "},
})

doc.SetCustomer(
&Contact{
Name: "安部 慎之介 様",
Address: &Address{
Address: "港区芝浦3-8-1",
Address2: "ホゲホゲビル 3F",
PostalCode: "1080023",
City: "東京都",
Country: "日本",
},
Email: "[email protected]",
InvoiceRegistrationNumber: "T1234567891234",
},
)

//doc.AppendItem(&Item{Name: "対象期間のDKTの売上", Total: 900000, Tax: &Tax{Amount: 90000}})

doc.SetAfterCommission(&AfterCommission{Amount: 630000, ConsumptionTax: 64545, IsDomesticCreator: true})
doc.SetWithholdingTax(&WithholdingTax{Amount: 64323})
doc.SetPaymentFree(&PaymentFree{Amount: 35244})
doc.SetPaidAmount(&PaidAmount{Amount: 593433, PayoutDate: "2021年11月30日"})

pdf, err := doc.Build()
if err != nil {
t.Errorf(err.Error())
}

err = pdf.OutputFileAndClose("payment_details_example.pdf")

if err != nil {
t.Errorf(err.Error())
}
}
Binary file modified payment_details_example.pdf
Binary file not shown.

0 comments on commit 4f6c6cb

Please sign in to comment.