diff --git a/README.md b/README.md index 0b21f34..98feaa2 100644 --- a/README.md +++ b/README.md @@ -22,16 +22,30 @@ cd zine_maker # Requirements Basic requirements are listed here. -Python3 should be installed on the computer -https://www.python.org/downloads/ - -And also the pip command if it didn't get installed with Python +- Terminal + - for MacOS and Linux, it comes together with the system, we can find the application by searching for terminal + - for Windows 10 and 11 follow the steps here (can you find a howto in Korean?) +- command line tool pdftk + - for MacOS we can download it from https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg + - for Linux we can install with sudo apt install poppler-utils + - for windows we can download it from https://pdftk.en.softonic.com/?ex=RAMP-1768.1 +- Python3 should be installed in the computer +Check by opening the terminal and run `python -i` +- And also the pip command if it didn't get installed with Python https://pip.pypa.io/en/stable/installation/ Once these are installed, from within zine_maker folder run: `pip install -r requirements.txt` +## Language +for non latin languages, you need to add language specific fonts in the `fonts` folder. At the moment there are Chinese and Korean fonts. + +## Images +For making use of images in the script +image magick needs to be installed +http://www.imagemagick.org/ + # Run the code! ## Parameters @@ -50,7 +64,38 @@ The python scripts `cover.py`, `body.py` and `colophon.py` take a text file as i from the root of the folder run: `python colophon.py` -The pdf is saved in the `output` folder. +The pdf documents are saved in the `output` folder. + +## Final PDF +For merging the cover, body and colophon pdf files, there are many pdf merger tools. One that is command line based and is used in this tutorial is pdfunite +http://linux-commands-examples.com/pdfunite + +from the root directory run: +`pdfunite covers/cover.pdf body/body.pdf colophons/colophon.pdf output/final.pdf` +You shall substitute the file paths to your own corresponding /path/filenames + +## See this readme as the generated pdf zine: +open the file output/zinemaker.pdf + +## Print +For preparing the final pdf for printing you need the pdfseparate command +http://www.linux-commands-examples.com/pdfseparate + +Run from the root directory: +``` +python book.py `output/final.pdf` `output/print_final.pdf` +``` + +## Prepare pages for printing + +./images/printer_settings.png + +In the printer settings opt-in for the following settings: +``` +- A4 Landscape +- Two pages per side +- Double side - short edge +``` To make your own zine modify the text files for the cover, for the body and for the colophon in the input folder. Or provide your own files with the full pathname: @@ -58,15 +103,17 @@ for example run: `python body.py /.txt /.pdf` ## Add images in the zine -`python doc_pdf.py text/images.txt body/images.pdf` +You need to add in your input text file the path of your image. +For example if you add images in the `image` folder you can add them in the `input/body.txt` as `./images/.jpg. You can also give the full path of your system font. +See the `input/images.txt` as an example of how to add images in your content. # Miscellaneous ## Fonts The source code comes with some fonts under the fonts folder. You can use your fonts of preference by adding them either in the fonts folder and edit the -files cover.py, colophon.py and doc_pdf.py to give the new names. Or add your -absolute font path directly to the python scripts. +files cover.py, colophon.py and body.py to give the new names. Or add your +absolute font path directly in the python scripts. ## Text The input texts should be clean from characters added by some text editors or @@ -88,70 +135,6 @@ https://www.cyberciti.biz/faq/sed-remove-m-and-line-feeds-under-unix-linux-bsd-a ## Layout All the font styling happens in the zine_maker function create_pages(). The input text is parsed for specific tags or symbols in the begining of each line -and changes to the font color and size happen accordingly. We can add more or edit -existing rules, directly in the zine_maker code. - -## Merge -For merging the cover, body and colophon pdf files, there are many pdf merger tools. One that is command line based and is used in this tutorial is pdfunite -http://linux-commands-examples.com/pdfunite - -## Print -For shuffling the final pdf and prepare it for printing you need the pdfseparate command -http://www.linux-commands-examples.com/pdfseparate -it is used inside the shuffle_pdf.py file (see details at the end of this README). - -## Images -For making use of images in the script -image magick needs to be installed -http://www.imagemagick.org/ - -## Make the cover of the pdf -Same, the default parameters included in the script would create the cover for the zine_maker: -`python cover.py` - -OR try-out the other cover samples: - -`python cover.py text/cover.txt covers/cover.pdf` - -OR add your cover text file and replace respectively: - -`python cover.py text/.txt covers/.pdf` - -## Make the colophon of the pdf -Same, the default parameters included in the script would create the colophon for the zine_maker: -`python colophon.py ` - -OR try-out the other colophon samples: - -`python colophon.py text/colophon.txt colophons/colophon.pdf` - -OR add your own colophon text file and replace respectively: - -`python colophon.py text/.txt colophons/.pdf` - -# Make a screen PDF - -## For the final screen version -from the terminal run: - -`pdfunite covers/cover.pdf body/body.pdf colophons/colophon.pdf zines/final.pdf` - -You shall substitute the file paths to your own corresponding /path/filenames - -## See this readme as the generated screen version zine: -open the file zines/zinemaker.pdf - -# Make a zine - -## Prepare signatures for printing - -./thumbs/printer_settings.png - -Default parameters: as input "zines/zinemaker_screen.pdf" and as output "zinemaker{random_number}.pdf" -Run it for your own pdf files as following: -`python shuffle_pdf.py` .pdf .pdf` - -In the printer settings opt-in for the following settings: -- A4 Landscape -- Two pages per side -- Double side - short edge +and changes to the font color and size happen accordingly. We can add more or edit existing rules, directly in the zine_maker code. +To add new functions for text style visit the [fpdf2 text documentation](https://py-pdf.github.io/fpdf2/TextStyling.html) +To add new functions for drawing shapes visit the [fpdf2 drawing documentation](https://py-pdf.github.io/fpdf2/fpdf/drawing.html) diff --git a/body.py b/body.py index b9c9eef..c236db3 100644 --- a/body.py +++ b/body.py @@ -20,22 +20,21 @@ def make(inputfile, output): zine = Zine(orientation="P", unit="mm", format="A5") # text font - zine.add_font( - 'chinese', '', - r"fonts/tinming.ttf" - ) + zine.add_font( 'chinese', '', r"fonts/tinming.ttf") + zine.add_font( 'korean', '', r"fonts/GmarketSansTTFMedium.ttf") zine.add_font('english', '', r"./fonts/CasaletwoNbp-Bp4V.ttf") header_font = 'CasaleNBP' - #header_font = 'Kpalter' english_font = 'english' chinese_font = 'chinese' + korean_font = 'korean' zine.set_font(english_font, '', size=text_font_size) zine.set_text_shaping(True) zine.create_pages(inputfile, max_height, left_margin, left_max_margin, top_margin, right_margin, cell_width, cell_height, cell_header_height, - header_font, english_font, chinese_font, text_font_size) + header_font, english_font, chinese_font, korean_font, + text_font_size) zine.output(output) print("PDF saved as {}".format(output)) diff --git a/shuffle_pdf.py b/book.py similarity index 95% rename from shuffle_pdf.py rename to book.py index 68c8664..48b78d8 100644 --- a/shuffle_pdf.py +++ b/book.py @@ -13,7 +13,6 @@ from zine_maker import Zine def shuffle_zine(finput, foutput): - # set font for all text zine = Zine(orientation="P", unit="mm", format="A5") chapter_list = zine.shuffle_chapters(finput) @@ -36,6 +35,8 @@ def shuffle_zine(finput, foutput): print("PDF saved as {}".format(foutput)) os.system("mv ./*_chapter.pdf ./.tmp") os.system("rm ./.tmp/*_chapter.pdf") + os.system("rm ./doc_data.txt") + os.system("rm ./chapters.txt") if __name__ == '__main__': diff --git a/fonts/GmarketSansTTFBold.ttf b/fonts/GmarketSansTTFBold.ttf new file mode 100644 index 0000000..0d20d4a Binary files /dev/null and b/fonts/GmarketSansTTFBold.ttf differ diff --git a/fonts/GmarketSansTTFLight.ttf b/fonts/GmarketSansTTFLight.ttf new file mode 100644 index 0000000..f315bd3 Binary files /dev/null and b/fonts/GmarketSansTTFLight.ttf differ diff --git a/fonts/GmarketSansTTFMedium.ttf b/fonts/GmarketSansTTFMedium.ttf new file mode 100644 index 0000000..2ac3b7f Binary files /dev/null and b/fonts/GmarketSansTTFMedium.ttf differ diff --git a/images/printer_settings.png b/images/printer_settings.png new file mode 100644 index 0000000..8a07bff Binary files /dev/null and b/images/printer_settings.png differ diff --git a/input/blank.pdf b/input/blank.pdf new file mode 100644 index 0000000..01fb22e Binary files /dev/null and b/input/blank.pdf differ diff --git a/input/korean.txt b/input/korean.txt new file mode 100644 index 0000000..ea55e04 --- /dev/null +++ b/input/korean.txt @@ -0,0 +1,3 @@ +# test korean + +## 한국어 diff --git a/output/korean.pdf b/output/korean.pdf new file mode 100644 index 0000000..cb8ba0e Binary files /dev/null and b/output/korean.pdf differ diff --git a/output/print_korean.pdf b/output/print_korean.pdf new file mode 100644 index 0000000..96470cf Binary files /dev/null and b/output/print_korean.pdf differ diff --git a/zine_maker.py b/zine_maker.py index d101f17..aa3f778 100644 --- a/zine_maker.py +++ b/zine_maker.py @@ -89,7 +89,8 @@ class Zine(FPDF): header_font = args[3] english_font = args[4] chinese_font = args[5] - default_font_size = args[6] + korean_font = args[6] + default_font_size = args[7] f = open(filename, 'rt') lines = f.readlines() @@ -105,6 +106,8 @@ class Zine(FPDF): for line in lines: if re.search(u'[\u4e00-\u9fff]', line): text_font = chinese_font + if re.search(u'[\uac00-\ud7af]', line): + text_font = korean_font else: text_font = english_font # check if we have an image