mirror of https://github.com/eyhc1/rendercv.git
docs: use `pdf_to_pngs` in `update_rendercv_files.py`
This commit is contained in:
parent
ec15f0ad3d
commit
ecb611108a
|
@ -11,7 +11,6 @@ from typing import Any
|
||||||
|
|
||||||
import pdfCropMargins
|
import pdfCropMargins
|
||||||
import ruamel.yaml
|
import ruamel.yaml
|
||||||
import pypdfium2
|
|
||||||
|
|
||||||
# Import rendercv. I import the data_models and renderer modules like this instead
|
# Import rendercv. I import the data_models and renderer modules like this instead
|
||||||
# of using `import rendercv` because in order for that to work, the current working
|
# of using `import rendercv` because in order for that to work, the current working
|
||||||
|
@ -191,7 +190,7 @@ def generate_entry_figures():
|
||||||
# moderncv theme does not support these options:
|
# moderncv theme does not support these options:
|
||||||
del design_dictionary["disable_page_numbering"]
|
del design_dictionary["disable_page_numbering"]
|
||||||
del design_dictionary["disable_last_updated_date"]
|
del design_dictionary["disable_last_updated_date"]
|
||||||
|
|
||||||
for entry_type, entry in entries.items():
|
for entry_type, entry in entries.items():
|
||||||
# Create the data model with only one section and one entry
|
# Create the data model with only one section and one entry
|
||||||
data_model = dm.RenderCVDataModel(
|
data_model = dm.RenderCVDataModel(
|
||||||
|
@ -236,18 +235,15 @@ def generate_entry_figures():
|
||||||
)
|
)
|
||||||
|
|
||||||
# Convert pdf to an image
|
# Convert pdf to an image
|
||||||
image_name = output_pdf_file_path.with_suffix(".png")
|
png_file_path = r.pdf_to_pngs(output_pdf_file_path)[0]
|
||||||
pdf = pypdfium2.PdfDocument(str(output_pdf_file_path.absolute()))
|
desired_png_file_path = output_pdf_file_path.with_suffix(".png")
|
||||||
page = pdf[0]
|
|
||||||
image = page.render(scale=5).to_pil()
|
|
||||||
|
|
||||||
# If the image exists, remove it
|
# If the image exists, remove it
|
||||||
if image_name.exists():
|
if desired_png_file_path.exists():
|
||||||
image_name.unlink()
|
desired_png_file_path.unlink()
|
||||||
|
|
||||||
image.save(image_name)
|
# Move the image to the desired location
|
||||||
|
png_file_path.rename(desired_png_file_path)
|
||||||
pdf.close()
|
|
||||||
|
|
||||||
# Remove the pdf file
|
# Remove the pdf file
|
||||||
output_pdf_file_path.unlink()
|
output_pdf_file_path.unlink()
|
||||||
|
@ -264,7 +260,12 @@ def generate_examples():
|
||||||
os.chdir(examples_directory_path)
|
os.chdir(examples_directory_path)
|
||||||
themes = dm.available_themes
|
themes = dm.available_themes
|
||||||
for theme in themes:
|
for theme in themes:
|
||||||
cli.cli_command_new("John Doe", theme)
|
cli.cli_command_new(
|
||||||
|
"John Doe",
|
||||||
|
theme,
|
||||||
|
dont_create_theme_source_files=True,
|
||||||
|
dont_create_markdown_source_files=True,
|
||||||
|
)
|
||||||
yaml_file_path = examples_directory_path / "John_Doe_CV.yaml"
|
yaml_file_path = examples_directory_path / "John_Doe_CV.yaml"
|
||||||
|
|
||||||
# Rename John_Doe_CV.yaml:
|
# Rename John_Doe_CV.yaml:
|
||||||
|
@ -296,11 +297,21 @@ def generate_examples():
|
||||||
shutil.rmtree(rendercv_output_directory)
|
shutil.rmtree(rendercv_output_directory)
|
||||||
|
|
||||||
# convert first page of the pdf to an image:
|
# convert first page of the pdf to an image:
|
||||||
pdf = pypdfium2.PdfDocument(str(new_pdf_file_path.absolute()))
|
png_file_paths = r.pdf_to_pngs(new_pdf_file_path)
|
||||||
page = pdf[0]
|
firt_page_png_file_path = png_file_paths[0]
|
||||||
image = page.render(scale=2).to_pil()
|
if len(png_file_paths) > 1:
|
||||||
image_path = image_assets_directory / f"{theme}.png"
|
# remove the other pages
|
||||||
image.save(image_path)
|
for png_file_path in png_file_paths[1:]:
|
||||||
|
png_file_path.unlink()
|
||||||
|
|
||||||
|
desired_png_file_path = image_assets_directory / f"{theme}.png"
|
||||||
|
|
||||||
|
# If the image exists, remove it
|
||||||
|
if desired_png_file_path.exists():
|
||||||
|
desired_png_file_path.unlink()
|
||||||
|
|
||||||
|
# Move the image to the desired location
|
||||||
|
firt_page_png_file_path.rename(desired_png_file_path)
|
||||||
|
|
||||||
|
|
||||||
def generate_schema():
|
def generate_schema():
|
||||||
|
|
Loading…
Reference in New Issue