Fix Copy-and-Pasting in PDFs
Update (3/30/15): PDF-XChange Viewer is now supported.
Update (10/24/14): I’ve disabled comments due to spam. If you want to contact me, click here.
Update (5/2/11): Major update. See details below.
Update (11/21/2010): Improved version of the script. See details below.
Recently I’ve been reading a lot of ebooks in PDF format so it wasn’t long before I noticed that when you copy text in Adobe Reader (or any other kind of PDF reader like Foxit Reader), it copies the hard returns so if you copy more than one line of text, each line of text is treated like its own paragraph.
The Problem
This is what it looks like in Adobe Reader.
This is what happens when you copy that text and paste it into Microsoft Word.
Still good, right? But what if I want to change the font size?
Here I changed the font size of the first two lines to 8-pt. Now you should see the problem quite clearly; in its infinite wisdom, Adobe Reader inserts hard returns instead of soft returns. In other words, Adobe Reader is essentially pressing “Enter/Return” after every line instead of automatically “word wrapping” the text to fit the window size. If this sounds absurdly idiotic, that’s because it is. At first I didn’t know that was the problem until I found this guy’s blog post in a Google search. To give you an idea of how basic “word wrap” is, Notepad has it.
I know I’m not the only one who’s had this problem, and someone even wrote a Word macro. I haven’t tried the macro but it only works with Microsoft Word and it seems overly complicated (it uses well over 100 lines of code and requires a detailed step-by-step installation and usage guide; my script just works out of the box and only uses five nine lines of code (I added support for other PDF readers) [The latest version uses quite a few lines of code, but the vast majority of it is just to add some “nice-to-have” features, especially the automatic quote appending].
The Fix
Download
PDF Copy-Paster.exe (program)
Program Notes
This script strips out all hard returns out of any copied text. Simply keep the program running and it will automatically take out all the hard returns in the background. The program only activates for PDF readers. Currently the program recognizes Adobe Reader (both the standalone program and the browser plugin versions), Foxit Reader, and Sumatra PDF as PDF readers. If your favorite PDF reader isn’t on here, shoot me a quick email and I’ll add it for you.
[Note: The latest version (5/2/11) will close this popup for you automatically] Note that if you press ctrl+c twice quickly, Adobe Reader may pop up a message saying “There was an error while copying to the Clipboard. An internal error occured.” This is likely because Adobe Reader tried to modify the clipboard contents while they were being modified by the script (removing the hard returns). You do not need to copy the text again; everything should work fine.
Update (5/2/11)
I finally made a breakthrough and identified why sometimes the script would stop working and have to be restarted. Turns out it’s an issue with Windows, not anything to do with my code. Anyway, I’ve included a workaround as well as some new features such as an option to automatically add quotes to your copied selections (right click on tray icon to enable) and the ability to left-click on the tray icon to disable or enable the program. The program’s been significantly changed, but most of it is under the hood. The script should now have absolutely no bugs. Of course, if you think you’ve found me, please contact me.
Update (11/21/2010)
I’ve been using this program a lot while writing some big research papers, so I returned to the script to make toggling it more elegant. Now, just press Ctrl+Shift+D to toggle whether the script is active or not. The script’s icon will reflect this change. You no longer need the helper program for this functionality.
Update (9/2/2010)
Helper Program
I wrote this little script for a friend who sometimes wanted to retain the hard returns and sometimes didn’t. It’s not exactly elegant, but it works. Press Ctrl+Shift+d to toggle PDF Copy-Paster. If it’s already running, it will be closed while if it isn’t running, this script will run it.
A few notes
1. This only works for the compiled version of PDF Copy-Paster (the .exe version). Although I am providing a source code version (.ahk), this version also only works with the compiled version of PDF Copy-Paster.
2. This companion script needs to be placed in the same directory as PDF Copy-Paster.exe.
3. I was too lazy to make an icon for this, so it uses the default AHK icons.
Helper Program Download
PDF Copy-Paster Toggler.exe (program)
PDF Copy-Paster Toggler.ahk (source code)
Reader Comments (38)
I can only say..OMFG!!
Dude, like how is it...I mean, I just....Thanks sooo f******* very much!
Why didn't I searched for this in the past??..and I can't believe you have no comments!! this is great!, so easy simple awesome, I really have to congratulate you.
You know, I got used to copy first and identify the hard breaks and erase one by one, at first it was annoying, then I just didn't care anymore, then in MS word I used a featured called "show all" or something like that which shows you the "invisible things" like spaces and tabulates and the hard returns, so I looked for those and erased them one by one..so...
I just have no words for your awesome contribution, it helps me a lot, I wish I saw this before, but now it's gonna be a lot of use.
Thanks thanks thanks, really! =)
Edward
mmmmmmm....
although..I'm seeing that when I select 2 paragraphs which are "hard returned" so they separe...I mean:
lalalala, paragraph 1.
lalalal, paragraph 2.
I get one line insted of 2, like:
lalalala, paragraph 1. lalalal, paragraph 2.
So I don't know if that can be fixed....but anyway doesn't matter that much, for now I usually copy few part's, not whole paragraphs, but for times like that, it would be nice to see the separation... =)
Edward
Hi Edward,
Thanks for the kind words! I think the reason this fix isn't more popular is because so few people know how to search for the problem. Few people know the difference between hard and soft returns, and even fewer people would ever imagine that Adobe would design their program to use hard returns even now in 2011. Also, I think that most people are willing to manually remove each hard return. It was only when I needed to copy from dozens of different PDFs that I actually bothered trying to solve the problem.
Yes, the issue with multiple paragraphs is a limitation, Unfortunately, I can't figure out a way to solve it. Unfortunately, there's really only so much that can be done without changing Adobe Reader itself.
Also, if you notice that sometimes the wrong characters are copied, that is also an unavoidable problem, since it's Adobe Reader not recognizing the correct character (regardless of whether my program is active or not).
Sincerely,
The One Hour Programmer
Hi there, you are a genius! thanks a lot for the fix...it works perfectly.
Hello,
I am one of those people who don't understand soft returns and hard returns etc. But I found this website trying to fix an error (error copying to clipboard message every time I tried to copy something). Not knowing what would happen I downloaded the fix, realised it didn't do what I needed (apparently hard returns are a good thing if you are copying legislation?) and toggled it off. But this has fixed my clipboard error problem, so thank you!
You said you have the updated version automatically removing the popup in Adobe that says “There was an error while copying to the Clipboard. An internal error occured.”
Can you please share the AHK script you wrote to do this?
Sure, no problem:
SetTimer, ErrorBlocker, 150
ErrorBlocker:
PostMessage, 0x112, 0xF060,,, Adobe Reader, There was an error while copying to the Clipboard. ; 0x112 = WM_SYSCOMMAND, 0xF060 = SC_CLOSE
return
It just checks for the window, and closes it if detected.
Wow this is AWESOME!!!!!! Thank you thank you thank you for sharing this!
One question, I don't see the icon on my tool bar - the shift+control+d works perfectly but it'd be great to use the button. Any suggestions making it appear?
Thanks again - I've been deleting hard returns for years...NO MORE!
Thanks very much! This is going to save me a lot of time. Your work is much appreciated.
Michael
Hi, you the icon isn't in your tool bar, but in your system tray (bottom right of your screen). You can enable/disable the program by simply left-clicking the icon.
you, sir, are a god, I've been looking for a work around this forever. The multiple paragraph is definitely a limitation, but it is better than the alternative. I wish Adobe or Microsoft would fix this annoying problem.
Also, what I have been doing before I found this script is using Calibre to convert pdf to txt for huge documents. Then I copy the text into Word for formatting. This helps with having copy multiple paragraph that this script doesn't do. But this program is nice that it allows me to select certain text. Hope this helps someone
Thank you so much for this!
Your fix is right on. I was constantly getting that error mesage til the annoyance became too much and then I started searching on the Adobe site and then to here. I will make sure that I post your site with your solution on the Adobe site and maybe that will prompt them to incorporate the fix themselves!
Thanks again for the simple and perfect fix.
starnet7
it's works fine.
lot of working time saved up
thanks
I just googled this having become exasperated by inability to copy from .pdf.
It seems like a breakthrough - It just works :). Great.
Rgds
I, too, found this post while looking for an solution to the "Adobe Reader: there was an error copying to the clipboard" dialogue that was popping up every 3rd or 4th time I copied text from the Reader.
Stripping the CR/LF is just icing on the cake, for me.
Thanks, again!
Al
Thank u very much :) Now I wanna say to myself, "WHY I DIDN'T VISITED YOUR WEBSITE BEFORE" . :) :) :)
Thanks very much. I ran it as administrator in windows x64 it seems working now.
Bitdefender market it as avirus.
your script does not work for me because i'm using a dictionary which uses clipboard and when i copy something it translate the word almost all dictionaries work the same way but when the script is running it translate the word repeatedly
This is awesome. Saved me a lotta time. Thanks a lot
there is a free downlload called easy pdf to text converter. it can be downloaded from cnet download. It is virus and malware free and it works just fine.
Worked a treat! Thanks!
Thank you very much for sharing this wonderful tool. My preferred PDF editor is pdf-Xchange viewer. I don't think your script works for that at the moment. Please could this be included in the next update?
Thank you so much, saved me a mini mental breakdown
Great piece of utility software. Thanks! Any plan to make the source code available for mass people?
great work
This little piece of coding art has become one of the most useful programs in my computer, standing in line with Word 2013 and Adobe Reader X. It has saved tons of time I used to waste dealing with formatting irregularities that arise while copying text from PDF files. You deserve my deepest gratitude sir! Thank you.
Thank you so much. This is awesome.
How do I remove your program from my computer???
Thanks!!
Albert Lopez
Awesome Man, I lately found what was happening, I just couldn't get the "justify" option in MS Word to work.
For the last 3 semesters of my distance degree program, I had to submit assignments and I had to copy paste stuffs from pdf files. I had to manually edit each and every line to make it look good. I searched, I found the problem was with the Pilcrow sign at the end of each line. Then I searched further and came across your site. Thaaaanks a lot buddy, you saved me a great amount of time.
God Bless.
For translators that work with PDFs a lot and need to copy text from source documents into dictionaries, etc., or check for other instances of source text on the internet, this is fantastic - I wonder why I never searched for it before. Thanks so much!
THANK YOU!
I kept getting the following Adobe Reader error message and found you via this link (google cache):
"There was an error while copying to the Clipboard. An internal error occurred."
http://webcache.googleusercontent.com/search?q=cache:HkUFrjVp6P0J:www.fixkb.com/2012/03/there-was-an-error-while-copying-to-the-clipboard-an-internal-error-occurred.html+&cd=3&hl=en&ct=clnk&gl=us&client=firefox-a
Been annoying me for quite a while, and every forum I found advised to disable Skype add-on in IE, but I don't have Skype installed, and unless it resurrected itself and is hiding somewhere, I'm pretty sure I uninstalled IE a long time ago! Your little patch worked instantly!
I used to be able to copy/past from pdf documents just fine, but in the last few months when I past into the receiving document (word file, my email, anything) it pastes the text but it removes all the spacing between words. I also think that this started happening the same time when I am selecting the text in pdf (pro) that the text becomes highlighted with green crescents (each letter & space gets a crescent where there is a flat facing left on the cresent)... I don't remember this happening before. I have to go back in and put words spacing in... quite a pain. HELP :)
thanks man, your script helped me
Works wonderfully and also appears to get rid of the annoying 'error copying' message. Thank you muchly.
Just wanted to say I've been using this for a couple of years and it has therefore saved me from countless minutes of reformatting and frustration. Thank you.