Title: PdfWriter add_page adds (re)writes old page instead of new · Issue #135062 · python/cpython · GitHub
Open Graph Title: PdfWriter add_page adds (re)writes old page instead of new · Issue #135062 · python/cpython
X Title: PdfWriter add_page adds (re)writes old page instead of new · Issue #135062 · python/cpython
Description: Bug report Bug description: The purpose of the following code (as a simplification) is to add PDF pages alternatively from 2 different opencv images. To make the sequence unique, a sequence number is written to each PDF page saved. The P...
Open Graph Description: Bug report Bug description: The purpose of the following code (as a simplification) is to add PDF pages alternatively from 2 different opencv images. To make the sequence unique, a sequence number ...
X Description: Bug report Bug description: The purpose of the following code (as a simplification) is to add PDF pages alternatively from 2 different opencv images. To make the sequence unique, a sequence number ...
Opengraph URL: https://github.com/python/cpython/issues/135062
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PdfWriter add_page adds (re)writes old page instead of new","articleBody":"# Bug report\n\n### Bug description:\n\nThe purpose of the following code (as a simplification) is to add PDF pages alternatively from 2 different opencv images.\nTo make the sequence unique, a sequence number is written to each PDF page saved. The PDF is written every 2 images but this is not essential\nHerewith I expect a resulting PDF file with 60 pages numbered #1, #2, #3, ... #59, #60.\n\nHowever the resulting PDF file shows a sequence which in my case starts erratically from the 25th page:\n#1, #2, #3, #4, #5, #6, #7, #8, #9, #10, #11, #12, #13, #14, #15, #16, #17, #18, #19, #20, #21, #22, #23, #24, #20, #22, #18, #19, #29, #30.\n#31, #32, #33, #34, #35, #36, #37, #38, #39, #40, #36, #37, #34, #35, #32, #33, #30, #31, #19, #29, #21, #18, #24, #20, #55, #23, #57, #23, #59, #20\n \n#25, #26, #27, #28 are missing an have been substituted by #20, #21, #18, #19.\nThen everything is back on track to #40\nIn the remainder of the sequence #55, #57 and #59 are on the right page. The rest shows an 'older' page \n\nThe import of PyPDF2 is version 3.0.1\n\n[pythonSeq.pdf](https://github.com/user-attachments/files/20565415/pythonSeq.pdf)\n\n```if os.path.exists(\"pythonSeq.pdf\"):\n os.remove(\"pythonSeq.pdf\")\n\npdf_writer = PdfWriter()\n\nimage1 = cv2.imread(\"Picture1.png\")\nimage2 = cv2.imread(\"Picture2.png\")\nfor seq in range(1,61,2):\n clone = image1.copy()\n cv2.putText(clone,f'Seq#{seq}', (200,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 3)\n cv2.imwrite(\"python.jpg\",clone)\n pdf_image = Image.open(\"python.jpg\")\n pdf_image.save(\"python.pdf\", format=\"PDF\")\n image_reader = PdfReader(\"python.pdf\")\n pdf_writer.add_page(image_reader.pages[0])\n\n clone = image2.copy()\n cv2.putText(clone,f'Seq#{seq+1}', (200,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 3)\n cv2.imwrite(\"python.jpg\",clone)\n pdf_image = Image.open(\"python.jpg\")\n pdf_image.save(\"python.pdf\", format=\"PDF\")\n image_reader = PdfReader(\"python.pdf\")\n pdf_writer.add_page(image_reader.pages[0])\n\n[pythonSeq.pdf](https://github.com/user-attachments/files/20565446/pythonSeq.pdf)\n\n with open(\"pythonSeq.pdf\", \"wb\") as pdf_file:\n pdf_writer.write(pdf_file)```\n\n\n### CPython versions tested on:\n\n3.13\n\n### Operating systems tested on:\n\nWindows","author":{"url":"https://github.com/DominiquePACCO","@type":"Person","name":"DominiquePACCO"},"datePublished":"2025-06-03T08:55:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/135062/cpython/issues/135062"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4598ed43-2ef4-236a-4cd3-02c238fb0b49 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE4A:1940BA:102121A:1587B60:69699264 |
| html-safe-nonce | 1904c3ff8d4d281f64f96ce923b280bee913c52ba3cb9c847c04cb780052a499 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTRBOjE5NDBCQToxMDIxMjFBOjE1ODdCNjA6Njk2OTkyNjQiLCJ2aXNpdG9yX2lkIjoiMzE2MzQ4NjM1NDUzOTUyNjEyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 370df0c80448c96352b5df9249200a80b5d01bbea20a1df756a98e0fad656ccd |
| hovercard-subject-tag | issue:3113064468 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/135062/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5b8201159d938b9c04f6b591ae7d4d1cf9314517563f19111338be6054b92fab/python/cpython/issues/135062 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5b8201159d938b9c04f6b591ae7d4d1cf9314517563f19111338be6054b92fab/python/cpython/issues/135062 |
| og:image:alt | Bug report Bug description: The purpose of the following code (as a simplification) is to add PDF pages alternatively from 2 different opencv images. To make the sequence unique, a sequence number ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DominiquePACCO |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3542e147982176a7ebaa23dfb559c8af16f721c03ec560c68c56b64a0f35e751 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | af80af7cc9e3de9c336f18b208a600950a3c187c |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width