Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/extraction/tests/container-client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ assert.equal(
.segments[0].text,
'Compressed page text'
);
const wrappedTable = await send(
'pdf',
readFileSync(`${fixtures}/wrapped-table.pdf`)
);
assert.equal(wrappedTable.status, 200);
assert.equal(wrappedTable.value.segments.length, 1);
assert.equal(wrappedTable.value.segments[0].kind, 'page');
assert.equal(wrappedTable.value.segments[0].index, 1);
assert.deepEqual(wrappedTable.value.segments[0].text.trim().split(/\s+/), [
'Row',
'Alpha',
'Beta',
'Gamma',
'Delta',
]);
const docx = await send('docx', readFileSync(`${fixtures}/body.docx`));
assert.equal(docx.status, 200);
assert.deepEqual(docx.value.segments, [
Expand Down
25 changes: 25 additions & 0 deletions packages/extraction/tests/fixtures/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ def pdf(name, pages, compressed=False, padding=0):
with (root / name).open('wb') as file:
writer.write(file)

def wrapped_table_pdf():
# Adjacent cells wrap above and below the row label's baseline. Keep every
# word separate even when the extractor keeps the fragments on one line.
writer = PdfWriter()
page = writer.add_blank_page(width=612, height=792)
font = writer._add_object(DictionaryObject({
NameObject('/Type'): NameObject('/Font'), NameObject('/Subtype'): NameObject('/Type1'),
NameObject('/BaseFont'): NameObject('/Helvetica'),
NameObject('/Encoding'): NameObject('/WinAnsiEncoding'),
}))
page[NameObject('/Resources')] = DictionaryObject({NameObject('/Font'): DictionaryObject({NameObject('/F1'): font})})
stream = DecodedStreamObject()
stream.set_data(
b'BT /F1 10 Tf '
b'1 0 0 1 72 700 Tm (Row) Tj '
b'1 0 0 1 160 706 Tm (Alpha) Tj '
b'1 0 0 1 160 694 Tm (Beta) Tj '
b'1 0 0 1 240 706 Tm (Gamma) Tj '
b'1 0 0 1 240 694 Tm (Delta) Tj ET'
)
page[NameObject('/Contents')] = writer._add_object(stream)
with (root / 'wrapped-table.pdf').open('wb') as file:
writer.write(file)

wrapped_table_pdf()
pdf('pages.pdf', ['First page text', 'Second page text'])
pdf('compressed.pdf', ['Compressed page text'], True)
pdf('empty.pdf', [''])
Expand Down
Binary file added packages/extraction/tests/fixtures/wrapped-table.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/extraction/worker/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pypdf==6.21.4
pypdf==7.1.0
python-docx==1.2.0
lxml==6.1.3
typing_extensions==4.15.0
Loading