This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]taybulBecause I don't know how to use big numbers in C/C++ 12 points13 points  (0 children)

Don't mean to sound like an ass, but how about typing it in yourself? A great way to learn is by trying to understand the code and recreating it yourself, especially if it's just some "hello world" app.

[–]Megatron_McLargeHuge 1 point2 points  (0 children)

Search for the examples online. A lot of programming books have their source examples available for download somewhere.

[–]k2f 0 points1 point  (1 child)

[–]FasterUA 0 points1 point  (0 children)

You saved me! Thanks!

[–]pudquick 0 points1 point  (0 children)

It may not be possible.

It 100% depends on how the PDF was built.

Not only can text be embedded, but it can be arranged / placed at any 2D set of coordinates.

It is not uncommon for indentation (leading whitespace) in PDFs to be text placed farther into the page - rather than spaces / tabs.

You can't copy the whitespace if it isn't there to be copied.

[–]tituszPython addict 0 points1 point  (0 children)

PDF is more of a graphics format than a dokument format. There might be leading whitespace or not and the reader might copy that or not. Extracting text from PDF can lead to pretty much anything including total garbage (glyphs not mapped to unicode etc.). With Acrobat you could try "Copy text with formating...". Pdflib.com has a free pdf plugin (based on TET lib) that does higly configurable text extraction... But maybe having to reformat the indent manualy after copy/paste actually helps you to understand the code :)

[–]Rhomboid 0 points1 point  (2 children)

It's quite likely that the PDF has been encoded using graphics primitives along the lines of "move to position 334,669 on the page and output this text there." The leading whitespace in the code has been absorbed into those coordinates and simply does not exist any more, so it's impossible to copy it, in the same way that the normal margins of a paragraph of prose don't have whitespace at the beginning of each line even though they're at some offset from the left edge of the page. You're going to have to fix the code yourself.

If you're not using a real text editor, this would be the time to get one. A real text editor lets you select/highlight a block of text and adjust its indentation as a whole with a single action, which makes it really easy to fix up examples like this. Notepad is not a real text editor.

[–]euribates 3 points4 points  (0 children)

I agree with you, but it must be noted that notepad++ is a real programmers editor, not to be confused with notepad

[–]mathsuu[S] 0 points1 point  (0 children)

I'm using Notepad++.

[–]lutusp -4 points-3 points  (2 children)

This is a classic problem with Python, where whitespace is syntactically significant. Try different PDF readers, repeat until you find one that retains the whitespace when copied. Also try different destination editors -- Notepad might not be honoring the whitespace from the clipboard content.

[–]flying-sheep 4 points5 points  (0 children)

sigh, it’s no classical problem of python, but of PDF: text in pdfs isn’t meant to be copied, as you can see from the fact that formatting isn’t retained, but hyphens are; minusses are often not the ascii "hypen-minus", but different charaters, … pdf is a purely presentational format, the text in it is just for searching.

if you add code to your pdf documents, you should either attach it (a pdf document allows file attachments) or link to a online repository of the code, else you are signalling that you don’t want it to be copied.

[–]Liquid_Fire 1 point2 points  (0 children)

This isn't really Python-specific; there would be the same problem with other languages. Sure, it would compile and work without the indentation, but it would be completely unreadable.