PDF Depasswordization

In my company I’m getting payslips as encrypted PDF. So, I need to know my password to open these files. That is completely right and I’m pleased that my personal information is secured.

BUT. If I try to print such document, the quality is so low, so I can barely understand what is written there.

This «protection» option along with some others can be enabled when PDF is being encrypted. And I couldn’t find a way to disable it or enhance quality for printing. I tried to do it with Acrobat Reader and Google Chrome. Printing to PDF also didn’t help.

Why do I need to print these papers? It’s required in 90% of cases when you want to rent a flat, for example.

What I don’t understand is this stupid restriction. I already opened the file and I see it in a perfect quality right now on my laptop screen. I can make a high resolution screenshot and print it! Why PDF readers make my life less comfortable?

Anyway, it worth just a little effort to find more appropriate solution for this. QPDF do the trick:

1
qpdf --decrypt --password='*******' infile.pdf outfile.pdf

My version of qpdf didn’t allow to decrypt source PDF file in-place, so I used the following script to convert all required files in a directory:

1
2
3
4
5
for f in `ls 2018-*`
do
    qpdf --decrypt --password=‘123456’ ${f} ${f%%.*}-1.pdf
    mv -f ${f%%.*}-1.pdf $f
done

Read more

Bulk download from Telegram

One day I got a lot of cool photos in Telegram chat. And I asked myself: how can I download them all at once? Because MacOS client for Telegram doesn’t have such feature (there is a feature request on Github). After some searching I found out that this can be done with help of one nice library which is named Telethon. There are more of them but I decided to write my script for bulk downloading in python.

But before some preparations are required:

  1. Goto https://my.telegram.org and generate api id and api hash
  2. Install Telethon library with pip3 install telethon
  3. Run following code (replace api_id, api_hash and username with your values):
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from telethon import TelegramClient

api_id=123456
api_hash='secretHashYO'

client = TelegramClient('test_session', api_id, api_hash)
client.start()
# At this point you have to input your phone number and confirmation code

for message in client.get_messages('username', limit=25):
    message.download_media()

The code above downloads media from the last 25 messages from the chat with username in current directory.

Read more

Blog

I decided to publish things which are interesting to me, problem solutions, and another stuff. There are several aims for that. Firstly, it should help me to structure various information which I collected in different note-taking services, such as evernote. Secondly, it’s a good chance to train my writing skills. And thirdly, it could be helpful for someone else.

Read more