2

Would it be possible to show line numbers as part of the pdf document. What option should I use?

3 Answers 3

0

I've found the following answer regarding your question. According to the second paragraph, it's almost impossible to do what you want.

Answer by user grantm on perlmonks.org:

It may be possible - it depends on how the PDF was generated. If the option was used to convert text to curves then you're probably out of luck.

Also the PDF file format has no concept of 'lines'. Characters in a particular font family, weight, size (etc) are placed at X/Y coordinates on the page. They can be placed in any order (ie: not just left-right, top to bottom).

So if it were possible, one approach would be to find the y coordinate of every piece of text on the page; reduce that to a unique set; sort them and assign line numbers; go down and add the line numbers as text elements at the same y coordinate on the right hand side of the page.

For the first part, you might find that the CAM::PDF module has some useful tools (eg: it can render just the text elements of a PDF page). Overlaying new text elements is the easy part. I tend to use PDF::Reuse but I'm sure that PDF::API2 could be used too.

1
  • It's possible to view line numbers on a text file if you view it via an editor, I am just looking for a similar capability
    – Joshua
    Jul 7, 2011 at 11:39
1

Here's a pretty good way, based on two caveats: (1) you have access to Adobe Acrobat DC (not just the Reader) (2) you don't need exact alignment (my purpose was to allow reviewers of a technical document to identify and comment on issues, so a one-line ambiguity is acceptable)

So - prepare a document (using Word or Open Office, etc.) with maybe 55 or 60 line numbers on the left side. You don't have to type the numbers - just turn on line-numbering if you are using a word processing program, and enter carriage returns. Adjust the font size to adjust the number of lines on your page. The line numbers should be positioned to the left of where the margin on your main document is located - so you may want to create the line-number document with a 0.6 inch left margin. Save/export this as a PDF file.

In Adobe Acrobat DC, you simply add the line-number PDF as a "background" to the main document. I will not describe that here - Please see the instructions at https://helpx.adobe.com/acrobat/using/add-backgrounds-pdfs.html.

Note that you can shift the line-numbered background around if you didn't get the line numbers far enough left (you can enter a negative off-center increment to move it to the left).

0

Here's how I figured out how to do it. It's a little fiddly to get the sizing right, but here goes:

Prepare a file of numbers, from 1 to approximately 32, using Excel or something else. Somehow make a png file. You could do this by saving to pdf in Excel and then using an online conversion tool, or by making a screenshot. Make sure the column of numbers is waay over to the left edge of the page, and size your row heights so that the numbers take up a reasonable amount of space.

Download and install PDFill.

Choose Item 8, "Add Watermark to Image." (It will walk you through opening two files.)

Open the pdf whose pages need line numbers.

Open the png file with the column of numbers.

Now you will choose an amplification factor and an offset value. Here, as an example, is what worked for me:

enter image description here

Hit "Save as" and save the file. The new file will probably open up automatically. (If not, check your settings in PDFill.)

Now count the line numbers on a sample page, and see if you need to adjust the amplification factor. Rinse and repeat. Once you've got the right number of lines, play with the offset value until "1" lines up with the first line of your pdf text. Save a screenshot of the successful values so you can remember next time!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .