xlsx-to-pdf
Excel to PDF
Set a workbook on paper, a table to a sheet, with its headings on every page.
- Reads
- a workbook — application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
- Writes
- one file — PDFs
- Tool page
- /excel-to-pdf
Example
Print a workbook so the columns stay where the author put them.
Given
- accounts.xlsx — an Excel workbook
From code
import { loadDocument, runOperation } from '@pagecraft/core';
const accounts = await loadDocument({ bytes, name: 'accounts.xlsx' });
const [output] = await runOperation('xlsx-to-pdf', [accounts], {
orientation: 'landscape',
headings: true,
});
From a shell
pagecraft xlsx-to-pdf accounts.xlsx --orientation landscape
What comes back
One PDF, containing “Region”.
This example is run by the test suite. If it stopped being true, the build would fail.
Options
filename--filename
string
Filename
What the PDF will be called.
Default: ''
size--size
string, one of
Page size
Default: 'a4'
source— The size and margins in the file, or A4 with 20mm where it names none.a3— A3a4— A4a5— A5a6— A6b5— B5letter— Letterlegal— Legaltabloid— Tabloidexecutive— Executivecustom— Custom size
width--width
number
Width
Only when size is 'custom'.
Default: 210
height--height
number
Height
Only when size is 'custom'.
Default: 297
orientation--orientation
string, one of
Orientation
Default: 'landscape'
portrait— Portraitlandscape— Landscape
margin--margin
number
Margin
Default: 20
unit--unit
string, one of
Measured in
Default: 'mm'
mm— Millimetrescm— Centimetresin— Inchespt— Points
fontSize--font-size
number (pt)
Text size
Default: 11
lineHeight--line-height
number
Line spacing
A multiple of the text size. 1.4 is what a book uses.
Default: 1.4
align--align
string, one of
Alignment
Default: 'left'
left— Even word spacing; an uneven right edge.justify— Both edges flush; the word spacing stretches to do it.
font--font
string, one of
Typeface
Default: 'sans'
sans— Helvetica.serif— Times.mono— Courier.
fontFile--font-file
Uint8Array
Font file
A TrueType or OpenType font to set the text in. Needed for scripts the built-in fonts do not cover, unless the host supplies one.
headings--headings
boolean
First row names the columns
Sets it in bold and repeats it at the top of every page the table runs onto.
Default: true
What it cannot do
- Every sheet becomes a table, headed by the name on its tab, and starts on a new page. Print areas, page-break previews, frozen panes and the scaling set in Excel are not read.
- A cell is set as the text the workbook stored. A number formatted as a date, a currency or a percentage is set as the number underneath it, because the format is a rule Excel applies and not a value in the file.
- Formulas are not calculated. The value the workbook last saved is what is set; a formula never calculated is blank.
- Charts, pictures, shapes, conditional formatting, cell colours and borders are not read.
- A `.xls` from before 2007 is a different format altogether and cannot be read. Save it as `.xlsx` first.
- A table wider than the page has its columns squeezed together to fit rather than running off the edge, so a very wide table is more readable on landscape paper, or at a smaller text size.
- A cell holding more than will fit its column wraps inside it, which makes the row taller rather than the column wider.
- Text is set in the standard fonts every reader already carries, so the file renders identically on a machine that has none of your fonts installed. Anything they cannot draw needs a font file, which is embedded and subsetted into the PDF with it.
- A font file you supply is used for everything: bold, italic and monospaced text are all drawn in that one face rather than in a bold, italic or fixed-width cut of it. Code blocks and columns of figures lose their alignment as a result, so supply one only when the built-in fonts cannot draw your text.
- Shaping and joining come from the font itself, and nothing reorders a line: text is drawn in the order it is given, so a line mixing right-to-left and left-to-right writing comes out in that order rather than in reading order.