Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

add text to pdf file in python

from PyPDF2 import PdfFileWriter, PdfFileReader, PdfFileMerger

import StringIO

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter

packet = StringIO.StringIO()
# create a new PDF with Reportlab
can = canvas.Canvas(packet, pagesize=letter)
can.drawString(290, 720, "Hello world")
can.save()

#move to the beginning of the StringIO buffer
packet.seek(0)
new_pdf = PdfFileReader(packet)
# read your existing PDF
existing_pdf = PdfFileReader("original.pdf")
output = PdfFileWriter()
# add the "watermark" (which is the new pdf) on the existing page
page = existing_pdf.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
# finally, write "output" to a real file
outputStream = open("destination.pdf", "wb")
output.write(outputStream)
outputStream.close()
Comment

add text to pdf file in python

packet = StringIO.StringIO()
can = canvas.Canvas(packet, pagesize=letter)
<do something with canvas>
can.save()
packet.seek(0)
input = PdfFileReader(packet)
Comment

PREVIOUS NEXT
Code Example
Python :: pandas dt.weekday to string 
Python :: python __truediv__ 
Python :: Python __sub__ magic method 
Python :: Python how to use __ge__ 
Python :: create different size matplotlib 
Python :: NumPy unique Example Identify the index of the first occurrence of unique values 
Python :: p0, percent, aug (inhabitants coming or leaving each year), p (population to surpass) 
Python :: track keyboard press pynput 
Python :: visualize 3 columns of pandas 
Python :: NumPy packbits Code Packed array along default axis 
Python :: django view - Generic class based view (listc, create, retrieve, update or delete - GET, POST, GET, PUT, DELETE) 
Python :: center pyfiglet to terminal 
Python :: cast set 
Python :: penggunaan len di python 
Python :: call a Python range() using range(start, stop) 
Python :: how to process numerical data machine learning 
Python :: XML to table form in Excel 
Python :: tensorflow 1.x spp implementation 
Python :: python readlines  
Python :: sqlite basic 
Python :: AJAX/FLASK/JS: How to POST existing array into endpoint 
Python :: socialscan 
Python :: for y in range(10): for x in range(y): print("*",end=') print() 
Python :: ring Create Lists 
Python :: delet categories from coco dataset 
Python :: Sum of diagonal elements of a matrix python without numpy 
Python :: open file find and replace commas python 
Python :: django create ap 
Python :: pip is not recognized as an internal or external command 
Python :: voilion plot 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =