updated nbs

master
Michael Murtaugh 4 years ago
parent 852a79582b
commit 0cd67901f0

@ -213,7 +213,8 @@
"!man -t ps2pdf | ps2pdf - man/ps2pdf.pdf\n",
"!man -t pdf2ps | ps2pdf - man/pdf2ps.pdf\n",
"!man -t pdftk | ps2pdf - man/pdftk.pdf\n",
"!man -t pdfposter | ps2pdf - man/pdfposter.pdf"
"!man -t pdfposter | ps2pdf - man/pdfposter.pdf\n",
"!man -t poster | ps2pdf - man/poster.pdf"
]
},
{
@ -444,18 +445,16 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tile and zoom with **pdfposter**"
"## Tile and zoom with **poster**"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"Let's see according to the [manual](man/pdfposter.pdf)\n",
"From the [poster](msn/poster.pdf) manual:\n",
"\n",
"Prints an A4 input file on 8 A3 pages, forming an A0 poster:"
">*Poster* can be used to create a large poster by building it from multiple pages and/or printing it on large me-dia. Itexpects as input a generic (encapsulated) postscript file, normally printing on a single page.Theoutput is again a postscript file, maybe containing multiple pages together building the poster.The outputpages bear cutmarks and have slightly overlapping images for easier assembling. The input picture will bescaled to obtain the desired size"
]
},
{
@ -464,39 +463,17 @@
"metadata": {},
"outputs": [],
"source": [
"!pdfposter -mA3 -pA0 1.pdf pdfposter.pdf"
"#!poster -mA3 -pA0 1.ps | ps2pdf - > poster.poster.pdf\n",
"!poster -v -c0 -iA4 -mA4 -pA0 1.ps | ps2pdf - > poster.poster.pdf"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## **Puzzle**: Combine tools to make a poster with different elements\n",
"![](https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/15-Puzzle.jpg/330px-15-Puzzle.jpg)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## RECAP: Using python: **PIL** and **aalib** and **reportlab.pdfgen.canvas** to make an ASCII art PDF"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from PIL import Image, ImageDraw\n",
"from urllib.request import urlopen\n",
"import aalib\n",
"f = urlopen(\"https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fkinneretstern.files.wordpress.com%2F2015%2F12%2Flee-miller2.jpg&f=1&nofb=1\")\n",
"im = Image.open(f)\n",
"screen = aalib.AsciiScreen(width=200, height=160)\n",
"resized = im.convert(\"L\").resize(screen.virtual_size)\n",
"screen.put_image((0, 0), resized)\n",
"lines = screen.render().splitlines()"
"The newer [pdfposter](man/pdfposter.pdf) works directly with PDF files, and has slightly different options.\n",
"\n",
"For example to prints an A4 input file on 8 A3 pages, forming an A0 poster:"
]
},
{
@ -505,39 +482,15 @@
"metadata": {},
"outputs": [],
"source": [
"from reportlab.pdfgen.canvas import Canvas\n",
"from reportlab.lib.pagesizes import *\n",
"from reportlab.lib.units import mm\n",
"from reportlab.pdfbase.ttfonts import TTFont, pdfmetrics\n",
"\n",
"c = Canvas(\"aa.pdf\", pagesize=A2, bottomup=0) \n",
"fontpath = \"fonts/mplus-1m-regular.ttf\"\n",
"font = TTFont('1mregular', fontpath)\n",
"pdfmetrics.registerFont(font)\n",
"\n",
"# To set a font in the PDF\n",
"c.setFont('1mregular', 14.4)\n",
"\n",
"start_y = 0*mm\n",
"y = start_y\n",
"lineheight = 4*mm\n",
"\n",
"# lines = open(\"my-fantastic-quilt\").readlines()\n",
"\n",
"for line in lines:\n",
" c.drawString(2*mm, y, line)\n",
" y += lineheight\n",
"\n",
"c.save()"
"!pdfposter -mA3 -pA0 1.pdf pdfposter.pdf"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"!pdfinfo aa.pdf"
"## **Puzzle**: Combine tools to make a poster with different elements\n",
"![](https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/15-Puzzle.jpg/330px-15-Puzzle.jpg)"
]
},
{

@ -0,0 +1,96 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# aalib PDF\n",
"\n",
"Making an ASCII art PDF using aalib, PIL, and reportlab"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from PIL import Image\n",
"from urllib.request import urlopen\n",
"import aalib\n",
"\n",
"f = urlopen(\"https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fkinneretstern.files.wordpress.com%2F2015%2F12%2Flee-miller2.jpg&f=1&nofb=1\")\n",
"im = Image.open(f)\n",
"screen = aalib.AsciiScreen(width=200, height=160)\n",
"resized = im.convert(\"L\").resize(screen.virtual_size)\n",
"screen.put_image((0, 0), resized)\n",
"lines = screen.render().splitlines()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from reportlab.pdfgen.canvas import Canvas\n",
"from reportlab.lib.pagesizes import *\n",
"from reportlab.lib.units import mm\n",
"from reportlab.pdfbase.ttfonts import TTFont, pdfmetrics\n",
"\n",
"c = Canvas(\"aa.pdf\", pagesize=A2, bottomup=0) \n",
"fontpath = \"fonts/mplus-1m-regular.ttf\"\n",
"font = TTFont('1mregular', fontpath)\n",
"pdfmetrics.registerFont(font)\n",
"c.setFont('1mregular', 14.4)\n",
"\n",
"start_y = 0*mm\n",
"y = start_y\n",
"lineheight = 4*mm\n",
"\n",
"for line in lines:\n",
" c.drawString(2*mm, y, line)\n",
" y += lineheight\n",
"\n",
"c.save()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pdfinfo aa.pdf"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading…
Cancel
Save