Just want to merge the content of more than one pdf into a single one and the header would be a combination of all pdf's header.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
Install the Python library PyPDF2, which provides functionality for manipulating PDFs. You can install it using pip:
pip install PyPDF2
Create a Python function that merges the PDFs and adds the combined header. Here's an example:
import PyPDF2
def merge_pdfs_with_combined_header(pdf_paths, header_text, output_path):
merger = PyPDF2.PdfFileMerger()
# Read each PDF and add it to the merger object
for pdf_path in pdf_paths:
merger.append(pdf_path)
# Add the combined header to each page of the merged PDF
for page_num in range(merger.getNumPages()):
page = merger.getPage(page_num)
page.mergePage(PyPDF2.pdf.PageObject.createBlankPage(page))
header = PyPDF2.pdf.PageObject.createTextObject(header_text)
page.mergeTranslatedPage(header, 0, page.mediaBox.getHeight())
# Save the merged PDF with the combined header
merger.write(output_path)
merger.close()
Hi,
If you are familiar with code , you can try use the following
attachment_report_id = self.env['ir.attachment'].sudo().create(
report_values)
# self.env.cr.commit()
merged_attach_ids = attachment_report_id._full_path(
attachment_report_id.store_fname)
pdfWriter = PyPDF2.PdfFileWriter()
for list in attachment_list:
pdf1File = open(list, 'rb')
pdf1Reader = PyPDF2.PdfFileReader(pdf1File)
#
for pageNum in range(pdf1Reader.numPages):
pageObj = pdf1Reader.getPage(pageNum)
pdfWriter.addPage(pageObj)
#
for page in range(new_pdf.numPages):
pageObj1 = new_pdf.getPage(page)
pdfWriter.addPage(pageObj1)
pdfOutputFile = open(merged_attach_ids, 'wb')
pdfWriter.write(pdfOutputFile)
pdfOutputFile.close()
pdf1File.close()
Regards
@Cybroses
What are attachment_list, new_pdf variables in your code. Please make it clear.
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
Header and footer not showing in PDF
Đã xử lý
|
|
11
thg 10 24
|
30392 | |
|
0
thg 10 22
|
2322 | ||
|
0
thg 4 22
|
857 | ||
|
0
thg 3 21
|
2241 | ||
[SOLVED] v14 save report to PDF
Đã xử lý
|
|
1
thg 2 21
|
4905 |