pdf-to-docx
PDF to Word
Turn a PDF into a Word document with real paragraphs, headings and tables.
- Reads
- a PDF — application/pdf
- Writes
- one file — Word documents
- Tool page
- /pdf-to-word
Example
Hand a document to somebody who works in Word.
Given
- report.pdf — a PDF of written text
From code
import { loadDocument, runOperation } from '@pagecraft/core';
const report = await loadDocument({ bytes, name: 'report.pdf' });
const [output] = await runOperation('pdf-to-docx', [report], {
headings: true,
tables: true,
});
From a shell
pagecraft pdf-to-docx report.pdf
What comes back
One Word document.
This example is run by the test suite. If it stopped being true, the build would fail.
Options
pages--pages
string, a page selection: '1-3, 7, 9-', 'even', 'last'
Pages
Which pages to convert.
Default: 'all'
headings--headings
boolean
Find headings
Treat larger and bolder lines as headings.
Default: true
tables--tables
boolean
Find tables
Turn ruled and aligned columns into Word tables.
Default: true
images--images
boolean
Keep pictures
Carry the pictures across, at the resolution the PDF stored them.
Default: true
pageBreaks--page-breaks
boolean
Break at page ends
Start a new page in Word wherever the PDF started one.
Default: true
What it cannot do
- This is a conversion, not a round trip. It gives back an editable document that says what the PDF said; it does not give back the page, and the two will not look the same side by side.
- A PDF does not record what was a heading, a list or a table; it records type at sizes in places. All of that is inferred from the page, and a page laid out unusually will be read unusually.
- The faces, sizes, colours and exact positions of the original are not carried across, and neither is anything drawn rather than typed: a chart, a logo outline, a signature.
- A picture comes across at the resolution the PDF stored and the size the page drew it, in the place a reader would have met it — but a picture the text wrapped around lands after that text rather than beside it.
- Scans stored as CCITT fax, JBIG2 or JPEG 2000 are left out: Word cannot read any of them.
- A scanned page holds a picture of words. Run OCR over it first, or the document will come back with the pictures and none of the text.