Skip to content

Create a simple grid to align objects in jsPDF generated documents

Notifications You must be signed in to change notification settings

cour64/jsPDF-GenerateGrid

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

jsPDF-GenerateGrid

Use a basic grid to align text in jsPDF created documents.

Returns an object of page coordinates.

  • aWidth: available width (the width of the page minus the page margins)
  • aHeight: available height (the height of the page minus the page margins)
  • hCenter: horizontal center
  • vCenter: vertical center
  • cols: array of column objects with the start (x), center (xc), and end (xe) of each column. Use those coordinates to align text as needed.

Example

doc = new jsPDF({ format: 'letter' });

myGrid = doc.generateGrid({ columns: 12, pageMargin: 5, columnMargin: 2 });

col = myGrid.cols;

Alignment

doc.setFontStyle('bold');

doc.text(col[3].x, 10, 'Regular text');
doc.text(col[4].xc, 20, 'Centered text', { align: 'center' });
doc.text(col[5].xe, 30, 'Right-aligned text', { align: 'right' });

Draw lines

doc.line(col[2].x, 5 - 4, col[5].xe, 5 - 4);

About

Create a simple grid to align objects in jsPDF generated documents

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%