@@ -648,32 +648,11 @@ def build_zip(record_summary: RecordSummary, user_information_dict: Dict[str, st
648648 osp_file_info = FormFilling ._create_and_write_pdf (user_information_dict_2 , temp_dir )
649649 zip_file .write (* osp_file_info [0 :2 ])
650650
651- #todo: refactor and build separate method to compose compiled
652651 if all_motions_to_set_aside :
653- compiled = PdfWriter ()
654-
655- # Must rename all the fields in the file so they are unique so that Acrobat doesn't mess with their values.
656- reader = PdfReader (all_motions_to_set_aside .pop (0 )[0 ])
657- start_index = 0
658- field_count = FormFilling .rename_fields (reader , start_index )
659- start_index += field_count
660- compiled .addpages (reader .pages )
661- for f in all_motions_to_set_aside :
662- reader = PdfReader (f [0 ])
663- field_count = FormFilling .rename_fields (reader , start_index )
664- start_index += field_count
665- compiled .addpages (reader .pages )
666-
667- reader = PdfReader (osp_file_info [0 ])
668- FormFilling .rename_fields (reader , start_index )
669- compiled .addpages (reader .pages )
670-
671- # Must update the appearances property so that the fields render correctly in Acrobat.
672- compiled .trailer .Root .AcroForm = PdfDict (NeedAppearances = PdfObject ("true" ))
673-
652+ file_paths = [f [0 ] for f in all_motions_to_set_aside ] + [osp_file_info [0 ]]
674653 comp_name = "COMPILED.pdf"
675654 comp_path = path .join (temp_dir , comp_name )
676- compiled . write ( comp_path )
655+ FormFilling . compile_pdfs ( file_paths , comp_path )
677656 zip_file .write (comp_path , comp_name )
678657
679658
@@ -697,6 +676,18 @@ def rename_fields(reader: PdfReader, start_index: int) -> int:
697676 field [PdfName ('T' )] = new_name
698677 return len (fields )
699678
679+ @staticmethod
680+ def compile_pdfs (file_paths : List [str ], output_path : str ) -> None :
681+ compiled = PdfWriter ()
682+ start_index = 0
683+ for file_path in file_paths :
684+ reader = PdfReader (file_path )
685+ field_count = FormFilling .rename_fields (reader , start_index )
686+ start_index += field_count
687+ compiled .addpages (reader .pages )
688+ compiled .trailer .Root .AcroForm = PdfDict (NeedAppearances = PdfObject ("true" ))
689+ compiled .write (output_path )
690+
700691 @staticmethod
701692 def build_summary_filename (aliases ):
702693 first_alias = aliases [0 ]
0 commit comments