commit 7d0eeff739a65d036ef891665d0cb4c56aa8378e Author: Francois Pelletier Date: Wed Dec 28 00:04:27 2022 -0500 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85e7c1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d8a74dd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM python:3.10-slim + +# Install system dependencies +RUN apt-get update + +RUN apt-get install -y \ + pandoc\ + imagemagick \ + lmodern + + +RUN apt-get install -y \ + texlive-latex-base \ + texlive-latex-recommended \ + texlive-latex-extra \ + texlive-fonts-recommended \ + texlive-fonts-extra \ + texlive-lang-french \ + texlive-luatex + +# Set the working directory +WORKDIR /app + +# Copy the requirements file +COPY requirements.txt . + +# Install Python dependencies +RUN pip install -r requirements.txt + +# Copy the application code +COPY . . + +# Policy for ImageMagick + +COPY conf/policy.xml /etc/ImageMagick-6/policy.xml + +# Expose the application port +EXPOSE 8000 + +# Run the application +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/build-local.sh b/build-local.sh new file mode 100644 index 0000000..654dad7 --- /dev/null +++ b/build-local.sh @@ -0,0 +1 @@ +docker build -t local/fabriquedoc . \ No newline at end of file diff --git a/conf/policy.xml b/conf/policy.xml new file mode 100644 index 0000000..4815b2c --- /dev/null +++ b/conf/policy.xml @@ -0,0 +1,99 @@ + + + + + + ]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docker-run.sh b/docker-run.sh new file mode 100644 index 0000000..18f4d04 --- /dev/null +++ b/docker-run.sh @@ -0,0 +1,8 @@ +#!/usr/bin/zsh + +#!/usr/bin/zsh + +docker stop fabriquedoc +docker rm fabriquedoc +# Ce programme sert à lancer le job_dispatcher dans un docker localement pour tester +docker run -p 8080:8080 --name fabriquedoc --network host local/fabriquedoc \ No newline at end of file diff --git a/font/GlacialIndifference/GlacialIndifference-Bold.otf b/font/GlacialIndifference/GlacialIndifference-Bold.otf new file mode 100644 index 0000000..8b342c5 Binary files /dev/null and b/font/GlacialIndifference/GlacialIndifference-Bold.otf differ diff --git a/font/GlacialIndifference/GlacialIndifference-Regular.otf b/font/GlacialIndifference/GlacialIndifference-Regular.otf new file mode 100644 index 0000000..5c002ff Binary files /dev/null and b/font/GlacialIndifference/GlacialIndifference-Regular.otf differ diff --git a/font/GlacialIndifference/SIL Open Font License.txt b/font/GlacialIndifference/SIL Open Font License.txt new file mode 100644 index 0000000..14c043d --- /dev/null +++ b/font/GlacialIndifference/SIL Open Font License.txt @@ -0,0 +1,41 @@ +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others. + +The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the copyright statement(s). + +"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment. + +"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission. + +5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. \ No newline at end of file diff --git a/font/SourceCodePro/LICENSE.txt b/font/SourceCodePro/LICENSE.txt new file mode 100755 index 0000000..d154618 --- /dev/null +++ b/font/SourceCodePro/LICENSE.txt @@ -0,0 +1,93 @@ +Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. + +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/font/SourceCodePro/ReadMe.html b/font/SourceCodePro/ReadMe.html new file mode 100755 index 0000000..1aeb775 --- /dev/null +++ b/font/SourceCodePro/ReadMe.html @@ -0,0 +1,72 @@ + + + + Read Me File for Adobe® OpenType® Fonts + + + +

Adobe® OpenType® Fonts

+

Thank +you for licensing Adobe OpenType fonts. In order to ensure that you +have the most up-to-date product information, Adobe has posted an OpenType +Read Me file on the Adobe web site that contains information such +as minimum system requirements, technical support contact information +and software installation notes. We have also posted an OpenType +User's Guide in PDF format on the Adobe web site that can be +viewed online and downloaded to your computer.

If you have +licensed an Adobe OpenType Pro font, there may be additional PDF +documents, such as a specimen book, a glyph complement showing, and a +typeface-specific Read Me file, available on the typeface’s +product pages on the Adobe web site. These additional files may be +viewed online or downloaded to your computer.

To get you started +quickly, below are links to localized installation instructions for +your fonts. + +

Installation Instructions


+

English
+Instructions for installing this font can be found online at http://www.adobe.com/type/browser/fontinstall/instructions_main.html.

+

