How to put line numbers on existing blank pages?

I have a document comprising of a few hundred blank pages (different page sizes and orientations) that I wish to put line numbers on. I can enable line numbering in Writer, however when I hold the enter key down, and get to the end of the first page, a new page is created. I don’t want this, as I want the line numbers to flow onto the next blank page. Attached at the bottom is a small sample of the blank pages that I wish to fill with line numbers (various sizes and orientation). I need a quick way to do this, as in practice I will have hundreds of blank pages, and the order,orientation, size of these blank pages must be preserved. I simply want line numbers from the top to bottom on these existing blank pages. Is there a setting I can change in Writer to enable this, or alternatively does anyone have any example of a macro script that would work?

EDIT - I have found an ugly hack to do what I want to do. But am still looking for a way to do this in Writer. Below is the approach I have taken:

The only way I have found to accomplish my task is to fill up a single page completely with a text character and export to PDF. I then export my few hundred blank pages to pdf and use a simple command line program to overlay the single page with the text character onto the hundreds of blank pages. Once this is complete, I then convert this pdf to ODT and I once again have my blank pages in writer, but these are filled with a single text character. To get rid of this text character, I then use “find and replace” and replace the character with a blank space. I then turn on line numbering and have line numbers on my blank pages. This works perfectly for what I want to achieve, but I can’t believe there is no way to put line numbers on existing blank pages in Writer, either by a macro or some other trick.

Blank pages.odt

Test file created by leory method:
test.odt

You haven’t explained what you really want, and what you expect will happen when you add text. Do the numbers have to be printable? See your previous question 287282

If you just want printable blank pages with numbers at the beginning using your layouts then you could just do a numbered list on the first page. Click on first page and press F12, click Edit > Direct Cursor Mode then carefully click at the bottom of your page just out from the margin, the page should fill with numbers, click Edit > Direct Cursor Mode to turn off Direct Cursor Mode.

Copy the list and paste it on each subsequent page.

You are using 5 names for 2 page styles. You can use 2 styles (MP0 and MP1), activating headers and adding a frame to the header with a table with numbers. See sample file line numbers on existing blank pages.odt with table in MP0 style.

Tested with LibreOffice 6.4.7.2 (x86); OS: Windows 6.1.


Add Answer is reserved for solutions. Please, click edit below your question to add more information.

Good point @LeroyG. I would be inclined to combine both, although I don’t understand the purpose of the exercise.

Create a frame anchored to page (so it is outside the text, Wrap to right. There seems to be a fixed number of pages so insertion of pages wouldn’t be an issue).

Take the numbered list I described from the first page and paste into frame. Adjust the frame so the numbers accurately align with some dummy text, ensure same style as body.

Copy and paste it into every page. Sequential numbering from 1 to around 16000.

I just realize my mistake:

I want the line numbers to flow onto the next blank page

So my approach does not work.

By the way, tables only allow 8192 rows.

Thanks Earnest, I think the list approach could very well work, but how can the numbers distance from the left margin be changed? If possible I want the numbers in the list flush with the left margin.

Secondly, you say about copying the list and pasting it on each subsequent page. This works, but is there a way to automate this process with a macro? Do you have an example of macro code that I could use for this?

Many thanks

@EarnestAl: the frame is not anchored To page. If it is, the frame must effectively be manually inserted on every page. It is in fact anchored To paragraph in the header. Thus it is automatically repeated on every instance of the same page style.

@ajlittoz I don’t know the purpose of the exercise but it seems to have a definite number of blank pages of differing styles. If the frame is anchored to the header (there is no room for a header in the sample given) then I don’t know if the the numbering would remain sequential from style to style, but it would require more work on each change of page.style.

You are absolutely right, Anchored to page can cause big problems. An inserted page later on would not get a sequentially numbered frame and might break the numbering if there were an attempt to paste a frame from another page.

Another way to do this would be to fill every existing page with line breaks and then turn on numbering (like in the Picture Example below). But is there some automatic way to fill every existing page with line breaks, either with some macro code or other automated way?

Picture Example

The fact that we try to outsmart Writer clearly shows this track is not the good one.

Let’s get back to the original problem: annotate a document. You said it is a PDF. Who created it? If you did, make a Writer version of it and work with it. If you annotate somebody else’s work, then it is not in its final shape. Request an editable copy of it.

Annotations are best made with the comment feature. Proof reading fixes use the track changes feature.

As a last resort, find some OCR application to transform the PDF into plain text at least. You’ll format it once and work on it from there on.

I did not create the PDF documents, so don’t have the source. OCR is a very bad approach, as it is time consuming and can change the formatting. PDF editors are a bad option, as I can only work on one page at a time. For thousands of pages this is tedious. If I can just find a way to fill these existing blank pages with line breaks, then I can turn on numbering in writer. It’s then so simple and quick to overlay one pdf to another pdf.

I mentioned OCR as a last resort measure because, as you rightfully point out, you must rebuild the formatting. But you however do it only once, provided the original document does not get edited over and over.

The simplest and best way is to request an editable copy from the author.

The task you describe in a comment of 287498/how-to-delete-all-page-content-but-leave-blank-pages would be much easier if you had an .odt (or eventually a .doc(x)) because you would then change Default Style to set font colour to white. Thus text is still there, formats the same but does not print. This is the only trick I know to be sure the structure of the document remains the same.

way to put line numbers on existing blank pages in Writer

Pages do not exist in Writer until text request a page to be laid out on. In addition line numbering numbers only existing lines. So if your page is blank (i.e. has no contents, save perhaps a single empty paragraph), you won’t get any numbering (save again 1 in front of the empty paragraph).

