NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

# Write the full newsletter PDF
import fitz
import os

doc = fitz.open('Working/Table of Contents.pdf')
toc_page_count = doc.page_count

## For each article in input data, attach articles and add TOC links
TOC = []
TOC.append([1, 'Table of Contents', 1, 36])
for _, article in df.iterrows():
pdf_name = article.PDF
pdf_type = article.Type
pdf_title = f'{article.Title} ({article.Source})'

if pdf_type == 'Top Article' and pdf_name.endswith('.pdf'):
page_count = doc.page_count
doc.insert_file('PDFs/'+pdf_name)
TOC.append([1, pdf_title, page_count+1, 36])

### create link to article
toc_rects = []
for page in doc.pages(0, toc_page_count-1):
for toc_rect in page.search_for(pdf_title):
toc_rects.append(toc_rect)
link_page = page.number
page.insert_link({
'kind': fitz.LINK_GOTO,
'page': page_count,
'from': toc_rect,
'to': fitz.Point(0, 0)
})
print(pdf_title)
print(toc_rects)
### create back to TOC links
for page in doc.pages(page_count):
page.clean_contents()
back_rect = fitz.Rect(page.rect.width-100, 30, page.rect.width-10, 60)
page.insert_textbox(back_rect, 'Back to TOC', color=(0,0,1))
page.insert_link({
'kind': fitz.LINK_GOTO,
'page': link_page,
'from': back_rect,
'to': fitz.Point(toc_rects[0][0], toc_rects[0][1]-30)
})
doc.set_toc(TOC)

## Add headers and footers
for page in doc.pages():
page.clean_contents()

### Footers
page.insert_textbox(fitz.Rect(page.rect.width-220, page.rect.height-50, page.rect.width-10, page.rect.height-30), 'For Internal Use Only - Do Not Distribute', color=(1,0,0))
page.insert_textbox(fitz.Rect(page.rect.width-145, page.rect.height-35, page.rect.width-10, page.rect.height-20), 'Powered by FRG | QuantHub | GPT3.5', fontsize=7)
page.insert_textbox(fitz.Rect(25, page.rect.height-50, 50, page.rect.height-25), str(page.number+1))

## Save PDF
pdfname = 'Working/Business Leader Consolidated News Update.pdf'
doc.ez_save(pdfname)

## Save as email template
from email.message import EmailMessage
from email.policy import SMTP

msg = EmailMessage()
msg['Subject'] = f'Business Leader Consolidated News Update ({timestamp})'

## Put TOC in email body
with open('Working/Table of Contents.html', 'r') as html:
msg.add_alternative(html.read(), subtype='html')

## Attach PDF
with open(pdfname, 'rb') as fp:
msg.add_attachment(fp.read(),
maintype='application',
subtype='pdf',
filename=f'Business Leader Consolidated News Update ({timestamp}).pdf')

## Save the message
with open('Newsletter Email Template.eml', 'wb') as fp:
fp.write(msg.as_bytes(policy=SMTP))
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.