@@ -100,7 +100,7 @@ const (
100100 idCardGapMM = 30.0
101101)
102102
103- func composeIdCard (ctx context.Context , fileHeaders []* multipart.FileHeader ) (string , func (), error ) {
103+ func composeIdCard (ctx context.Context , fileHeaders []* multipart.FileHeader , paper string ) (string , func (), error ) {
104104 if len (fileHeaders ) != 2 {
105105 return "" , nil , errors .New ("id card mode requires exactly 2 files (front and back)" )
106106 }
@@ -131,14 +131,50 @@ func composeIdCard(ctx context.Context, fileHeaders []*multipart.FileHeader) (st
131131 }
132132 }
133133
134+ var pageW , pageH float64
135+ if paper == "A5" {
136+ pageW , pageH = 148.0 , 210.0
137+ pdf := gofpdf .NewCustom (& gofpdf.InitType {
138+ OrientationStr : "P" ,
139+ UnitStr : "mm" ,
140+ Size : gofpdf.SizeType {Wd : pageW , Ht : pageH },
141+ })
142+ pdf .SetMargins (0 , 0 , 0 )
143+ pdf .SetAutoPageBreak (false , 0 )
144+ pdf .AddPage ()
145+
146+ imp := gofpdi .NewImporter ()
147+
148+ halfH := pageH / 2
149+ cardX := (pageW - idCardWidthMM ) / 2
150+ card1Y := (halfH - idCardHeightMM ) / 2
151+ card2Y := halfH + (halfH - idCardHeightMM )/ 2
152+
153+ if err := placePageInSlot (pdf , imp , & pages [0 ], cardX , card1Y , idCardWidthMM , idCardHeightMM ); err != nil {
154+ cleanup ()
155+ return "" , nil , fmt .Errorf ("front: %w" , err )
156+ }
157+ if err := placePageInSlot (pdf , imp , & pages [1 ], cardX , card2Y , idCardWidthMM , idCardHeightMM ); err != nil {
158+ cleanup ()
159+ return "" , nil , fmt .Errorf ("back: %w" , err )
160+ }
161+
162+ outPath := filepath .Join (tmpDir , "idcard_composed.pdf" )
163+ if err := pdf .OutputFileAndClose (outPath ); err != nil {
164+ cleanup ()
165+ return "" , nil , err
166+ }
167+ return outPath , cleanup , nil
168+ }
169+
170+ pageW , pageH = 210.0 , 297.0
134171 pdf := gofpdf .New ("P" , "mm" , "A4" , "" )
135172 pdf .SetMargins (0 , 0 , 0 )
136173 pdf .SetAutoPageBreak (false , 0 )
137174 pdf .AddPage ()
138175
139176 imp := gofpdi .NewImporter ()
140177
141- pageW , pageH := 210.0 , 297.0
142178 halfH := pageH / 2
143179 cardX := (pageW - idCardWidthMM ) / 2
144180 card1Y := (halfH - idCardHeightMM ) / 2
0 commit comments