MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / png_to_pdf

Function png_to_pdf

utils/poster_eval_utils.py:999–1018  ·  view source on GitHub ↗

Convert a PNG image to a PDF file. Args: input_path: Path to the source .png file. output_path: Path where the resulting .pdf will be saved.

(input_path: str, output_path: str)

Source from the content-addressed store, hash-verified

997 return new_data
998
999def png_to_pdf(input_path: str, output_path: str) -> None:
1000 """
1001 Convert a PNG image to a PDF file.
1002
1003 Args:
1004 input_path: Path to the source .png file.
1005 output_path: Path where the resulting .pdf will be saved.
1006 """
1007 with Image.open(input_path) as img:
1008 # Convert image to RGB if it has an alpha channel
1009 if img.mode in ("RGBA", "LA") or (img.mode == "P" and "transparency" in img.info):
1010 background = Image.new("RGB", img.size, (255, 255, 255))
1011 if img.mode != "RGBA":
1012 img = img.convert("RGBA")
1013 background.paste(img, mask=img.split()[-1]) # use alpha channel as mask
1014 img = background
1015 else:
1016 img = img.convert("RGB")
1017
1018 img.save(output_path, "PDF", resolution=200.0)
1019
1020def extract_images_and_sections(md):
1021 parts = re.split(r'(## [^\n]+)', md)

Callers 1

gen_eval_markdownFunction · 0.70

Calls 2

convertMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected