Open pdf as txt file and then copy - why it doesn't work
31 minutes ago, Adonis4000 said:I was thinking that since I am able to change the extension at the end of a .pdf to .txt and then back to .pdf without any loss of data, in theory I should be able to copy the text from the pdf file to another text file and then change that file to .pdf.
Chaging the name of the file doesn't touch the file itself. The name is meaningless and has nothing to do with the format, it's just used for some OSes (and users) to decide what program will open it by default and it'll interpret the file contents however it needs.
The content of a pdf file is binary, not text. If you copy the contents with a text editor or python in text mode some bytes will be mangled/lost because they are not valid text characters. Need to open the file as binary.
31 minutes ago, Adonis4000 said:copy files using python, which there probably is a better way of going about
shutil has file copy functions.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now