Drop a file here
PDF (1 page), PNG, JPG
Uploads are off right now · the samples work
Or try a sample
Sources: U.S. National Archives · U.S. Census Bureau · CORD, NAVER Clova (CC BY 4.0) · NIST SD 2, converted to PDF (NIST data licence)
Files are deleted after 30 days and never used for training.
import io
import pandas as pd
from bs4 import BeautifulSoup
from hyperapi import HyperAPIClient
client = HyperAPIClient() # reads HYPERAPI_KEY from the environment
result = client.parse("report.pdf")
def placed_cells(html):
"""A born-digital page's table: one placed line per cell."""
rows = {}
for line in BeautifulSoup(html, "html.parser").select("span.line"):
style = dict(p.split(":", 1) for p in line["style"].split(";") if ":" in p)
top = round(float(style["top"].strip().removesuffix("pt")))
left = float(style["left"].strip().removesuffix("pt"))
rows.setdefault(top, []).append((left, line.get_text(" ", strip=True)))
grid = [[text for _, text in sorted(r)] for _, r in sorted(rows.items())]
return pd.DataFrame(grid[1:], columns=grid[0])
for block in result["result"]["blocks"]:
if block["type"] != "table":
continue
if "<table" in block["html"]: # scans and photos: an HTML table
df = pd.read_html(io.StringIO(block["html"]))[0]
else:
df = placed_cells(block["html"])
df.to_csv(f"{block['id']}.csv", index=False)Questions
No credit card. 30 pages free every month. Read the docs and ship today.