Show HN: Make Your PDF Look Scanned
scanyourpdf.com
scanyourpdf.com
convert -density 150 input.pdf -colorspace gray -linear-stretch 3.5%x10% -blur 0x0.5 -attenuate 0.25 +noise Gaussian -rotate 0.5 temp.pdf
gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite -sColorConversionStrategy=LeaveColorUnchanged dAutoFilterColorImages=true -dAutoFilterGrayImages=true -dDownsampleMonoImages=true -dDownsampleGrayImages=true -dDownsampleColorImages=true -sOutputFile=output.pdf temp.pdfconvert letter.pdf -colorspace gray \( +clone -blur 0x1 \) +swap -compose divide -composite -linear-stretch 5%x0% -rotate 1.5 as-scanned.pdf
[0] https://news.ycombinator.com/item?id=23157979
[1] https://tex.stackexchange.com/questions/94523/simulate-a-sca...
convert -density 150 ORIGINAL.pdf -colorspace gray +noise Gaussian -rotate 0.5 -depth 2 SCANNED.pdf
Consider using `-depth 1`, `-depth 3` as a final parameter to map colors to only 2¹=2 or 2³=8 instead of 2²=4 gray levels. Using a small number of gray levels SIGNIFICANTLY reduces file size and also gives your pseudo-scanned document a more pixelated, it-just-came-out-of-my-old-printer look.Also consider using `-density 100` or even `-density 75` for long text documents. Using a density of 75 dpi produces documents that are 4x smaller than 150 dpi (75²=150²/4) and doesn't affect the readability of normal-sized (10-12pt) text that much.
Finally, sometimes it works best not to add Gaussian noise.
convert letter.pdf -colorspace gray \( +clone -blur 0x1 \) +swap -compose divide -composite -linear-stretch 5%x0% -rotate 1.5 as-scanned.pdf
However, that may be a useful feature, since many users end up inadvertently creating very large PDFs when scanning.
All that said, note that you can always add a `-compress <compression method>` to the convert command, although this could make it noticeably slower, say, for a directory full of long documents. There's even a Fax TIFF compression method that makes the document look like it came out of one of those fax machines you see in movies from the 1980's. To get a list of supported compression methods, type `convert -list compress` at the command line.
IF EXIST scanThis.pdf (magick convert -density 100 scanThis.pdf -colorspace gray +noise Gaussian -rotate 0.5 -depth 2 SCANNED.pdf) ELSE (ECHO File scanThis.pdf not found & PAUSE)To be honest, I'm waiting for a boom of such services, that can be run in a separate tab without any network jumps.
One suggestion: add thumbnail/preview of how docs will look like after "scanned". Or maybe even a "Before and After" teaser! :)
It's interesting that the problem they had was with the signature. You can very easily make a handwritten signature on an iPad. I don't see how there's any practical way to tell the difference between a high-quality, handwritten signature done on an iPad with either a finger or an Apple Pencil and a scanned signature done with a pen.
Are you sure that's not just some excuse they gave you?
Ironically, despite being hosted on tex.stackexchange.com, all of the answers use ImageMagick, Photoshop, or Windows 10/Adobe Acrobat.
[1] http://hanno-rein.de/archives/349
[2] http://mirrors.concertpass.com/tex-archive/macros/luatex/lat...
Yes, absurd.
Banks are themselves full of absurd practices but in this one tiny area I’d give them a pass.
A couple of years ago I used DocuSign on a contract, and the PDF “copy” I was emailed as a receipt had different terms than the one I actually signed.
Luckily I did not object to the discrepancy, but I would have wondered what would have actually happened if I did.
Regardless, I am sure there has been a version of a some document signing software somewhere that had a bug with immutability. Now paper documents aren't immutable either, but you couldn't accidentally change one with a bad where clause in a SQL statement, and casual attempts will leave evidence of the change.
BTW this is why numbers in contracts are often written “1 (one)”: because in the age of pens it was easy to change “1” to “10” or “4” or “one” to “none”
Also why checks do this — checks are actually simply contracts, which were standardized in the US a bit in the 1920s (you’d get a check form, fill in your name and the bank name, then the amounts, etc; current check design With preprinted bank info dates back I believe to the late 1960s.
> If you’re a solicitor responsible for registration, you need the other parties' solicitors, on closing, to send you the wet-ink signed parts of the documents. You’ll only proceed when you have the wet-ink signed documents, not when you have seen electronic images of them.
As others noted a before and after pic would be great.
Just tried this. Orienting your phone at 45 degrees to the monitor can mostly reduce them, but that's not really that useful.
I recently felt privileged enough to get a printer at home in the workroom of my 2bd apartment in San Francisco.
And yet, it ran out of toner! The notaries wanted documents already printed! The print shops are all closed! What the deuce!
I got one to sympathize with me, she wouldn't take my flash drive, but ran out of excuses when I said I have the files on my iphone's file section and could email them.
Original: Please don't upload any private or confidential pdfs right now. I emailed OP two security concerns that trivially allow anybody to see any of the converted pdfs.
do you OP! I think it still provides a service, enjoy all the secrets
And what makes you think the operator has nefarious intent?
https://github.com/baicunko/scanyourpdf/blob/master/pdfwebsi...
This is rather less than secure; output files are named, e.g., "Scan_2020512_{four random lower-case letters}.pdf" into a web-server-readable directory.
That gives a total of 456976 different possible filenames on a day. It's more than feasible to brute-force that many filenames in the hour before files get deleted.
OP: I don't think randomly-suffixed file names are an inherently bad way to approach this. But you should definitely consider using a longer random string, and definitely consider not using the `random` module too (it is not secure and is not intended to be).
Consider: If you moved this on to another server, would you remember to enable rate limiting there? If someone else uses your code, will they know to enable rate limiting?
Rate limiting isn't a bad idea, but your security should not depend on it, especially as you have a way of securing it in your application. base64.b16encode(os.urandom(8)) will give you a 64-bit, filename-safe, as-close-to-random-as-reasonable suffix that should be long enough to make it brute-force-proof :)
The same reasoning applies to the cron job (I presume) that is cleaning your files - that's something you have to remember to set up for future (re-)deployments.
Edit: I'd also like to add that showing your code on HN takes bravery and this is, in fact, a neat tool that solves a problem I really wish didn't exist. So, good work on both counts :)
I will start working on your comments throughout the weekend, I agree with most of them. Would love for you to follow the github page for any other comments you may have, all are appreciated
So that is what I've decided to do! First step: a PR coming out of getting this up and running on my Ubuntu box. :)
>>> tempfile.mkstemp(suffix='.pdf')
(4, '/tmp/tmp0g7l3uq7.pdf')
one could take it a step further... >>> tempfile.mkstemp(suffix='.pdf', prefix=uuid.uuid4().hex)
(5, '/tmp/7b7881400a2348bfae63d37b970d4489pqhz_1g2.pdf')https://stackoverflow.com/questions/4845239/how-can-i-disabl...
Still there's no admin user configured so it's safe
Before resorting to this, I've found that if I convert the PDF to an image, and send it as a TIFF file, that is usually what the organization's people are looking for. I haven't had to do that for years now.
On the extremely rare occasions someone asks if I signed it on "real paper" (lol), I say with a straight face, "yep, I'm a computer guy, I have a really good scanner and image software". I do. It's just gathering dust. Last time that happened was about 5 years ago.
Over 20 years ago, I wrote my signature in thick, black Sharpie across an entire letter-sized, landscape-orientation page, scanned it with the highest resolution scanner I could cadge at the time (600 dpi, wooo!), laboriously cleaned it up, added an alpha channel, then even more laboriously vectorized it. Ever since then, dropping my signature into PDF's has worked except for those situations where a physical, wet-signed notarized document was required.
At first I took to the trouble to convert the resultant PDF into TIFFs and digitally sign them. Then with some experimentation I found that flattened and stripped PDFs without the digital signature were accepted without comment. Further experimentation revealed to me that only developers like us could even tell the difference, and plain PDF's where I dropped the signature into them are accepted these days.
Now, I use an Acrobat DC stamp that I converted from the vectorized form, and haven't touched the old bitmap or vectorized versions in years. Ironically, the most secure option of digital signatures gave me the most problems.
I love it.
Original (was PDF): https://i.imgur.com/v5nn1ql.png
Processed: https://www.scanyourpdf.com/media/Scan_2020512_wegb.pdf
Not wanting to drive a few hours, I exported the unsigned pdf as images, quickly made the fix, converted it back pdf, and sent it away with a message saying not to worry, I fixed the problem.
Then communication ceased. I couldn’t get a reply. When I called, they put me on hold and said they were no longer taking applications (they claimed many units were available before).
I like to think the pristine color and noise matching, from my especially mediocre photoshop skill, was too convincing, and made them worry.
You were trying to see if someone was sniffing the documents uploaded (and confirmed they were).... or you realized you could use them as a vector though which others would post your materials on websites elsewhere (and they did)?
1. picks one incantation randomly for each display 2. slightly and randomly alters the position/rotation of each character 3. adds a tiny blotch now and then
Like the print in a real book, especially ones printed before 1970.
I also suggest that the background be an actual scanned image of a blank piece of paper. Those "paper color" backgrounds are too perfect. Take some blank pages out of an older book sometime and scan them, and you'll see what I mean.
I'd settle for "too perfect" in a heartbeat.
One of them, for example, was an option to eliminate the margin in a pdf display. The pdf already has a margin, so there's the pdf margin plus the margin the ereader puts around the pdf. This significantly reduces the number of pixels displaying information.
Sadly, I'd also be extremely wary of sending the kind of documents that I need to print out and sign through some server-side black box.
The thing is, sharing a repository does not prove that the server is running that same code. And someone worried about their document security wouldn't run some random binary locally either, because it could send the document off to a server. They would run the source code locally after reading it, which sharing the repository allows for.
Just downgrading the pdf? Looking for a signature-like part and turns this to pseduo-handwritten characters, maybe changing the color? Something completely different?
Naturally, I did not want to upload a potentially confidential document to some random webservice.
I actually had a pdf file containing several pages of "Lorem ipsum" that I needed for another thing, but I deleted it yesterday because I was done with it.
1) set to grayscale (optional), 2) add blur, 3) slight rotational tilt, 4) add gaussian blur (?)
You can go one further by randomly adding tiny artifacts (ie. specks) to add even more realism. Maybe even a simulated crease in a corner.
Perhaps one suggestion. Can you update your documentation a bit to make it easier for someone to be able to implement it themselves? There's not much about that on the Github and I would guess some people would rather run their own locally.
Sample PDF: https://campustecnologicoalgeciras.es/wp-content/uploads/201...
Output PDF: https://scanyourpdf.com/media/Scan_2020513_gtqh.pdf
EDIT: Forgot to mention that a before and after will be included in the website as it has been mentioned multiple times as a great way of showing what the website does!
I have my 3-4 copies of signatures as font file, along with initials.
I like that it is open source and in theory possible to self host since I really wouldn't want to upload my documents anywhere.
I would really like to know if a similar solution exists that is very easy to run locally or if it runs in the browser it does everything client-side?
What I normally do in a pinch is use Google Drive.. it has a "scan" option that you can take a picture with your phone.
Wait, what less than kosher method were you thinking?
It's like if all devices in your house have no internet connection, and your ISP support rep asks you to reboot your computer. You say "Ok it just rebooted" without rebooting because the reason for the procedure is simply to ensure that it's not an issue local to one device, and you have ensured that for them (albeit by alternative means).
the server is down.
Just one comment: maybe you could randomize the rotation angle so that all pages don't look the same.