Python Forum
[SOLVED] Renumber page numbers and write result to file?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] Renumber page numbers and write result to file?
#1
Question 
Hello,

Before I look further, is there an easier way I should know about to modify the page number on each line in a PDF's bookmark file?

I removed the ToC at the beginning, so each page number should have 11 substracted to it to match the new order.

Cheers,

import re

#0 "My title" 24 → 0 "My title" 13
pattern_number = re.compile("^0 .+ (\d+)$")

with open('bookmarks.txt', encoding="utf-8") as reader:
	for line in reader.readlines():
		if (m := pattern_number.search(line)):
			print(m.group(1))
			#rewrite line

#save all to file
--
Edit: LibreOffice Calc to the rescue

   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  If I open a file write or append, is the file loaded into RAM? Pedroski55 11 1,146 Jan-14-2026, 07:49 AM
Last Post: Pedroski55
Question [SOLVED] Linefeed when writing "f" strings to text file? Winfried 5 897 Nov-04-2025, 11:51 AM
Last Post: buran
  how to write/overwrite data in a txt. file according to inp Quinn 2 1,608 Aug-12-2025, 04:20 PM
Last Post: Quinn
Question [SOLVED] Open file, and insert space in string? Winfried 7 2,576 May-28-2025, 07:56 AM
Last Post: Winfried
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 13 36,787 May-20-2025, 12:26 PM
Last Post: hanmen9527
Question [SOLVED] [Beautiful Soup] Replace tag.string from another file? Winfried 2 1,703 May-01-2025, 03:43 PM
Last Post: Winfried
  How to write variable in a python file then import it in another python file? tatahuft 4 2,288 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  [SOLVED] [Linux] Write file and change owner? Winfried 6 3,263 Oct-17-2024, 01:15 AM
Last Post: Winfried
  [SOLVED] Reportlab - change a single page orientation beetlecad 1 5,009 Aug-16-2024, 05:43 PM
Last Post: beetlecad
  [solved] how to delete the 10 first lines of an ascii file paul18fr 7 4,251 Aug-07-2024, 08:18 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020