@@ -7,16 +7,14 @@ const OutputType = {
77 DataUrlNewWindow : "dataurlnewwindow" , //opens the data uri in new window
88} ;
99
10- export {
11- OutputType ,
12- jsPDF
13- }
10+ export { OutputType , jsPDF } ;
1411
1512/**
1613 *
1714 * @param { {
1815 * outputType: OutputType | string
1916 * fileName: string,
17+ * orientationLandscape: boolean,
2018 * logo: {
2119 * src: string,
2220 * width: number,
@@ -249,14 +247,12 @@ function jsPDFInvoiceTemplate(props) {
249247 }
250248 currentHeight -= 2 ;
251249 } ;
252-
253250 var addTableBodyBoarder = ( lineHeight ) => {
254251 for ( let i = 0 ; i < param . invoice . header . length ; i ++ ) {
255252 if ( i === 0 ) doc . rect ( 10 , currentHeight , tdWidth , lineHeight ) ;
256253 else doc . rect ( tdWidth * i + 10 , currentHeight , tdWidth , lineHeight ) ;
257254 }
258255 } ;
259-
260256 var addTableHeader = ( ) => {
261257 if ( param . invoice . headerBorder ) addTableHeaderBoarder ( ) ;
262258
@@ -296,25 +292,35 @@ function jsPDFInvoiceTemplate(props) {
296292 //td border height
297293 currentHeight += 5 ;
298294
295+ //pre-increase currentHeight to check the height based on next row
296+ if ( index + 1 < tableBodyLength ) currentHeight += itemDesc . height ;
297+
299298 if (
300- ( param . orientationLandscape && currentHeight > 178 ) ||
301- ( currentHeight > 168 && doc . getNumberOfPages ( ) > 1 )
299+ param . orientationLandscape &&
300+ ( currentHeight > 185 ||
301+ ( currentHeight > 178 && doc . getNumberOfPages ( ) > 1 ) )
302302 ) {
303303 doc . addPage ( ) ;
304304 currentHeight = 10 ;
305305 if ( index + 1 < tableBodyLength ) addTableHeader ( ) ;
306306 }
307307
308308 if (
309- ( ! param . orientationLandscape && currentHeight > 265 ) ||
310- ( currentHeight > 255 && doc . getNumberOfPages ( ) > 1 )
309+ ! param . orientationLandscape &&
310+ ( currentHeight > 265 ||
311+ ( currentHeight > 255 && doc . getNumberOfPages ( ) > 1 ) )
311312 ) {
312313 doc . addPage ( ) ;
313314 currentHeight = 10 ;
314315 if ( index + 1 < tableBodyLength ) addTableHeader ( ) ;
315316 // else
316317 // currentHeight += pdfConfig.subLineHeight + 2 + pdfConfig.subLineHeight - 1; //same as in addtableHeader
317318 }
319+
320+ //reset the height that was increased to check the next row
321+ if ( index + 1 < tableBodyLength && currentHeight > 30 )
322+ // check if new page
323+ currentHeight -= itemDesc . height ;
318324 } ) ;
319325 // doc.line(10, currentHeight, docWidth - 10, currentHeight); //nese duam te shfaqim line ne fund te tabeles
320326
@@ -327,7 +333,7 @@ function jsPDFInvoiceTemplate(props) {
327333 currentHeight = 10 ;
328334 }
329335
330- if ( ! param . orientationLandscape && currentHeight + invDescSize > 260 ) {
336+ if ( ! param . orientationLandscape && currentHeight + invDescSize > 270 ) {
331337 doc . addPage ( ) ;
332338 currentHeight = 10 ;
333339 }
@@ -350,7 +356,7 @@ function jsPDFInvoiceTemplate(props) {
350356 // currentHeight += pdfConfig.subLineHeight;
351357 doc . setFontSize ( pdfConfig . labelTextSize ) ;
352358
353- // if (currentHeight > 250 && doc.getNumberOfPages() > 1) {
359+ //add num of pages at the bottom
354360 if ( doc . getNumberOfPages ( ) > 1 ) {
355361 for ( let i = 1 ; i <= doc . getNumberOfPages ( ) ; i ++ ) {
356362 doc . setFontSize ( pdfConfig . fieldTextSize - 2 ) ;
@@ -397,6 +403,7 @@ function jsPDFInvoiceTemplate(props) {
397403 } ;
398404 addInvoiceDesc ( ) ;
399405
406+ //add num of page at the bottom
400407 if ( doc . getNumberOfPages ( ) === 1 && param . pageEnable ) {
401408 doc . setFontSize ( pdfConfig . fieldTextSize - 2 ) ;
402409 doc . setTextColor ( colorGray ) ;
@@ -409,7 +416,10 @@ function jsPDFInvoiceTemplate(props) {
409416 }
410417
411418 if ( param . outputType === "save" ) doc . save ( param . fileName ) ;
412- else doc . output ( param . outputType , { filename : param . fileName } ) ;
419+ else
420+ doc . output ( param . outputType , {
421+ filename : param . fileName ,
422+ } ) ;
413423
414424 return {
415425 pageNumber : doc . getNumberOfPages ( ) ,
0 commit comments