Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge chapters #147

Open
red-avtovo opened this issue Apr 3, 2024 · 2 comments
Open

Merge chapters #147

red-avtovo opened this issue Apr 3, 2024 · 2 comments

Comments

@red-avtovo
Copy link

Once I download a list of chapters (issues), it would be amazing to be able to merge them together and have only 1 file that could be effortlessly imported.
Is that something that you could provide?

Especially in comics with lots of chapters it makes it cumbersome to work with tons of files instead of one really thick "book"

@sendhelpls
Copy link

sendhelpls commented Apr 8, 2024

I'm not sure about windows synates, but here we go:

Step 1: move every pdf file into one directory:
for %i in (*.pdf) do move "%i" \all - windows
find . -type f -exec mv -i {} all/ \; - linux

Step 2: rename each file to only chapter number.
for %i in (*-*.pdf) do move "%i" "%i" - windows
for file in *-*.pdf; do mv "$file" "${file##*-}";done - linux

Step 3: merge the pdf files.
for this, install the pypdf library

merger file attached as txt, but here is the code
comic merger.txt

import os
from pypdf import PdfMerger
import re

def find_pdf_files(directory):
    pdf_files = []
    for root, _, files in os.walk(directory):
        for file in files:
            if file.endswith('.pdf'):
                file_path = os.path.join(root, file)
                pdf_files.append(file_path)
                print(f'added {str(file)} to the list')
    return pdf_files

pdfs = find_pdf_files(os.getcwd())
pdfs = pdf_files_sorted = sorted(pdfs, key=lambda x: [int(s) if s.isdigit() else s.lower() for s in re.split(r'(\d+)', x)])

merger = PdfMerger()

print('merging...')
for pdf in pdfs:
    print(f'merged {pdf}.')
    merger.append(pdf)

merger.write("merged.pdf")
merger.close()

@Girbons
Copy link
Owner

Girbons commented Apr 15, 2024

That would be really cool @red-avtovo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants