- Timestamp:
- 29 Sep 2020, 08:26:52 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py
r16159 r16253 772 772 return getUtility(IPDFCreator) 773 773 774 def _mergeFiles(self, mergefiles, watermark, pdf_steam): 775 merger = PdfFileMerger() 776 merger.append(StringIO(pdf_stream)) 777 for file in mergefiles: 778 if watermark: 779 # Pass through all pages of each file 780 # and merge with watermark page. Paint 781 # watermark first to make it transparent. 782 marked_file = PdfFileWriter() 783 orig_file = PdfFileReader(file) 784 num_pages = orig_file.getNumPages() 785 for num in range(num_pages): 786 watermark_file = PdfFileReader(watermark) 787 page = watermark_file.getPage(0) 788 page.mergePage(orig_file.getPage(num)) 789 marked_file.addPage(page) 790 # Save into a file-like object 791 tmp1 = StringIO() 792 marked_file.write(tmp1) 793 # Append the file-like object 794 merger.append(tmp1) 795 else: 796 # Just append the file object 797 merger.append(file) 798 # Save into a file-like object 799 tmp2 = StringIO() 800 merger.write(tmp2) 801 return tmp2.getvalue() 802 774 803 def renderPDF(self, view, filename='slip.pdf', student=None, 775 804 studentview=None, … … 777 806 note=None, signatures=None, sigs_in_footer=(), 778 807 show_scans=True, topMargin=1.5, 779 omit_fields=()): 808 omit_fields=(), 809 mergefiles=None, watermark=None): 780 810 """Render pdf slips for various pages (also some pages 781 811 in the applicants module). … … 867 897 type="danger") 868 898 return view.redirect(view.url(view.context)) 899 if mergefiles: 900 return self._mergeFiles(mergefiles, watermark, pdf_steam) 869 901 return pdf_stream 870 902 … … 940 972 letterhead_path=letterhead_path) 941 973 if mergefiles: 942 merger = PdfFileMerger() 943 merger.append(StringIO(pdf_stream)) 944 for file in mergefiles: 945 if watermark: 946 # Pass through all pages of each file 947 # and merge with watermark page. Paint 948 # watermark first to make it transparent. 949 marked_file = PdfFileWriter() 950 orig_file = PdfFileReader(file) 951 num_pages = orig_file.getNumPages() 952 for num in range(num_pages): 953 watermark_file = PdfFileReader(watermark) 954 page = watermark_file.getPage(0) 955 page.mergePage(orig_file.getPage(num)) 956 marked_file.addPage(page) 957 # Save into a file-like object 958 tmp1 = StringIO() 959 marked_file.write(tmp1) 960 # Append the file-like object 961 merger.append(tmp1) 962 else: 963 # Just append the file object 964 merger.append(file) 965 # Save into a file-like object 966 tmp2 = StringIO() 967 merger.write(tmp2) 968 return tmp2.getvalue() 974 return self._mergeFiles(mergefiles, watermark, pdf_steam) 969 975 return pdf_stream 970 976
Note: See TracChangeset for help on using the changeset viewer.