Hi !
Good day! I’m John from http://bai.ph/
We came up to add up a feature that allows adding background images/watermark in every page of pdf files.
Current stage: we are able to repeat the images every pdf page
the image that we want to be repeated is the one on the left-most part
here’s what we did:
added this function to /frappe-bench/apps/frappe/frappe/utils/pdf.py
def append_pdf_test(fname):
from reportlab.pdfgen import canvas
from PyPDF2 import PdfFileWriter, PdfFileReader
import getpass
# Create the watermark from an image c = canvas.Canvas('watermark.pdf')
# Draw the image at x, y. I positioned the x,y to be where i like here c.drawImage('/home/'+getpass.getuser()+'/frappe-bench/sites/development/public/files/Side.png', 0, 250)
c.save()
# Get the watermark file you just created watermark = PdfFileReader(open("watermark.pdf", "rb"))
# Get our files ready output_file = PdfFileWriter() input_file = PdfFileReader(open(fname, "rb")) #input_file = filedata
# Number of pages in input document page_count = input_file.getNumPages()
# Go through all the input file pages to add a watermark to them for page_number in range(page_count): print "Watermarking page {} of {}".format(page_number, page_count) # merge the watermark with the page input_page = input_file.getPage(page_number) input_page.mergePage(watermark.getPage(0)) # add page from input file to output document output_file.addPage(input_page)
# finally, write "output" to document-output.pdf fname = "/home/"++getpass.getuser()++"/document-output.pdf" with open(fname, "wb") as outputStream: output_file.write(outputStream)
return fname
Full file
Our next step is to add fields in Letter head, the fields are: Image file/path, X position, Y position, and a child table in where we can select which print format will this background/watermark will show.
UPDATE!
added watermark Type Attach Image in Letter Head doctype
Credits to our client http://code.ag/ for opening up this idea.
We are open for suggestions, if anybody else has a better approach on this. Looking forward