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
- Księgowość
- Zapasy
- PoS
- Project
- MRP
To pytanie dostało ostrzeżenie
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.
Podoba Ci się ta dyskusja? Dołącz do niej!
Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!
Zarejestruj sięPowiązane posty | Odpowiedzi | Widoki | Czynność | |
---|---|---|---|---|
Header and footer not showing in PDF
Rozwiązane
|
|
11
paź 24
|
28134 | |
|
0
paź 22
|
2035 | ||
|
0
kwi 22
|
857 | ||
|
0
mar 21
|
1977 | ||
[SOLVED] v14 save report to PDF
Rozwiązane
|
|
1
lut 21
|
4558 |