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
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
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.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
11
Oct 24
|
26950 | ||
|
0
Oct 22
|
1807 | ||
|
0
Apr 22
|
857 | ||
|
0
Mar 21
|
1753 | ||
|
1
Feb 21
|
4262 |