def test_embed_fonts(): input_pdf = BytesIO(multi_page_pdf) assert contains_unembedded_fonts(input_pdf) new_pdf = embed_fonts(BytesIO(multi_page_pdf)) assert not contains_unembedded_fonts(new_pdf)
def rewrite_pdf(file_data, *, page_count, allow_international_letters, filename): file_data, recipient_address, redaction_failed_message = rewrite_address_block( file_data, page_count=page_count, allow_international_letters=allow_international_letters, ) if not does_pdf_contain_cmyk(file_data) or does_pdf_contain_rgb(file_data): file_data = convert_pdf_to_cmyk(file_data) if contains_unembedded_fonts(file_data): file_data = remove_embedded_fonts(file_data) if contains_unembedded_fonts(file_data): # To start with log this is happening, later mark file as validation-failed current_app.logger.info( f"File still contains embedded fonts after remove_embedded_fonts for file name {filename}" ) else: current_app.logger.info( f"File no longer contains embedded fonts for file name {filename}" ) # during switchover, DWP and CYSP will still be sending the notify tag. Only add it if it's not already there if not is_notify_tag_present(file_data): file_data = add_notify_tag_to_letter(file_data) return file_data, recipient_address, redaction_failed_message
def rewrite_pdf(file_data, *, page_count, allow_international_letters): file_data, recipient_address, redaction_failed_message = rewrite_address_block( file_data, page_count=page_count, allow_international_letters=allow_international_letters, ) if not does_pdf_contain_cmyk(file_data) or does_pdf_contain_rgb(file_data): file_data = convert_pdf_to_cmyk(file_data) if contains_unembedded_fonts(file_data): file_data = remove_embedded_fonts(file_data) # during switchover, DWP and CYSP will still be sending the notify tag. Only add it if it's not already there if not is_notify_tag_present(file_data): file_data = add_notify_tag_to_letter(file_data) return file_data, recipient_address, redaction_failed_message
def test_contains_unembedded_fonts(client, pdf_file, has_unembedded_fonts): assert bool(contains_unembedded_fonts(pdf_file)) == has_unembedded_fonts