Skip to content

Commit 4f6c6cb

Browse files
authored
Merge pull request #4 from postprime/minh/refactor-text-length
Change background size when text isn't fitted with backgound size
2 parents b2d06db + c007451 commit 4f6c6cb

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

build.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,14 @@ func (d *Document) appendTitle(pdf *gofpdf.Fpdf) {
7878
title := d.typeAsString()
7979
pdf.SetXY(120, BaseMarginTop)
8080
pdf.SetFillColor(DarkBgColor[0], DarkBgColor[1], DarkBgColor[2])
81-
pdf.Rect(120, BaseMarginTop, 80, 10, "F")
81+
titleCharacters := []rune(title)
82+
if len(titleCharacters) >= 13 {
83+
// in case: [調整ロイヤリティ支払報告書]
84+
pdf.Rect(110, BaseMarginTop, 100, 10, "F")
85+
} else {
86+
// in case: [ロイヤリティ支払報告書]
87+
pdf.Rect(120, BaseMarginTop, 80, 10, "F")
88+
}
8289
d.pdf.SetFont("deja", "", 20)
8390
pdf.CellFormat(80, 10, title, "0", 0, "C", false, 0, "")
8491
}

generator_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,60 @@ func TestNew(t *testing.T) {
6060
t.Errorf(err.Error())
6161
}
6262
}
63+
64+
func TestWithLongTitle(t *testing.T) {
65+
doc, _ := New(Invoice, &Options{
66+
TextTypeInvoice: "調整ロイヤリティ支払報告書",
67+
AutoPrint: true,
68+
})
69+
70+
doc.SetFooter(&HeaderFooter{
71+
Text: "<center>*ロイヤリティは所得税法上の源泉徴収の対象となる使用料の支払に該当し、所定の源泉徴収税率を乗じて算出しています。</center>\n" +
72+
"<center>*上記を確認の上、内容に異議がある場合には2週間以内に連絡下さいますようお願い致します。</center>",
73+
Pagination: true,
74+
})
75+
76+
doc.SetVersion(GenerateInvoiceNumber())
77+
78+
doc.SetDescription("対象期間:2021年5月1日~2021年5月31日")
79+
80+
doc.SetDate("2021/07/10")
81+
82+
doc.SetCompany(&Contact{
83+
Name: "PostPrime(DKT株式会社)",
84+
Address: &Address{Country: " ", City: " ", Address: " ", Address2: " ", PostalCode: " "},
85+
})
86+
87+
doc.SetCustomer(
88+
&Contact{
89+
Name: "安部 慎之介 様",
90+
Address: &Address{
91+
Address: "港区芝浦3-8-1",
92+
Address2: "ホゲホゲビル 3F",
93+
PostalCode: "1080023",
94+
City: "東京都",
95+
Country: "日本",
96+
},
97+
Email: "abe.shinosuke@gmail.com",
98+
InvoiceRegistrationNumber: "T1234567891234",
99+
},
100+
)
101+
102+
//doc.AppendItem(&Item{Name: "対象期間のDKTの売上", Total: 900000, Tax: &Tax{Amount: 90000}})
103+
104+
doc.SetAfterCommission(&AfterCommission{Amount: 630000, ConsumptionTax: 64545, IsDomesticCreator: true})
105+
doc.SetWithholdingTax(&WithholdingTax{Amount: 64323})
106+
doc.SetPaymentFree(&PaymentFree{Amount: 35244})
107+
doc.SetPaidAmount(&PaidAmount{Amount: 593433, PayoutDate: "2021年11月30日"})
108+
109+
pdf, err := doc.Build()
110+
if err != nil {
111+
t.Errorf(err.Error())
112+
}
113+
114+
err = pdf.OutputFileAndClose("payment_details_example.pdf")
115+
116+
if err != nil {
117+
t.Errorf(err.Error())
118+
}
119+
}

payment_details_example.pdf

-4.06 KB
Binary file not shown.

0 commit comments

Comments
 (0)