This repository contains the implementation of a Telegram bot that provides various functionalities for creating, merging, and manipulating PDF files directly through the Telegram interface.
- PDF Creation: Create PDFs from images or text with support for Google Fonts and embedded Times New Roman.
- PDF Merging: Merge multiple PDF files into one.
- Language Support: Choose between English, Russian, and Uzbek interfaces via inline buttons.
- User-Friendly Interface: Powered by Telegram inline keyboards and commands.
- Open Telegram and search for BotFather.
- Send the command
/newbot
to BotFather and follow the instructions:- Provide a name for your bot.
- Choose a unique username (must end with "bot").
- Once the bot is created, BotFather will provide an API token. Copy this token for later use.
- Create two Telegram chats:
- Logging Chat: For logging bot activities.
- File Storage Chat: To store PDF files.
- Add your bot to both chats.
- Use a tool like RawDataBot to get the chat IDs:
- Add RawDataBot to your chats.
- Type
/start
in each chat to receive the chat ID.
The bot uses different configurations for development and production environments.
spring:
application:
name: app-pdf-bot
profiles:
active: dev
server:
port: 80
telegram:
api-url: "https://api.telegram.org"
webhook-path: "YOUR_BOT_WEBHOOK"
bot-name: "YOUR_BOT_USERNAME"
bot-token: "YOUR_BOT_TOKEN"
chat-id:
log: CHAT_ID_FOR_LOGGING
file-store: CHAT_ID_FOR_STORING
logging:
level:
root: warn
file:
name: app-pdf-bot.log
logback:
rollingpolicy:
max-file-size: 10MB
max-history: 10
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss} - %logger{36} - %msg%n"
spring:
datasource:
url: jdbc:postgresql://localhost:5432/postgres
username: postgres
password: root1234
jpa:
hibernate:
ddl-auto: update
show-sql: true
servlet:
multipart:
max-request-size: 100MB
max-file-size: 100MB
spring:
datasource:
url: jdbc:h2:mem:mydb
username: sa
password: root1234
driver-class-name: org.h2.Driver
jpa:
hibernate:
ddl-auto: update
show-sql: true
database-platform: org.hibernate.dialect.H2Dialect
servlet:
multipart:
max-request-size: 100MB
max-file-size: 100MB
h2:
console:
enabled: true
-
Clone the repository:
git clone <repository_url> cd app-pdf-bot
-
Update the
application.yml
file:- Replace
YOUR_BOT_WEBHOOK
,YOUR_BOT_USERNAME
, andYOUR_BOT_TOKEN
with your bot's information. - Set the
CHAT_ID_FOR_LOGGING
andCHAT_ID_FOR_STORING
with the IDs obtained earlier.
- Replace
-
Build and run the bot:
./mvnw clean package java -jar target/app-pdf-bot.jar
Your bot is now ready to process commands!
The repository includes:
- Google Fonts: A collection of freely available fonts for use with the bot.
- Times New Roman: Included as the default font for users who skip font selection.
Fonts are dynamically loaded by the bot using the FontService. Users can easily add or remove fonts by managing the files in the fonts directory. This flexibility allows customization to meet specific font requirements without additional configuration.
The methods and tools described in this project may become outdated as technologies evolve. Please refer to the official documentation of the technologies used for the latest updates and configurations.
- Spring Framework
- Telegram Bot API
- Apache PDFBox
- H2 Database
- Java Telegram Bot API (telegrambots)
- Google Fonts
Logs are saved in app-pdf-bot.log
. Customize logging settings in application.yaml
under the logging
section.
Ensure you set up the logging group as described above.
Contributions are welcome! Feel free to fork the repository and submit pull requests.
This project is licensed under the MIT License.