French / Français
+Le mode d'installation de cette police de caractère se trouve en +ligne à http://www.adobe.com/type/browser/fontinstall/instructions_main.html.

+

German / Deutsch
+Die Anweisungen zur Installation dieser Schriftart finden Sie online +unter http://www.adobe.com/type/browser/fontinstall/instructions_main.html.

+

Italian / Italiano
+Le istruzioni per l'installazione di questo font sono disponibili +online all'indirizzo http://www.adobe.com/type/browser/fontinstall/instructions_main.html.

+

Spanish / Español
+Las instrucciones para instalar esta fuente se pueden encontrar +online en http://www.adobe.com/type/browser/fontinstall/instructions_main.html.

+

Dutch / Hollands
+De instructies voor de installatie van dit lettertype vindt u op http://www.adobe.com/type/browser/fontinstall/instructions_main.html.

+

Swedish / Svenska
+Anvisningar för hur det här teckensnittet installeras finns +online på http://www.adobe.com/type/browser/fontinstall/instructions_main.html.

+

Norwegian / Norsk
+Instruksjoner for installering av skrifttypen finnes online på +http://www.adobe.com/type/browser/fontinstall/instructions_main.html.

+

Finnish / Suomi
+Ohjeet tämän fontin asentamiseen löytyvät +osoitteesta http://www.adobe.com/type/browser/fontinstall/instructions_main.html.

+

Danish / Dansk
+Du finder en vejledning i installation af denne skrifttype online +på adressen http://www.adobe.com/type/browser/fontinstall/instructions_main.html.

+

Japanese / 日本語
+このフォントをインストールする手順は、オンラインで http://www.adobe.com/type/browser/fontinstall/instructions_main.html +を参照してください。

+ + diff --git a/font/SourceCodePro/SourceCodePro-Black.ttf b/font/SourceCodePro/SourceCodePro-Black.ttf new file mode 100755 index 0000000..c793884 Binary files /dev/null and b/font/SourceCodePro/SourceCodePro-Black.ttf differ diff --git a/font/SourceCodePro/SourceCodePro-Bold.ttf b/font/SourceCodePro/SourceCodePro-Bold.ttf new file mode 100755 index 0000000..51823d9 Binary files /dev/null and b/font/SourceCodePro/SourceCodePro-Bold.ttf differ diff --git a/font/SourceCodePro/SourceCodePro-ExtraLight.ttf b/font/SourceCodePro/SourceCodePro-ExtraLight.ttf new file mode 100755 index 0000000..46d9982 Binary files /dev/null and b/font/SourceCodePro/SourceCodePro-ExtraLight.ttf differ diff --git a/font/SourceCodePro/SourceCodePro-Light.ttf b/font/SourceCodePro/SourceCodePro-Light.ttf new file mode 100755 index 0000000..56ecda6 Binary files /dev/null and b/font/SourceCodePro/SourceCodePro-Light.ttf differ diff --git a/font/SourceCodePro/SourceCodePro-Regular.ttf b/font/SourceCodePro/SourceCodePro-Regular.ttf new file mode 100755 index 0000000..3189898 Binary files /dev/null and b/font/SourceCodePro/SourceCodePro-Regular.ttf differ diff --git a/font/SourceCodePro/SourceCodePro-Semibold.ttf b/font/SourceCodePro/SourceCodePro-Semibold.ttf new file mode 100755 index 0000000..3c9b0e1 Binary files /dev/null and b/font/SourceCodePro/SourceCodePro-Semibold.ttf differ diff --git a/font/SourceCodePro/SourceCodeProReadMe.html b/font/SourceCodePro/SourceCodeProReadMe.html new file mode 100755 index 0000000..775774d --- /dev/null +++ b/font/SourceCodePro/SourceCodeProReadMe.html @@ -0,0 +1,230 @@ + + + + Read Me File for Source Code Pro + + + + + Read Me + + + + + + +
+

Source™ Code Pro

+
+ + +
+

This document contains late-breaking product information, updates, and troubleshooting tips.
+
+ Minimum system requirements
+ Font installation
+ Family information
+ Release Notes
+ Known issues
+ Customer care
+ Other resources
+
+

+
+

Minimum system requirements

+
+ +
+

Windows®

