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

error Object 203 0 not defined when using stub_to_print #8

Open
g-raffy opened this issue Jun 10, 2024 · 2 comments
Open

error Object 203 0 not defined when using stub_to_print #8

g-raffy opened this issue Jun 10, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@g-raffy
Copy link
Owner

g-raffy commented Jun 10, 2024

Object 203 0 not defined.
Traceback (most recent call last):
  File "./mno.py", line 3907, in <module>
    prints_for_20240612()
  File "./mno.py", line 3904, in prints_for_20240612
    piece.build_print(track_selector, prints_dir=output_dir)
  File "/home/graffy/private/dev/pymusco/src/pymusco/piece.py", line 232, in build_print
    stub_to_print(
  File "/home/graffy/private/dev/pymusco/src/pymusco/main.py", line 429, in stub_to_print
    toto_pdf.add_page(track_page)
  File "/home/graffy/private/melting-notes/partitions/partitions.venv/lib/python3.8/site-packages/PyPDF2/_writer.py", line 321, in add_page
    return self._add_page(page, list.append, excluded_keys)
  File "/home/graffy/private/melting-notes/partitions/partitions.venv/lib/python3.8/site-packages/PyPDF2/_writer.py", line 271, in _add_page
    page = cast("PageObject", page_org.clone(self, False, excluded_keys))
  File "/home/graffy/private/melting-notes/partitions/partitions.venv/lib/python3.8/site-packages/PyPDF2/generic/_data_structures.py", line 181, in clone
    d__._clone(self, pdf_dest, force_duplicate, ignore_fields)
  File "/home/graffy/private/melting-notes/partitions/partitions.venv/lib/python3.8/site-packages/PyPDF2/generic/_data_structures.py", line 243, in _clone
    v.clone(pdf_dest, force_duplicate, ignore_fields)
  File "/home/graffy/private/melting-notes/partitions/partitions.venv/lib/python3.8/site-packages/PyPDF2/generic/_base.py", line 248, in clone
    assert obj is not None
AssertionError
@g-raffy g-raffy added the bug Something isn't working label Jun 10, 2024
@g-raffy g-raffy self-assigned this Jun 10, 2024
@g-raffy
Copy link
Owner Author

g-raffy commented Jun 10, 2024

Here's what I found until now:

  • The bug seems to be revealed by the "hautbois 1" page, which is clearly different from other pages (it('s not an original track, it has been created by someone else, and has different properties: unlike the other pdf pages, it doesn't contain a /Group element)).
  • the bug disappears when the stamps are not added
  • the bug seems to be in pdftex, see [https://tex.stackexchange.com/questions/76273/multiple-pdfs-with-page-group-included-in-a-single-page-warning]

@g-raffy
Copy link
Owner Author

g-raffy commented Jun 10, 2024

Here's a test function that exhibits the bug:

def bug_shower_1(trigger_bug: bool):
    src_pdf_file_path = Path('/home/graffy/private/melting-notes/partitions/scans/888-bug.pdf')

    tmp_dir = Path('/home/graffy/private/dev/pymusco/tickets/ticket0008/tmp')

    scanned_image_file_paths = []
    with open(src_pdf_file_path, 'rb') as src_pdf_file:
        pdf_reader = PyPDF2.PdfReader(src_pdf_file)
        page_index = 0
        for page in pdf_reader.pages:
            print(f'============= page_index = {page_index}')
            # image_file_path = extract_pdf_page_main_image(page, image_dir=tmp_dir, image_name=('page%03d' % page_index))
            image_file_path = extract_pdf_page(page, image_dir=tmp_dir, image_name=f'page{page_index:03d}')
            print(image_file_path)
            # check_pdf_file(image_file_path)

            scanned_image_file_paths.append(image_file_path)
            page_index += 1

    # stamp_descs = stamp_descs if stamp_descs is not None else []

    orchestra = load_orchestra('/home/graffy/private/dev/pymusco/samples/harmony.orchestra')

    piece = load_piece_description(Path('/home/graffy/private/melting-notes/partitions/scans/888-bug.desc'), orchestra)

    dst_stub_pdf_file_path = Path('/home/graffy/private/dev/pymusco/tickets/ticket0008/stub.pdf')
    toc = piece.scan_toc

    if trigger_bug:
        stamp_descs = piece.stamp_descs
    else:
        stamp_descs = []

    images_to_pdf(StubContents(image_file_paths=scanned_image_file_paths, toc=toc, title='toto', stamp_descs=stamp_descs, page_info_line_y_pos=1.0), dst_stub_pdf_file_path)

    # check_pdf_file(dst_stub_pdf_file_path)

    dst_stub_copy_pdf_file_path = Path('/home/graffy/private/dev/pymusco/tickets/ticket0008/stub-copy.pdf')
    duplicate_pdf_file_001(dst_stub_pdf_file_path, dst_stub_copy_pdf_file_path)
    # check_pdf_file(dst_pdf_file_path)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant