So I contacted LinkedIn customer support thinking maybe, just maybe, I had missed some kind of check box/setting....well, no dice. They offer a "convenient" LinkedIn hyperlink which goes to my LinkedIn profile, and is also a nice viral opportunity for LinkedIn. However not having a phone number definitely hurts my chances of getting a phone call. Not cool.
Having exhausted official channels and not wanting to maintain a separate Word document it was time to take matters into my own hands. Time to fire up the Python.
hum....where is that number
Oh there it is!
Below is the code I used to composite a phone number and address over the first page. If there is overwhelming demand, maybe I'll create a web service to do this.
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch
from reportlab.lib.pagesizes import letter, A4
from pyPdf import PdfFileWriter, PdfFileReader
import cStringIO, sys
if (not len(sys.argv) == 5):
print "Usage: [file name] [phone number] [Address 1] [Address 2]"
sys.exit()
file_name = sys.argv[1]
phone = sys.argv[2]
addr1 = sys.argv[3]
addr2 = sys.argv[4]
x = 4
xSpc = 0.725
y = 11 - 2.28 # xy is in the bottom left corner
ySpc = .30
def create_addr_in_pdf():
c = canvas.Canvas("addr.pdf", pagesize=letter)
c.translate(inch,inch)
# define a large font
c.setFont("Helvetica", 12)
c.drawString(x * inch, (y + ySpc * 2) * inch, "Phone:")
c.drawString((x + xSpc) * inch, (y + ySpc * 2) * inch, phone)
c.drawString(x * inch, (y + ySpc) * inch, "Address:")
c.drawString((x + xSpc) * inch, (y + ySpc) * inch, addr1)
c.drawString((x + xSpc) * inch, y * inch, addr2)
addrIo = cStringIO.StringIO()
addrIo.write(c.getpdfdata())
return PdfFileReader(addrIo)
# Plan of attack:
# create an address pdf
# merge the address and first page
# output to a new _mod.pdf file
addrPyPdf = create_addr_in_pdf()
outPDF = PdfFileWriter()
input1 = PdfFileReader(file(file_name, "rb"))
for i in range(0,input1.getNumPages()-1):
page = input1.getPage(i)
if i == 0:
page.mergePage(addrPyPdf.getPage(0))
outPDF.addPage(page)
outputStream = file(file_name[:-4]+'_mod'+file_name[-4:], "wb")
outPDF.write(outputStream)
outputStream.close()
No comments:
Post a Comment