As said, line numbering numbers lines. If your page is blank, how tall would be potential lines? They don’t exist and consequently have no formatting. Which font size should be used? Which spacing between paragraphs (this space is not numbered)? Etc.

Once again, you’re trying to use Writer outside its designed domain. This explains why it is so difficult.

Create a numbered list Click on first page and press F12, click Edit > Direct Cursor Mode then carefully click at the bottom of your page just out from the margin, the left of the page should fill with numbers, click Edit > Direct Cursor Mode to turn off Direct Cursor Mode.

Create a frame interactively, anchored to page (so it is outside the text, Page Wrap. There seems to be a fixed number of pages so insertion of pages wouldn’t be an issue).

Cut the numbered list described above and paste into frame. Alter the numbering: right-click, select Bullets and Numbering. In the dialog that opens select the Position tab, change Aligned at to 0.0 cm, Numbering followed by Nothing, Indent at 0.0 cm, OK.

Select the list and change Paragraph Style to Text Body (assuming your text uses Text Body style). Modify Text Body Style so there is no extra space after the end of a paragraph. (If you want a paragraph spacing then use two returns

Adjust the frame so the numbers accurately align with some dummy text, ensure same style (Text Body).

Copy and paste the frame into every page starting from the last page and working backward. For some reason the the numbers reverse their order after saving and closing in LO 6.4.7.2; is this a known issue?).

Sequential numbering from 1 to around 10000 for two hundred pages pasting at 3 seconds per page = 600 hundred seconds = 10 minutes. Sorry, I cannot help with a macro.

Sample attached

I had assumed the problem might have been related to translation/study of/transcription of a document, probably a hard to read one.

Given the discussion above I don’t believe that that trying to number lines in a pasted/inserted pdf is going to work. Line spacing would have to match exactly on each individual page. There are no shortcuts. As @ajlittoz says OCR the pdf.

It is worth getting the best OCR program you can buy for a task like this, something that allows you to edit and correct the OCR within the program itself. Trying to use the OCR program’s layout rendering is likely to create a big mess so export as plain text and maybe recreate the layout in LO, but only if it really is important. The blank sample pages look like they would be hard work for a reader.

Line spacing does not have to match the exact text. It is only there for a rough reference. The only way I have found to accomplish my task is to fill up a single page completely with a text character and export to PDF. I then export my few hundred blank pages to pdf and use a simple command line program to overlay the single page with the text character onto the hundreds of blank pages. Once this is complete, I then convert this pdf to ODT and I once again have my blank pages in writer, but these are filled with a single text character. To get rid of this text character, I then use “find and replace” and replace the character with a blank space. I then turn on line numbering and have line numbers on my blank pages. This works perfectly for what I want to achieve, but I can’t believe there is no way to put line numbers on existing blank pages in Writer, either by a macro or some other trick.

Just curious. Did you try copying the frame from my sample and pasting it into some pages?

Yes the list method works, but it is necessary to click on every page. I am trying to cut down the amount of manual steps. But thanks for your suggestion

An option editing the content.xml file to add new paragraphs and create a numbered list with the paragraphs of all pages:

  • Add a second paragraph in page 1 (it will be useful to add some content to this paragraph to find it easily a few steps latter).
  • Save.
  • Extract and edit the content.xml file.
  • Find the recently added paragraph, take note of the style-name, and detele the paragraph.¹
  • Find <text:p text:style-name="P[0-5]"/> and replace all 80 times² with &<text:p text:style-name="P6"/>
  • Save and replace the content.xml file in its container file.
  • Open the file.
  • Select all.
  • Press F12 to create numbered list.

Edit: Your sample file has 5 page styles: P1-P5. Note the P[0-5] in the find text that I proposed (no P6). You need to Find & Replace; just 80 clicks on the Replace All button (no Paste 80 times). Each click add a new paragraph to each page. Maybe instead of P[0-5] you need to use P[0-9]{1,3} (this will search from P0 to P999).

The style-name of the paragraph with AAAAAAA content is P6? Or instead of 6 there is another number close to a few hundred?

All pages in the document have the same height (as in the sample)? In that case 80 additional paragraphs per page are enough. If not, there we have a problem. I don’t know how many page sizes this work has, but a better way around this problem is to use a single page style for all pages of the same size (something I suggested in my first comment). That way, in each style the new paragraph could be added a different number of times.

¹ <text:p text:style-name="P6">some content</text:p>; P6 is the style-name of the new paragraph.

² 81 lines fit on each page.

³ I used [0-5] and P6 based on the sample provided.

Tested with LibreOffice 6.4.7.2 (x64); OS: Windows 10.0.


Add Answer is reserved for solutions. If you think the answer is not satisfactory, add a comment below, or click edit (below your question) to add more information. Thanks.

Check the mark (Answer markCorrect answer mark) to the left of the answer that solves your question.

If the answer helped you, you can mark the up arrow (Upvote mark) that is on the left (to vote, you need to have karma of at least 5).

Thanks for your reply. I added a paragraph with the wording AAAAAAA, saved and extracted the content.xml. As per your instructions, I replaced with <text:p text:style-name=“P6”/> and pasted 80 times (adding prefix “&” before the string results in error). I then replaced the content.xml. But pasting 80 times just fills the first page. I don’t understand why it is pasted 80 times? While 80 times may fill one page size, what happens if there are many mixed page sizes in the same document? You would have to work out how many times you have to paste it for each page of different sizes and then edit the content.xml accordingly. It would be very tedious with hundreds of pages of different sizes.

Attached below is the test file that I create with your method. I don’t understand how the method can quickly work for a document comprising of many pages of different sizes? Please look at the following test file created with your method:
test.odt