+
    +
  • Intel® Pentium,® Intel Centrino,® Intel Xeon,® or Intel Core™ Duo processor
  • +
  • Microsoft Windows 2000, Windows XP, Windows Vista™, or Windows 7
    +
  • +
  • 16 MB of RAM (32 MB recommended)
  • +
  • Note: + Fonts from Font Folio 11 may also be installed under Microsoft Windows 98, Windows Millennium Edition, + and Windows NT® 4.0 with Service Pack 4 if you install Adobe Type Manager® (ATM™) Light + 4.1 on your system. If using a PostScript® printer on Windows 98/ME, AdobePS™ printer + driver 4.3 or later is recommended. If using a PostScript printer + on Windows NT 4.0, AdobePS printer driver 5.1.2 or later is recommended.
  • +
+

Macintosh

+
    +
  • PowerPC® G4 or G5 or multicore Intel processor
  • +
  • Mac OS X
  • +
  • 16 MB of RAM (32 MB recommended)
  • +
  • If using a PostScript printer, the latest AdobePS printer driver is recommended.
  • +
  • Note: Fonts from Font Folio 11 may be installed under Mac OS 8.6 through 9.2 with ATM Light 4.6, + and under Classic mode in Mac OS X with ATM Light 4.6.2.
  • +
+
+ + + + +
+

For information on installing these fonts, see http://www.adobe.com/go/learn_fontinstall_en.

+
+ + +
+

History

+ Source Code Pro was designed by Paul D. Hunt as a companion to Source Sans. This complementary family was adapted from the Source design due to a request to create a monospaced version for coding applications. Source Code preserves the design features and vertical proportions of Source Sans, but alters the glyph widths so that they are uniform across all glyphs and weights. Although this family was designed specifically for coding environments, for which a regular weight will typically suffice, Source Code has been made available in the same weight range as the corresponding Source Sans design.

Source Code Pro currently supports a wide range of languages using the Latin script, and includes all the characters in the Adobe Latin 4 glyph set. As an open source project, it is expected that incremental updates will be made over time to extend glyph set coverage and functionality. Future releases are expected to add support for Greek and Cyrillic scripts, italics, and other features documented on the project page at Open@Adobe, which is hosted by SourceForge.net®. If you are interested in contributing to this open source project, please visit this project page for information on how to become involved. Source Code Pro can be adapted and redistributed according to the terms of the Open Font License (OFL) agreement. +

Menu Names And Style Linking

+ +

In many Windows® applications, instead of every font appearing on +the menu, fonts are grouped into style-linked sets, and only the name of +the base style font for a set is shown in the menu. The italic and the +bold weight fonts of the set (if any) are not shown in the font menu, but can still be +accessed by selecting the base style font, and then using the italic +and bold style buttons. In this family, such programs will show only the +following base style font names in the menu:

+

Source Code Pro
+Source Code Pro Black
+Source Code Pro ExtraLight
+Source Code Pro Light
+Source Code Pro Semibold

+

The other fonts in this family must be selected by choosing a menu name +and then a style option following the guide below.

+ + + + + + + + + + + + + + + + + +
Menu Name plus Style Option... selects this font
Source Code Pro [none] Source Code Pro Regular
Source Code Pro Bold Source Code Pro Bold
Source Code Pro ExtraLight [none] Source Code Pro ExtraLight
Source Code Pro Light [none] Source Code Pro Light
Source Code Pro Semibold [none] Source Code Pro Semibold
Source Code Pro Black [none] Source Code Pro Black
+

On the Mac OS, although each font appears as a separate entry on the +font menu, users may also select fonts by means of style links. +Selecting a base style font and then using the style links (as described +above for Windows) enhances cross-platform document compatibility with +many applications, such as Microsoft® Word and Adobe PageMaker®, +although it is unnecessary with more sophisticated Adobe applications +such as recent versions of Illustrator®, Photoshop® or +InDesign®.

+

One should not, however, select a base font which has no style-linked +variant, and then use the bold or italic styling button. Doing so will +either have no effect, or result in programmatic bolding or slanting of +the base font, which will usually produce inferior screen and print +results.

+
+ +
+

For all fonts of family Source Code Pro : version 1.009 created on Thu Sep 20 16:40:47 2012.

+

version 1.009 created 2012/09/20

+
    +
  • First release.
  • +
+
+ + +
+
  • Some glyphs in the font cannot be accessed unless you are using an OpenType-savvy application. +
  • +
+
+ + + +
+

Customer Service
+ Adobe Customer Service provides assistance with product information, sales, registration, and other non-technical issues. To find out how to contact Adobe Customer Service, please visit Adobe.com for your region or country and click on Contact.

+

Support Plan Options and Technical Resources
+ If you require technical assistance for your product, including information on free and paid support options and troubleshooting resources, more information is available at http://www.adobe.com/go/support/. Outside of North America, go to http://www.adobe.com/go/intlsupport/. Free troubleshooting resources include Adobe’s support knowledgebase, Adobe user-to-user forums and more.

