-
Notifications
You must be signed in to change notification settings - Fork 0
Add --dpi flag for PDF rendering resolution #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,3 +208,4 @@ cython_debug/ | |
| marimo/_static/ | ||
| marimo/_lsp/ | ||
| __marimo__/ | ||
| .subtask/ | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
| # "openai>=1.0", | ||||||||||||||||||||||||||||||||||||||||||||||||
| # "tenacity>=8", | ||||||||||||||||||||||||||||||||||||||||||||||||
| # "Pillow>=10", | ||||||||||||||||||||||||||||||||||||||||||||||||
| # "pdf2image>=1.16", | ||||||||||||||||||||||||||||||||||||||||||||||||
| # "pypdfium2>=4", | ||||||||||||||||||||||||||||||||||||||||||||||||
| # ] | ||||||||||||||||||||||||||||||||||||||||||||||||
| # /// | ||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -972,17 +972,21 @@ def image_to_base64(path: Path) -> str: | |||||||||||||||||||||||||||||||||||||||||||||||
| return f"data:{mime};base64,{b64}" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| def pdf_to_base64_images(path: Path) -> list[str]: | ||||||||||||||||||||||||||||||||||||||||||||||||
| """Convert PDF pages to base64 data URIs using pdf2image.""" | ||||||||||||||||||||||||||||||||||||||||||||||||
| from pdf2image import convert_from_path | ||||||||||||||||||||||||||||||||||||||||||||||||
| def pdf_to_base64_images(path: Path, dpi: int = 150) -> list[str]: | ||||||||||||||||||||||||||||||||||||||||||||||||
| """Convert PDF pages to base64 data URIs using pypdfium2.""" | ||||||||||||||||||||||||||||||||||||||||||||||||
| import pypdfium2 as pdfium | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| images = convert_from_path(str(path)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| doc = pdfium.PdfDocument(str(path)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| results = [] | ||||||||||||||||||||||||||||||||||||||||||||||||
| for img in images: | ||||||||||||||||||||||||||||||||||||||||||||||||
| for idx in range(len(doc)): | ||||||||||||||||||||||||||||||||||||||||||||||||
| page = doc[idx] | ||||||||||||||||||||||||||||||||||||||||||||||||
| bitmap = page.render(scale=dpi / 72) | ||||||||||||||||||||||||||||||||||||||||||||||||
| img = bitmap.to_pil() | ||||||||||||||||||||||||||||||||||||||||||||||||
| buf = io.BytesIO() | ||||||||||||||||||||||||||||||||||||||||||||||||
| img.save(buf, format="PNG") | ||||||||||||||||||||||||||||||||||||||||||||||||
| b64 = base64.b64encode(buf.getvalue()).decode("utf-8") | ||||||||||||||||||||||||||||||||||||||||||||||||
| results.append(f"data:image/png;base64,{b64}") | ||||||||||||||||||||||||||||||||||||||||||||||||
| doc.close() | ||||||||||||||||||||||||||||||||||||||||||||||||
| return results | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+979
to
990
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description mentions adding a
--dpiCLI flag and threading it through to this function. However, the implementation seems incomplete. Thedpiparameter is added here with a default value, but there's no--dpiflag in theruncommand, and the value is not passed down fromload_inputs. This means the PDF rendering resolution cannot be controlled from the CLI as intended. Please ensure the--dpiflag is added and its value is passed to this function.