Project Title: PDF Generator Tool
Description: A Java-based application that converts text files and images to PDF format, demonstrating core Object-Oriented Programming concepts including inheritance, polymorphism, abstraction, and encapsulation.
Key Features:
- Convert text files to properly formatted PDF documents
- Convert images to PDF with embedded image information
- Interactive console-based user interface
- Proper PDF file generation that works with standard PDF viewers
- Educational demonstration of OOP principles
Java Project/
βββ src/
β βββ com/
β βββ pdfgenerator/
β βββ PDFGenerator.java # Abstract base class
β βββ TextToPDFGenerator.java # Text to PDF converter
β βββ ImageToPDFGenerator.java # Image to PDF converter
β βββ PDFGeneratorApp.java # Main application class
βββ sample-files/
β βββ sample.txt # Sample text for testing
β βββ README_for_images.txt # Instructions for image files
βββ output/ # Generated PDF files appear here
βββ lib/ # (Reserved for future libraries)
βββ README.md # This file
βββ VIVA_PREPARATION.md # Detailed viva preparation guide
βββ COMPILE_AND_RUN.md # Step-by-step execution guide
PDFGenerator
serves as the abstract parent classTextToPDFGenerator
andImageToPDFGenerator
extend the base class- Child classes inherit common methods like
validateInputFile()
and status display methods - Demonstrates "IS-A" relationship (TextToPDFGenerator IS-A PDFGenerator)
- Same method
generatePDF()
behaves differently in each subclass PDFGenerator
reference can point to any concrete implementation- Runtime method resolution based on actual object type
- Demonstrates method overriding and dynamic binding
PDFGenerator
contains abstract methodgeneratePDF()
- Hides implementation details from user
- Provides clean interface for PDF generation
- Each subclass must implement the abstract method
- Private methods for internal PDF creation logic
- Protected fields accessible only to subclasses
- Public methods provide controlled access to functionality
- Data hiding and access control principles
- Java Development Kit (JDK) 8 or higher
- Windows Command Prompt or PowerShell
- Text editor (VS Code, Notepad++, etc.) for viewing files
cd "C:\Users\HP\Downloads\Java Project"
javac -cp . src\com\pdfgenerator\*.java -d .
What this does:
javac
: Java compiler command-cp .
: Sets classpath to current directorysrc\com\pdfgenerator\*.java
: Compile all Java files in package-d .
: Output compiled classes to current directory
java com.pdfgenerator.PDFGeneratorApp
You'll see a menu like this:
========================================
Welcome to PDF Generator Tool
========================================
ββββββββββββββββββββββββββββββββββββββββ
β MAIN MENU β
β βββββββββββββββββββββββββββββββββββββββ£
β 1. Convert Text File to PDF β
β 2. Convert Image File to PDF β
β 3. Demo with Sample Files β
β 4. View Output Directory β
β 5. Exit β
ββββββββββββββββββββββββββββββββββββββββ
Enter your choice (1-5):
- Choose option
1
- Enter path:
sample-files\sample.txt
- PDF will be generated in
output/
folder
- Add an image file (JPG/PNG) to
sample-files/
folder - Choose option
2
- Enter the image file path
- PDF with image information will be created
- Choose option
3
- Automatically processes sample files
- Shows both text and image conversion
- Choose option
4
- See list of all generated PDF files
- File sizes and names displayed
Our application generates proper PDF files with:
- PDF Header:
%PDF-1.4
(version identifier) - Binary Marker: Ensures compatibility with PDF readers
- Object Catalog: Root object defining document structure
- Pages Object: Container for all pages in document
- Page Object: Individual page with dimensions and content
- Font Object: Text rendering font (Helvetica)
- Content Stream: Actual text/image content data
- Cross-Reference Table: File navigation information
- Trailer: Document metadata and structure
- End Marker:
%%EOF
(end of file)
- Line Wrapping: Automatically wraps long lines to fit page width
- Character Escaping: Handles special PDF characters safely
- Font Formatting: Uses standard Helvetica font at 12pt
- Margin Control: 50-point margins on all sides
- Multi-line Support: Processes line breaks correctly
- Format Support: JPG, PNG, GIF, BMP image files
- Scaling Calculation: Automatically scales images to fit A4 page
- Aspect Ratio: Maintains original image proportions
- Positioning: Centers images on PDF page
- Metadata: Includes original dimensions and file information
- BufferedReader: Efficient text file reading
- FileReader: Character stream reading
- ImageIO: Image file loading and processing
- File Validation: Existence and readability checks
- FileOutputStream: Binary PDF file writing
- BufferedWriter: Efficient text output
- OutputStreamWriter: Character encoding control
- Directory Management: Automatic folder creation
- Real-World Application: Solves actual problem (file conversion)
- Industry Relevance: PDF generation is common in enterprise applications
- Scalable Design: Easy to extend with additional features
- Clean Code: Well-commented and organized for learning
- Object-oriented design principles
- File handling and I/O operations
- Exception handling and error management
- User interface design (console-based)
- Software architecture and modularity
Problem: javac
not recognized
Solution: Ensure JDK is installed and added to PATH
Problem: Class not found errors
Solution: Make sure you're in the project root directory
Problem: File not found when converting
Solution: Use absolute paths or ensure files exist in specified location
Problem: Permission denied creating output
Solution: Check write permissions on output directory
Problem: Generated PDF won't open
Solution: Try different PDF viewer (Adobe Reader, browser, etc.)
- GUI Interface: Swing or JavaFX-based user interface
- iText Integration: Professional PDF library for advanced features
- Multi-page Support: Handle documents longer than one page
- Image Embedding: True image data embedding in PDF
- Font Options: Multiple font types and sizes
- Batch Processing: Convert multiple files simultaneously
- PDF Merging: Combine multiple PDFs into one
- Encryption: Password protection for generated PDFs
- Use established libraries (iText, Apache PDFBox) for commercial use
- Add comprehensive error handling and logging
- Implement unit tests for all components
- Add configuration files for customization
- Consider memory optimization for large files
For questions about this project:
- Review the
VIVA_PREPARATION.md
file for detailed examination guidance - Check
COMPILE_AND_RUN.md
for step-by-step execution instructions - Examine source code comments for implementation details
- Test with sample files to understand functionality
This project is created for educational purposes and academic demonstration. Feel free to use, modify, and extend for learning objectives.
Created: October 2025
Language: Java 8+
Platform: Cross-platform (Windows, Mac, Linux)
Dependencies: Standard Java libraries only
Happy coding and good luck with your viva examination! π