#BY; @nowarsiv
import telebot
from fpdf import FPDF
import io
# Bot API anahtarınızı buraya ekleyin
bot = telebot.TeleBot('Token')
# PDF oluşturma işlevi
def create_pdf(text):
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
# Metni satır satır ekle
for line in text.split('\n'):
pdf.cell(200, 10, txt=line, ln=True)
# Bellek içi dosya oluştur
pdf_output = io.BytesIO()
pdf.output(pdf_output)
pdf_output.seek(0)
return pdf_output
# Komut işleyici
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Hoş geldiniz! Bana bir metin gönderin, ben de onu PDF'ye dönüştüreyim geri vereyim.")
# Metin işleyici
@bot.message_handler(func=lambda message: True)
def handle_text(message):
user_text = message.text
# PDF'yi oluştur ve kullanıcıya gönder
pdf_file = create_pdf(user_text)
bot.send_document(message.chat.id, pdf_file, reply_to_message_id=message.message_id, caption="İşte PDF'niz!")
# Botu sürekli çalıştır
bot.polling()
Metini PDF ye dönüştürme toolu14 ژوئیه 2024, 06:41