+
+ + + + +
+
+ © 2012 Adobe Systems Incorporated. All rights reserved. +
+ + + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..3aa2dfa --- /dev/null +++ b/main.py @@ -0,0 +1,115 @@ +import datetime +import logging + +from fastapi import FastAPI +from fastapi.responses import FileResponse +from pydantic import BaseModel +import pypandoc +import json +import httpx +from fastapi.testclient import TestClient +import os +from wand.image import Image +from wand.color import Color +import shutil + + +class DocumentSpecs(BaseModel): + format: str + style: str + linkcolor: str + tocdepth: int + pdfengine: str + content: str + fontsize: int + paperwidth: int + paperheight: int + margin: int + extension: str + +def convert_pdf_jpg(filename, output_path, resolution=300): + """ Convert a PDF into images. + + All the pages will give a single png file with format: + {pdf_filename}-{page_number}.png + + The function removes the alpha channel from the image and + replace it with a white background. + """ + all_pages = Image(filename=filename, resolution=resolution) + for i, page in enumerate(all_pages.sequence): + with Image(page) as img: + img.format = 'jpg' + 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 = os.path.join(output_path, image_filename) + + img.save(filename=image_filename) + +app = FastAPI() + + +@app.get("/generer/") +async def generer(specs: DocumentSpecs): + header_file = f'{os.getcwd()}/styles/{specs.style}/{specs.format}/header.tex' + cover_file = f'{os.getcwd()}/styles/{specs.style}/{specs.format}/cover.tex' + datef = datetime.datetime.now().strftime("%m-%d-%Y") + output_file = f"./{specs.style}-{specs.format}-{datef}-output.pdf" + filters = [] + pdoc_args = [ + f'--include-in-header={header_file}', + f'--include-after-body={cover_file}', + '--listings', + '--dpi=300', + f'--toc-depth={specs.tocdepth}', + f'--pdf-engine={specs.pdfengine}', + '-V',f'linkcolor={specs.linkcolor}', + '-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' + ] + try: + logging.info("Dossier courant = " + os.getcwd()) + + result = pypandoc.convert_text(source=specs.content, + to='pdf', + format='markdown+implicit_figures+smart', + encoding='utf-8', + extra_args=pdoc_args, + filters=filters, + cworkdir=os.getcwd(), + outputfile=output_file + ) + + except RuntimeError as rerr: + logging.exception(rerr) + except OSError as oerr: + logging.exception(oerr) + if specs.extension=="zip": + 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) + shutil.make_archive(zip_filename, 'zip', png_output_dir) + shutil.rmtree(png_output_dir) + except Exception as e: + logging.exception(e) + return FileResponse(zip_filename+".zip") + elif specs.extension=="pdf": + return FileResponse(output_file) + else: + return 0 + +client = TestClient(app) + + +def test_generer(): + test_json = json.read("test.json") + response = client.get("/generer/", json=test_json) + assert response.status_code == 200 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8ff15f4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,26 @@ +h11~=0.14.0 +pip~=21.3.1 +wheel~=0.37.1 +PyYAML~=6.0 +anyio~=3.6.2 +sniffio~=1.3.0 +click~=8.1.3 +httpcore~=0.16.3 +idna~=3.4 +rfc3986~=1.5.0 +certifi~=2022.12.7 +pandoc~=2.3 +ply~=3.11 +plumbum~=1.8.0 +uvloop~=0.17.0 +fastapi~=0.88.0 +starlette~=0.22.0 +pydantic~=1.10.2 +websockets~=10.4 +uvicorn~=0.20.0 +httptools~=0.5.0 +watchfiles~=0.18.1 +httpx~=0.23.1 +setuptools~=60.2.0 +pypandoc~=1.10 +Wand~=0.6.10 \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..76ea2df --- /dev/null +++ b/run.sh @@ -0,0 +1 @@ +uvicorn main:app --reload \ No newline at end of file diff --git a/styles/jevalideca/a4paper/cover.tex b/styles/jevalideca/a4paper/cover.tex new file mode 100644 index 0000000..6eaae02 --- /dev/null +++ b/styles/jevalideca/a4paper/cover.tex @@ -0,0 +1,27 @@ +\newpage + +\thispagestyle{empty} + +\noindent Tu apprécies ? \emoji{red-heart} et partage !\newline + +\leavevmode \newline + +\noindent Certains droits réservés\ \ccbysa\ \newline \the\year{}\ -\ François Pelletier + +\leavevmode \newline + +\noindent Visite mon site web au \url{https://jevalide.ca} et mes réseaux sociaux au \url{https://linktr.ee/jevalideca} + +\leavevmode \newline + +\noindent \doclicenseThis + +\leavevmode \newline + +\noindent Publié le \today + +\leavevmode \newline + +\noindent Mise en page effectuée avec \LaTeX + +\pagebreak diff --git a/styles/jevalideca/a4paper/fonds_a4.pdf b/styles/jevalideca/a4paper/fonds_a4.pdf new file mode 100644 index 0000000..4952693 Binary files /dev/null and b/styles/jevalideca/a4paper/fonds_a4.pdf differ diff --git a/styles/jevalideca/a4paper/fonds_a4.png b/styles/jevalideca/a4paper/fonds_a4.png new file mode 100644 index 0000000..09e3aa4 Binary files /dev/null and b/styles/jevalideca/a4paper/fonds_a4.png differ diff --git a/styles/jevalideca/a4paper/fonds_a4.svg b/styles/jevalideca/a4paper/fonds_a4.svg new file mode 100644 index 0000000..cf52449 --- /dev/null +++ b/styles/jevalideca/a4paper/fonds_a4.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/styles/jevalideca/a4paper/header.tex b/styles/jevalideca/a4paper/header.tex new file mode 100644 index 0000000..5442312 --- /dev/null +++ b/styles/jevalideca/a4paper/header.tex @@ -0,0 +1,49 @@ +\usepackage[french]{babel} % Césure en français +\usepackage[autolanguage]{numprint} + +\usepackage[ + type={CC}, + modifier={by-sa}, + version={4.0}, +]{doclicense} + +\usepackage{wallpaper} +\makeatletter +\ULCornerWallPaper{1}{./styles/jevalideca/a4/fonds_a4.pdf} +\makeatother + +\usepackage{listings} + +\usepackage{xcolor} + +\lstset{ + basicstyle=\ttfamily, + numbers=left, + numberstyle=\footnotesize, + stepnumber=2, + numbersep=5pt, + backgroundcolor=\color{black!10}, + showspaces=false, + showstringspaces=false, + showtabs=false, + tabsize=2, + captionpos=b, + breaklines=true, + breakatwhitespace=true, + breakautoindent=true, + linewidth=\textwidth +} + +% Override default figure placement To be within the flow of the text rather +% than on it's own page. +\usepackage{float} +\makeatletter +\def\fps@figure{H} +\makeatother + +\usepackage{fontspec} + \setmainfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} + \setsansfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} + \setmonofont[Path=font/SourceCodePro/]{SourceCodePro-Regular.ttf} + +\usepackage{emoji} \ No newline at end of file diff --git a/styles/jevalideca/instagram/cover.tex b/styles/jevalideca/instagram/cover.tex new file mode 100644 index 0000000..bf12361 --- /dev/null +++ b/styles/jevalideca/instagram/cover.tex @@ -0,0 +1,17 @@ +\newpage + +\thispagestyle{empty} + +\noindent Tu apprécies ? \emoji{red-heart} et partage !\newline + +\noindent Certains droits réservés\newline\ccbysa\newline \the\year{}\ -\ François Pelletier + +\noindent Site web: \newline\url{https://jevalide.ca} + +\noindent Réseaux sociaux: \newline\url{https://linktr.ee/jevalideca} + +\noindent Publié le \today. + +\noindent Mise en page effectuée avec \LaTeX + +\pagebreak diff --git a/styles/jevalideca/instagram/fonds_instagram.pdf b/styles/jevalideca/instagram/fonds_instagram.pdf new file mode 100644 index 0000000..d772f96 Binary files /dev/null and b/styles/jevalideca/instagram/fonds_instagram.pdf differ diff --git a/styles/jevalideca/instagram/fonds_instagram.png b/styles/jevalideca/instagram/fonds_instagram.png new file mode 100644 index 0000000..94ecc6a Binary files /dev/null and b/styles/jevalideca/instagram/fonds_instagram.png differ diff --git a/styles/jevalideca/instagram/fonds_instagram.svg b/styles/jevalideca/instagram/fonds_instagram.svg new file mode 100644 index 0000000..0a5c1e0 --- /dev/null +++ b/styles/jevalideca/instagram/fonds_instagram.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/styles/jevalideca/instagram/header.tex b/styles/jevalideca/instagram/header.tex new file mode 100644 index 0000000..1c9b478 --- /dev/null +++ b/styles/jevalideca/instagram/header.tex @@ -0,0 +1,59 @@ +\usepackage[french]{babel} % Césure en français +\usepackage[autolanguage]{numprint} + +\usepackage[ + type={CC}, + modifier={by-sa}, + version={4.0}, +]{doclicense} + +\usepackage{xcolor} + +\usepackage{listings} + +\usepackage{geometry} + +\lstset{ + basicstyle=\ttfamily, + numbers=left, + numberstyle=\footnotesize, + stepnumber=2, + numbersep=5pt, + backgroundcolor=\color{black!10}, + showspaces=false, + showstringspaces=false, + showtabs=false, + tabsize=2, + captionpos=b, + breaklines=true, + breakatwhitespace=true, + breakautoindent=true, + linewidth=\textwidth +} + +\usepackage{wallpaper} +\makeatletter +\ULCornerWallPaper{1}{./styles/jevalideca/instagram/fonds_instagram.pdf} +\makeatother + +% Override default figure placement To be within the flow of the text rather +% than on it's own page. +\usepackage{float} +\makeatletter +\def\fps@figure{H} +\makeatother + +\pagenumbering{gobble} +\AddToHook{cmd/section/before}{\clearpage} +\AddToHook{cmd/subsection/before}{\clearpage} + +\usepackage{caption} +\DeclareCaptionLabelFormat{nolabel}{} +\captionsetup{labelformat=nolabel,textformat=empty} + +\usepackage{fontspec} + \setmainfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} + \setsansfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} + \setmonofont[Path=font/SourceCodePro/]{SourceCodePro-Regular.ttf} + +\usepackage{emoji} \ No newline at end of file diff --git a/styles/jevalideca/lettre/cover.tex b/styles/jevalideca/lettre/cover.tex new file mode 100644 index 0000000..6eaae02 --- /dev/null +++ b/styles/jevalideca/lettre/cover.tex @@ -0,0 +1,27 @@ +\newpage + +\thispagestyle{empty} + +\noindent Tu apprécies ? \emoji{red-heart} et partage !\newline + +\leavevmode \newline + +\noindent Certains droits réservés\ \ccbysa\ \newline \the\year{}\ -\ François Pelletier + +\leavevmode \newline + +\noindent Visite mon site web au \url{https://jevalide.ca} et mes réseaux sociaux au \url{https://linktr.ee/jevalideca} + +\leavevmode \newline + +\noindent \doclicenseThis + +\leavevmode \newline + +\noindent Publié le \today + +\leavevmode \newline + +\noindent Mise en page effectuée avec \LaTeX + +\pagebreak diff --git a/styles/jevalideca/lettre/fonds_lettre.pdf b/styles/jevalideca/lettre/fonds_lettre.pdf new file mode 100644 index 0000000..a4d679f Binary files /dev/null and b/styles/jevalideca/lettre/fonds_lettre.pdf differ diff --git a/styles/jevalideca/lettre/fonds_lettre.png b/styles/jevalideca/lettre/fonds_lettre.png new file mode 100644 index 0000000..f8bc9fb Binary files /dev/null and b/styles/jevalideca/lettre/fonds_lettre.png differ diff --git a/styles/jevalideca/lettre/fonds_lettre.svg b/styles/jevalideca/lettre/fonds_lettre.svg new file mode 100644 index 0000000..3e24812 --- /dev/null +++ b/styles/jevalideca/lettre/fonds_lettre.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/styles/jevalideca/lettre/header.tex b/styles/jevalideca/lettre/header.tex new file mode 100644 index 0000000..46c2723 --- /dev/null +++ b/styles/jevalideca/lettre/header.tex @@ -0,0 +1,49 @@ +\usepackage[french]{babel} % Césure en français +\usepackage[autolanguage]{numprint} + +\usepackage[ + type={CC}, + modifier={by-sa}, + version={4.0}, +]{doclicense} + +\usepackage{xcolor} + +\usepackage{listings} + +\lstset{ + basicstyle=\ttfamily, + numbers=left, + numberstyle=\footnotesize, + stepnumber=2, + numbersep=5pt, + backgroundcolor=\color{black!10}, + showspaces=false, + showstringspaces=false, + showtabs=false, + tabsize=2, + captionpos=b, + breaklines=true, + breakatwhitespace=true, + breakautoindent=true, + linewidth=\textwidth +} + +\usepackage{wallpaper} +\makeatletter +\ULCornerWallPaper{1}{./styles/jevalideca/lettre/fonds_lettre.pdf} +\makeatother + +% Override default figure placement To be within the flow of the text rather +% than on it's own page. +\usepackage{float} +\makeatletter +\def\fps@figure{H} +\makeatother + +\usepackage{fontspec} + \setmainfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} + \setsansfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} + \setmonofont[Path=font/SourceCodePro/]{SourceCodePro-Regular.ttf} + +\usepackage{emoji} diff --git a/styles/jevalideca/linkedin/cover.tex b/styles/jevalideca/linkedin/cover.tex new file mode 100644 index 0000000..b248fc2 --- /dev/null +++ b/styles/jevalideca/linkedin/cover.tex @@ -0,0 +1,19 @@ +\newpage + +\thispagestyle{empty} + +\noindent Tu apprécies ? \emoji{red-heart} et partage !\newline + +\noindent Site web: \url{https://jevalide.ca} + +\noindent Réseaux sociaux: \newline\url{https://linktr.ee/jevalideca} + +\pagebreak + +\noindent Certains droits réservés\ \ccbysa \newline \the\year{}\ -\ François Pelletier + +\noindent Publié le \today. + +\noindent Mise en page effectuée avec \LaTeX + +\pagebreak diff --git a/styles/jevalideca/linkedin/fonds_linkedin.pdf b/styles/jevalideca/linkedin/fonds_linkedin.pdf new file mode 100644 index 0000000..32320e8 Binary files /dev/null and b/styles/jevalideca/linkedin/fonds_linkedin.pdf differ diff --git a/styles/jevalideca/linkedin/fonds_linkedin.png b/styles/jevalideca/linkedin/fonds_linkedin.png new file mode 100644 index 0000000..bd00de3 Binary files /dev/null and b/styles/jevalideca/linkedin/fonds_linkedin.png differ diff --git a/styles/jevalideca/linkedin/fonds_linkedin.svg b/styles/jevalideca/linkedin/fonds_linkedin.svg new file mode 100644 index 0000000..21e6605 --- /dev/null +++ b/styles/jevalideca/linkedin/fonds_linkedin.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/styles/jevalideca/linkedin/header.tex b/styles/jevalideca/linkedin/header.tex new file mode 100644 index 0000000..52ffe87 --- /dev/null +++ b/styles/jevalideca/linkedin/header.tex @@ -0,0 +1,53 @@ +\usepackage[french]{babel} % Césure en français +\usepackage[autolanguage]{numprint} + +\usepackage{ccicons} + +\usepackage{wallpaper} +\makeatletter +\ULCornerWallPaper{1}{./styles/jevalideca/linkedin/fonds_linkedin.pdf} +\makeatother + +\usepackage{xcolor} + +\usepackage{listings} + +\lstset{ + basicstyle=\ttfamily, + numbers=left, + numberstyle=\footnotesize, + stepnumber=2, + numbersep=5pt, + backgroundcolor=\color{black!10}, + showspaces=false, + showstringspaces=false, + showtabs=false, + tabsize=2, + captionpos=b, + breaklines=true, + breakatwhitespace=true, + breakautoindent=true, + linewidth=\textwidth +} + +% Override default figure placement To be within the flow of the text rather +% than on it's own page. +\usepackage{float} +\makeatletter +\def\fps@figure{H} +\makeatother + +\pagenumbering{gobble} +\AddToHook{cmd/section/before}{\clearpage} +\AddToHook{cmd/subsection/before}{\clearpage} + +\usepackage{caption} +\DeclareCaptionLabelFormat{nolabel}{} +\captionsetup{labelformat=nolabel,textformat=empty} + +\usepackage{fontspec} + \setmainfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} + \setsansfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} + \setmonofont[Path=font/SourceCodePro/]{SourceCodePro-Regular.ttf} + +\usepackage{emoji} \ No newline at end of file diff --git a/styles/jevalideca/slide169/cover.tex b/styles/jevalideca/slide169/cover.tex new file mode 100644 index 0000000..bf12361 --- /dev/null +++ b/styles/jevalideca/slide169/cover.tex @@ -0,0 +1,17 @@ +\newpage + +\thispagestyle{empty} + +\noindent Tu apprécies ? \emoji{red-heart} et partage !\newline + +\noindent Certains droits réservés\newline\ccbysa\newline \the\year{}\ -\ François Pelletier + +\noindent Site web: \newline\url{https://jevalide.ca} + +\noindent Réseaux sociaux: \newline\url{https://linktr.ee/jevalideca} + +\noindent Publié le \today. + +\noindent Mise en page effectuée avec \LaTeX + +\pagebreak diff --git a/styles/jevalideca/slide169/fonds_slide.pdf b/styles/jevalideca/slide169/fonds_slide.pdf new file mode 100644 index 0000000..0b1e11c Binary files /dev/null and b/styles/jevalideca/slide169/fonds_slide.pdf differ diff --git a/styles/jevalideca/slide169/fonds_slide.png b/styles/jevalideca/slide169/fonds_slide.png new file mode 100644 index 0000000..155099e Binary files /dev/null and b/styles/jevalideca/slide169/fonds_slide.png differ diff --git a/styles/jevalideca/slide169/fonds_slide.svg b/styles/jevalideca/slide169/fonds_slide.svg new file mode 100644 index 0000000..610c9c7 --- /dev/null +++ b/styles/jevalideca/slide169/fonds_slide.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/styles/jevalideca/slide169/header.tex b/styles/jevalideca/slide169/header.tex new file mode 100644 index 0000000..a0d76b6 --- /dev/null +++ b/styles/jevalideca/slide169/header.tex @@ -0,0 +1,57 @@ +\usepackage[french]{babel} % Césure en français +\usepackage[autolanguage]{numprint} + +\usepackage[ + type={CC}, + modifier={by-sa}, + version={4.0}, +]{doclicense} + +\usepackage{xcolor} + +\usepackage{listings} + +\lstset{ + basicstyle=\ttfamily, + numbers=left, + numberstyle=\footnotesize, + stepnumber=2, + numbersep=5pt, + backgroundcolor=\color{black!10}, + showspaces=false, + showstringspaces=false, + showtabs=false, + tabsize=2, + captionpos=b, + breaklines=true, + breakatwhitespace=true, + breakautoindent=true, + linewidth=\textwidth +} + +\usepackage{wallpaper} +\makeatletter +\ULCornerWallPaper{1}{./styles/jevalideca/slide169/fonds_slide.pdf} +\makeatother + +% Override default figure placement To be within the flow of the text rather +% than on it's own page. +\usepackage{float} +\makeatletter +\def\fps@figure{H} +\makeatother + +\pagenumbering{gobble} +\AddToHook{cmd/section/before}{\clearpage} +\AddToHook{cmd/subsection/before}{\clearpage} + +\usepackage{caption} +\DeclareCaptionLabelFormat{nolabel}{} +\captionsetup{labelformat=nolabel,textformat=empty} + +\usepackage{fontspec} + \setmainfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} + \setsansfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} + \setmonofont[Path=font/SourceCodePro/]{SourceCodePro-Regular.ttf} + +\usepackage{emoji} diff --git a/test_main.http b/test_main.http new file mode 100644 index 0000000..7c9fa77 --- /dev/null +++ b/test_main.http @@ -0,0 +1,59 @@ +# Test your FastAPI endpoints + +GET http://127.0.0.1:8000/generer/ +Content-Type: application/json +Accept: application/zip + +{ + "format": "instagram", + "style": "jevalideca", + "linkcolor": "blue", + "tocdepth": 2, + "pdfengine": "lualatex", + "content": "# Ceci est un titre\n## Ceci est un sous-titre\n\nCeci est un paragraphe\n\n## Ceci est un autre sous-titre\n\n> Ceci est du code", + "fontsize": 14, + "paperwidth": 1080, + "paperheight": 1920, + "margin": 180, + "extension": "zip" +} + +### + +GET http://127.0.0.1:8000/generer/ +Content-Type: application/json +Accept: application/pdf + +{ + "format": "linkedin", + "style": "jevalideca", + "linkcolor": "blue", + "tocdepth": 2, + "pdfengine": "lualatex", + "content": "# Ceci est un titre\n## Ceci est un sous-titre\n\nCeci est un paragraphe\n\n## Ceci est un autre sous-titre\n\n> Ceci est du code", + "fontsize": 14, + "paperwidth": 1080, + "paperheight": 1080, + "margin": 90, + "extension": "pdf" +} + +### + +GET http://127.0.0.1:8000/generer/ +Content-Type: application/json +Accept: application/pdf + +{ + "format": "slide169", + "style": "jevalideca", + "linkcolor": "blue", + "tocdepth": 2, + "pdfengine": "lualatex", + "content": "# Ceci est un titre\n## Ceci est un sous-titre\n\nCeci est un paragraphe\n\n## Ceci est un autre sous-titre\n\n> Ceci est du code", + "fontsize": 14, + "paperwidth": 1920, + "paperheight": 1080, + "margin": 90, + "extension": "pdf" +}