Skip to content
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

pdfium: use the variables rather than literal constants #412

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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: 7 additions & 8 deletions src/nv_ingest/util/pdf/pdfium.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import numpy as np
import pypdfium2 as pdfium
import pypdfium2.raw as pdfium_c
from numpy import dtype
from numpy import ndarray
from PIL import Image
Expand All @@ -19,13 +20,12 @@

logger = logging.getLogger(__name__)

# Mapping based on the FPDF_PAGEOBJ_* constants
PDFIUM_PAGEOBJ_MAPPING = {
1: "TEXT", # FPDF_PAGEOBJ_TEXT
2: "PATH", # FPDF_PAGEOBJ_PATH
3: "IMAGE", # FPDF_PAGEOBJ_IMAGE
4: "SHADING", # FPDF_PAGEOBJ_SHADING
5: "FORM", # FPDF_PAGEOBJ_FORM
pdfium_c.FPDF_PAGEOBJ_TEXT: "TEXT",
pdfium_c.FPDF_PAGEOBJ_PATH: "PATH",
pdfium_c.FPDF_PAGEOBJ_IMAGE: "IMAGE",
pdfium_c.FPDF_PAGEOBJ_SHADING: "SHADING",
pdfium_c.FPDF_PAGEOBJ_FORM: "FORM",
}


Expand All @@ -45,8 +45,7 @@ def convert_bitmap_to_corrected_numpy(bitmap: pdfium.PdfBitmap) -> np.ndarray:
A NumPy array representing the correctly formatted image data.
"""
# Get the bitmap format information
bitmap_info = bitmap.get_info()
mode = bitmap_info.mode # Use the mode to identify the correct format
mode = bitmap.mode # Use the mode to identify the correct format

# Convert to a NumPy array using the built-in method
img_arr = bitmap.to_numpy()
Expand Down