changements pour flexibilité
This commit is contained in:
parent
4792add7f9
commit
bfa1f824ce
6 changed files with 49 additions and 11 deletions
2
install.sh
Normal file
2
install.sh
Normal file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
pip install -r requirements.txt
|
14
main.py
14
main.py
|
@ -25,9 +25,10 @@ class DocumentSpecs(BaseModel):
|
|||
paperwidth: int
|
||||
paperheight: int
|
||||
margin: int
|
||||
vmargin: int
|
||||
extension: str
|
||||
|
||||
def convert_pdf_jpg(filename, output_path, resolution=300):
|
||||
def convert_pdf(filename, filetype, output_path, resolution=300):
|
||||
""" Convert a PDF into images.
|
||||
|
||||
All the pages will give a single png file with format:
|
||||
|
@ -39,12 +40,12 @@ def convert_pdf_jpg(filename, output_path, resolution=300):
|
|||
all_pages = Image(filename=filename, resolution=resolution)
|
||||
for i, page in enumerate(all_pages.sequence):
|
||||
with Image(page) as img:
|
||||
img.format = 'jpg'
|
||||
img.format = filetype
|
||||
img.background_color = Color('black')
|
||||
#img.alpha_channel = 'remove'
|
||||
|
||||
image_filename = os.path.splitext(os.path.basename(filename))[0]
|
||||
image_filename = '{}-{}.jpg'.format(image_filename, i)
|
||||
image_filename = f'{image_filename}-{i}.{filetype}'
|
||||
image_filename = os.path.join(output_path, image_filename)
|
||||
|
||||
img.save(filename=image_filename)
|
||||
|
@ -70,7 +71,8 @@ async def generer(specs: DocumentSpecs):
|
|||
'-V',f'fontsize={specs.fontsize}pt',
|
||||
'-V',f'geometry:paperwidth={specs.paperwidth/300}in',
|
||||
'-V',f'geometry:paperheight={specs.paperheight/300}in',
|
||||
'-V',f'geometry:margin={specs.margin/300}in'
|
||||
'-V',f'geometry:margin={specs.margin/300}in',
|
||||
'-V',f'geometry:vmargin={specs.vmargin/300}in'
|
||||
]
|
||||
try:
|
||||
logging.info("Dossier courant = " + os.getcwd())
|
||||
|
@ -89,13 +91,13 @@ async def generer(specs: DocumentSpecs):
|
|||
logging.exception(rerr)
|
||||
except OSError as oerr:
|
||||
logging.exception(oerr)
|
||||
if specs.extension=="zip":
|
||||
if specs.extension in ["png","jpg"]:
|
||||
zip_filename = os.path.splitext(os.path.basename(output_file))[0]
|
||||
png_output_dir = "./png_output"
|
||||
if not os.path.exists(png_output_dir):
|
||||
os.mkdir(png_output_dir)
|
||||
try:
|
||||
convert_pdf_jpg(output_file, png_output_dir, resolution=300)
|
||||
convert_pdf(output_file, specs.extension, png_output_dir, resolution=300)
|
||||
shutil.make_archive(zip_filename, 'zip', png_output_dir)
|
||||
shutil.rmtree(png_output_dir)
|
||||
except Exception as e:
|
||||
|
|
|
@ -56,4 +56,8 @@
|
|||
\setsansfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf}
|
||||
\setmonofont[Path=font/SourceCodePro/]{SourceCodePro-Regular.ttf}
|
||||
|
||||
\usepackage{emoji}
|
||||
\usepackage{emoji}
|
||||
|
||||
\hyphenpenalty=10000
|
||||
\hbadness=10000
|
||||
\centering
|
||||
|
|
|
@ -50,4 +50,9 @@
|
|||
\setsansfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf}
|
||||
\setmonofont[Path=font/SourceCodePro/]{SourceCodePro-Regular.ttf}
|
||||
|
||||
\usepackage{emoji}
|
||||
\usepackage{emoji}
|
||||
|
||||
\hyphenpenalty=10000
|
||||
\hbadness=10000
|
||||
\centering
|
||||
|
||||
|
|
|
@ -50,4 +50,8 @@
|
|||
\setsansfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf}
|
||||
\setmonofont[Path=font/SourceCodePro/]{SourceCodePro-Regular.ttf}
|
||||
|
||||
\usepackage{emoji}
|
||||
\usepackage{emoji}
|
||||
|
||||
\hyphenpenalty=10000
|
||||
\hbadness=10000
|
||||
\centering
|
|
@ -15,7 +15,7 @@ Accept: application/zip
|
|||
"paperwidth": 1080,
|
||||
"paperheight": 1920,
|
||||
"margin": 180,
|
||||
"extension": "zip"
|
||||
"extension": "jpg"
|
||||
}
|
||||
|
||||
###
|
||||
|
@ -44,6 +44,27 @@ GET http://127.0.0.1:8000/generer/
|
|||
Content-Type: application/json
|
||||
Accept: application/pdf
|
||||
|
||||
{
|
||||
"format": "linkedin",
|
||||
"style": "missioncyber",
|
||||
"linkcolor": "blue",
|
||||
"tocdepth": 2,
|
||||
"pdfengine": "lualatex",
|
||||
"content": "# Comment améliorer ma sécurité informatique\n\n20 défis gratuits de 2 minutes chacun !",
|
||||
"fontsize": 20,
|
||||
"paperwidth": 1080,
|
||||
"paperheight": 1080,
|
||||
"margin": 180,
|
||||
"extension": "jpg",
|
||||
"vmargin": 300
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
GET http://127.0.0.1:8000/generer/
|
||||
Content-Type: application/json
|
||||
Accept: application/pdf
|
||||
|
||||
{
|
||||
"format": "slide169",
|
||||
"style": "jevalideca",
|
||||
|
@ -55,5 +76,5 @@ Accept: application/pdf
|
|||
"paperwidth": 1920,
|
||||
"paperheight": 1080,
|
||||
"margin": 90,
|
||||
"extension": "pdf"
|
||||
"extension": "jpg"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue