Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How do I concatenate two PDF reports? [Closed]

By
AJ Schrafel Paper Corp
on 5/7/13, 3:05 AM 2,210 views

The Question has been closed

by
AJ Schrafel Paper Corp
on 06/27/2013 17:57:52

I have 2 pdfs stored as strings. I want to store them as a temporary file on the server. My problem is the PDF is not properly being stored. Whatever file is written second over writes the file that is written first. Seperately, the 2 files can be stored like this and if you reverse the order of the files the second file always over writes the first.

        fd, file_name = mkstemp()
        temp = result
        temp2 = base64.decodestring(record.attachment_id.datas)

        output = ''.join([temp,"\f",temp2])
        os.write(fd, output)

I want to insert a new page character or something to prevent the second file from over writing the second file in the PDF. What can I do to concatenate 2 PDFs in openerp?

0

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
2050
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 5/7/13, 5:58 PM

This is the way i finally got it to work, but this seems overly complicated. There has to be a way to concatenate the PDFs without storing them as temporary files first.

fd, file_name = mkstemp()
fd2, file_name2 = mkstemp()
fd3, file_name3 = mkstemp()
os.write(fd, result)
os.write(fd2, base64.decodestring(record.attachment_id.datas))

output = PdfFileWriter()
pdfOne = PdfFileReader(file(file_name, "rb"))
pdfTwo = PdfFileReader(file(file_name2, "rb"))

pgcnt=pdfOne.getNumPages()
for i in range(0,pgcnt):
    output.addPage(pdfOne.getPage(i))
pgcnt=pdfTwo.getNumPages()
for i in range(0,pgcnt):
    output.addPage(pdfTwo.getPage(i))

outputStream = file(file_name3, "wb")
output.write(outputStream)
outputStream.close()
0

Gustavo

--Gustavo--
950
| 2 1 4
Buenos Aires, Argentina
--Gustavo--

Python developer, big fan of sailing

Gustavo
On 5/7/13, 12:03 PM

this post on how to merge two pdf files will help you:

http://mygisblog.wordpress.com/2011/08/26/merging-pdf-files-with-python/

no that doesn't help, that is for merging PDFs that are files, I am trying to merge PDFs that are stored in the openERP database. When I put the name of the variable storing the PDF into PdfFileReader, I get an error that the input is a string.

AJ Schrafel Paper Corp
on 5/7/13, 12:09 PM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 5/7/13, 3:05 AM
Seen: 2210 times
Last updated: 3/16/15, 8:10 AM