User:Pedro Sá Couto/TW/Watermark
< User:Pedro Sá Couto | TW
Revision as of 02:53, 8 June 2020 by Pedro Sá Couto (talk | contribs) (Created page with "=STEPS= ====The watermark is produced in 2 steps:==== 1. Getting the text input from a txt file<br> 2. Producing it with Python<br> <br> =RESULT= <gallery> File:producedwater...")
STEPS
The watermark is produced in 2 steps:
1. Getting the text input from a txt file
2. Producing it with Python
RESULT
FLOW
This is the .txt input from https://hub.xpub.nl/watermark/
['Mr. Beauregard', 'No', '0 minutes', 'It was stored in my computer lib', 'This is a test. I am republishing this book because I am creating Tactical Watermarks, lets make it works, plz']
Python Script with ReportLab
from reportlab.pdfgen import canvas
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase import pdfmetrics
from reportlab.lib import colors
from reportlab.lib.colors import pink, green, brown, white, black
import textwrap
from textwrap import wrap
from reportlab.lib.units import inch
from reportlab.lib.pagesizes import letter
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import inch
from reportlab.lib.units import cm
from reportlab.lib.colors import HexColor
import datetime
from reportlab.lib.utils import ImageReader
import ast
with open('watermark.txt', 'r') as f:
watermark = ast.literal_eval(f.read())
#The Ruler
def DrawTheRuler(pdf):
pdf.drawString(30,960, '|')
pdf.drawString(60,960, '|')
pdf.drawString(90,960, '|')
pdf.drawString(120,960, '|')
pdf.drawString(150,960, '|')
pdf.drawString(180,960, '|')
pdf.drawString(210,960, '|')
pdf.drawString(240,960, '|')
pdf.drawString(270,960, '|')
pdf.drawString(300,960, '|')
pdf.drawString(330,960, '|')
pdf.drawString(360,960, '|')
pdf.drawString(390,960, '|')
pdf.drawString(420,960, '|')
pdf.drawString(450,960, '|')
pdf.drawString(480,960, '|')
pdf.drawString(510,960, '|')
pdf.drawString(540,960, '|')
pdf.drawString(570,960, '|')
pdf.drawString(600,960, '|')
pdf.drawString(630,960, '|')
pdf.drawString(10,940, '—')
pdf.drawString(10,910, '—')
pdf.drawString(10,880, '—')
pdf.drawString(10,850, '—')
pdf.drawString(10,820, '—')
pdf.drawString(10,790, '—')
pdf.drawString(10,760, '—')
pdf.drawString(10,730, '—')
pdf.drawString(10,700, '—')
pdf.drawString(10,670, '—')
pdf.drawString(10,640, '—')
pdf.drawString(10,610, '—')
pdf.drawString(10,580, '—')
pdf.drawString(10,550, '—')
pdf.drawString(10,520, '—')
pdf.drawString(10,490, '—')
pdf.drawString(10,460, '—')
pdf.drawString(10,430, '—')
pdf.drawString(10,400, '—')
pdf.drawString(10,370, '—')
pdf.drawString(10,340, '—')
pdf.drawString(10,310, '—')
pdf.drawString(10,280, '—')
pdf.drawString(10,250, '—')
pdf.drawString(10,220, '—')
pdf.drawString(10,190, '—')
pdf.drawString(10,160, '—')
pdf.drawString(10,130, '—')
pdf.drawString(10,100, '—')
pdf.drawString(10,70, '—')
pdf.drawString(10,40, '—')
# Unchanged
fileName = "watermark.pdf"
documentTitle = "TACTICAL WATERMARKS"
title = "TACTICAL WATERMARKS"
subTitle = "REPUBLISHED THROUGH"
#Create the file
pdf = canvas.Canvas(fileName)
#Set the background
pdf.setFillColor(HexColor(0xceff00))
pdf.rect(0,0,660, 1000,fill=1)
#Change color back to black
pdf.setFillColorRGB(0,0,0)
##Draw the Ruler
DrawTheRuler(pdf)
# Set the title
pdf.setTitle(documentTitle)
#Set the Height and Width
pdf.setPageSize((660, 1000))
#DRAW LOGO
logojump = ImageReader('logojump.png')
pdf.drawImage(logojump, 560, 10, width=(300/3),height=(300/3), mask='auto')
logostar = ImageReader('logostar.png')
pdf.drawImage(logostar, 100, 400, width=(300),height=(300), mask='auto')
#TITLE
# Register a new font
pdfmetrics.registerFont(
TTFont('header', 'LyonJeanTrue.ttf')
)
# Draw
pdf.setFont('header', 45)
pdf.drawString(40, 30, title)
#SUBTITLE
# Register a new font for the subtitle
pdfmetrics.registerFont(
TTFont('subtitle', 'Favorit_Medium.ttf')
)
# Draw
pdf.setFont('subtitle', 14)
pdf.setFillColorRGB(0, 0, 0)
pdf.drawString(40, 80, subTitle)
# DATE
date = datetime.datetime.now()
# Draw
pdf.setFont('subtitle', 10)
pdf.setFillColorRGB(0, 0, 0)
pdf.drawString(30, 980, str(date))
# HEADER
header = "UPLOADERS SIGNATURE"
pdf.setFont('subtitle', 35)
pdf.setFillColorRGB(0, 0, 0)
pdf.drawString(30, 920, header)
# BODY
# Register a new font for the body
pdfmetrics.registerFont(
TTFont('body', 'Favorit_Regular.ttf')
)
pdfmetrics.registerFont(
TTFont('bodyitalic', 'Favorit_Regular_Italic.ttf')
)
# ID
# Q
id = "Name—Nickname—Pseudonim of the uploader"
pdf.setFont('bodyitalic', 14)
pdf.setFillColorRGB(0, 0, 0)
pdf.drawString(60, 890, id)
#A
id_answer = watermark[0]
pdf.setFont('body', 14)
pdf.setFillColorRGB(0, 0, 0)
pdf.drawString(30, 870, id_answer)
# DID YOU DIGITISE?
# Q
digitise = "Did you digitise the file?"
pdf.setFont('bodyitalic', 14)
pdf.setFillColorRGB(0, 0, 0)
pdf.drawString(60, 835, digitise)
#A
digitise_answer = watermark[1]
pdf.setFont('body', 14)
pdf.setFillColorRGB(0, 0, 0)
pdf.drawString(30, 815, digitise_answer)
# HOW LONG?
# Q
howlong = "How long did it take to scan?"
pdf.setFont('bodyitalic', 14)
pdf.setFillColorRGB(0, 0, 0)
pdf.drawString(60, 780, howlong)
#A
howlong_answer = watermark[2]
pdf.setFont('body', 14)
pdf.setFillColorRGB(0, 0, 0)
pdf.drawString(30, 760, howlong_answer)
# WHERE DID YOU FIND IT?
# Q
where = "Where was the source found?"
pdf.setFont('bodyitalic', 14)
pdf.setFillColorRGB(0, 0, 0)
pdf.drawString(60, 725, where)
#A
where_answer = watermark[3]
pdf.setFont('body', 14)
pdf.setFillColorRGB(0, 0, 0)
pdf.drawString(30, 705, where_answer)
#ANECDOTE
# Q
sharing = "Why are you sharing this file?"
anecdote = "You can tell an anecdote"
personal = "You can leave a personal message!"
pdf.setFont('bodyitalic', 14)
pdf.setFillColorRGB(0, 0, 0)
pdf.drawString(60, 670, sharing)
pdf.drawString(60, 655, anecdote)
pdf.drawString(60, 640, personal)
#A
strs = watermark[4]
#Wrap the lines
textLines = wrap(strs, 75)
text = pdf.beginText(40, 615)
text.setFont("body", 14)
text.setFillColor(colors.black)
for line in textLines:
text.textLine(line)
# Draw
pdf.drawText(text)
# Save the pdf
pdf.save()