Python FPDF output pdf file version upper than 1.3 (Acrobat 4.x)

Viewed 127

I'm creating pdf files using FPDF. FPDF create file version 1.3 (Acrobat 4.x)

Is there a way to output files in a version upper to 1.3? (like 1.5, or 1.6)

I need it because I'm trying to attach the file to an email using MIMEApplication, but MIME do not works if a try to attach pdf version 1.3

1 Answers

you can modify the source code to version

https://github.com/reingart/pyfpdf/blob/cb3340806c140b6e63eb4ce9d6230be84fba456e/fpdf/fpdf.py#L146

update: it doesn't have with PDF version i added a working example with PDF 1.3

import smtplib
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
from os.path import basename

from fpdf import FPDF

# pdf as string
pdf = FPDF()
pdf.add_page()
pdf.set_font('Arial', 'B', 16)
pdf.cell(40, 10, 'Hello World!')

name = 'hello.pdf'
s = pdf.output(dest='S').encode('latin-1')

send_from = '***@gmail.com'
email_list = ['***@gmail.com']
msg = MIMEMultipart()
msg['Subject'] = 'test'
msg['From'] = 'SCRIPT NOTIFICATION'
msg['To'] = COMMASPACE.join(email_list)
msg['Date'] = formatdate(localtime=True)

costext = 'file attached below'
msg.attach(MIMEText(costext))

part = MIMEApplication(
    s,
    Name=basename(name)
)
# After the file is closed
part['Content-Disposition'] = 'attachment; filename="%s"' % basename(name)
msg.attach(part)

try:
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.ehlo()
    server.starttls()
    server.login('email@gmail.com', 'password')
    server.sendmail(send_from, email_list, msg.as_string())

except:
    print("failed to send email")

enter image description here

Related