Why PDF Editor Is Best For Us ?

In today's digital world, Portable Document Format (PDF) files are widely used for sharing documents due to their universal compatibility and fixed formatting. However, editing PDFs can be challenging without the right tools. This is where a PDF editor becomes essential. Whether for business, education, or personal use, a reliable PDF editor offers numerous advantages that make it the best choice for handling PDF files.


1. Preserves Original Formatting

Unlike other file formats, PDFs maintain their layout across different devices and operating systems. A good PDF editor allows you to modify text, images, and other elements without disrupting the original design, ensuring professional and consistent documents.

2. Enhances Productivity

Manually retyping or recreating PDF content is time-consuming. A PDF editor speeds up workflows by enabling:

Text editing – Modify existing text or add new content.

Image adjustments – Insert, resize, or replace images.

Annotations – Highlight, underline, or add comments for collaboration.

Form filling – Easily complete PDF forms electronically.

3. Secure Document Handling

PDF editors provide security features such as:

Password protection – Restrict unauthorized access.

Redaction tools – Permanently remove sensitive information.

Digital signatures – Sign documents legally without printing.

4. Supports OCR (Optical Character Recognition)

Many advanced PDF editors include OCR technology, which converts scanned documents or images into editable and searchable text. This is particularly useful for digitizing printed records.

5. Easy Conversion to Other Formats

A PDF editor allows seamless conversion between PDF and other formats like Word, Excel, or PowerPoint, making it versatile for different needs.

6. Cloud Integration & Collaboration

Modern PDF editors support cloud storage (Google Drive, Dropbox, etc.), enabling real-time collaboration. Multiple users can review, edit, and share PDFs efficiently.

7. Cost-Effective & Eco-Friendly

Editing PDFs digitally reduces the need for printing, saving paper and costs. Businesses and individuals can manage documents efficiently without physical storage.

Conclusion

A PDF editor is an indispensable tool for anyone who regularly works with digital documents. It enhances efficiency, ensures security, and simplifies document management. Whether you're a student, professional, or business owner, investing in a good PDF editor will save time and improve productivity while maintaining document integrity.

Choose the right PDF editor today and experience seamless document handling!

HTML Script # 01

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>PDFPro - Advanced PDF Editor Tool</title>

    <style>

        /* Global Styles */

        * {

            margin: 0;

            padding: 0;

            box-sizing: border-box;

            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

        }

        

        body {

            background-color: #000;

            color: #fff;

            overflow-x: hidden;

        }

        

        .container {

            max-width: 1200px;

            margin: 0 auto;

            padding: 0 20px;

        }

        

        /* Header Styles */

        header {

            background-color: rgba(0, 0, 0, 0.9);

            padding: 20px 0;

            position: fixed;

            width: 100%;

            z-index: 100;

            border-bottom: 1px solid #ff0000;

        }

        

        nav {

            display: flex;

            justify-content: space-between;

            align-items: center;

        }

        

        .logo {

            font-size: 28px;

            font-weight: bold;

            color: #ff0000;

            text-decoration: none;

        }

        

        .logo span {

            color: #fff;

        }

        

        .nav-links {

            display: flex;

            list-style: none;

        }

        

        .nav-links li {

            margin-left: 30px;

        }

        

        .nav-links a {

            color: #fff;

            text-decoration: none;

            font-weight: 500;

            transition: color 0.3s;

        }

        

        .nav-links a:hover {

            color: #ff0000;

        }

        

        /* Hero Section */

        .hero {

            height: 100vh;

            background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url('https://images.unsplash.com/photo-1547658719-da2b51169166?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80') no-repeat center center/cover;

            display: flex;

            align-items: center;

            text-align: center;

            padding-top: 80px;

        }

        

        .hero-content {

            max-width: 800px;

            margin: 0 auto;

        }

        

        .hero h1 {

            font-size: 48px;

            margin-bottom: 20px;

            color: #ff0000;

            text-transform: uppercase;

            letter-spacing: 2px;

        }

        

        .hero p {

            font-size: 20px;

            margin-bottom: 30px;

            line-height: 1.6;

        }

        

        .cta-button {

            display: inline-block;

            background-color: #ff0000;

            color: #fff;

            padding: 15px 40px;

            border-radius: 30px;

            text-decoration: none;

            font-weight: bold;

            font-size: 18px;

            transition: all 0.3s;

            border: 2px solid #ff0000;

            margin: 10px;

        }

        

        .cta-button:hover {

            background-color: transparent;

            color: #ff0000;

            transform: translateY(-3px);

            box-shadow: 0 10px 20px rgba(255, 0, 0, 0.3);

        }

        

        .secondary-button {

            display: inline-block;

            background-color: transparent;

            color: #fff;

            padding: 15px 40px;

            border-radius: 30px;

            text-decoration: none;

            font-weight: bold;

            font-size: 18px;

            transition: all 0.3s;

            border: 2px solid #fff;

            margin: 10px;

        }

        

        .secondary-button:hover {

            background-color: #fff;

            color: #000;

            transform: translateY(-3px);

        }

        

        /* Features Section */

        .features {

            padding: 100px 0;

            background-color: #111;

        }

        

        .section-title {

            text-align: center;

            margin-bottom: 60px;

        }

        

        .section-title h2 {

            font-size: 36px;

            color: #ff0000;

            margin-bottom: 15px;

        }

        

        .section-title p {

            font-size: 18px;

            color: #aaa;

            max-width: 700px;

            margin: 0 auto;

        }

        

        .features-grid {

            display: grid;

            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));

            gap: 30px;

        }

        

        .feature-card {

            background-color: #1a1a1a;

            padding: 30px;

            border-radius: 10px;

            transition: transform 0.3s;

            border-left: 4px solid #ff0000;

        }

        

        .feature-card:hover {

            transform: translateY(-10px);

        }

        

        .feature-icon {

            font-size: 40px;

            color: #ff0000;

            margin-bottom: 20px;

        }

        

        .feature-card h3 {

            font-size: 22px;

            margin-bottom: 15px;

            color: #fff;

        }

        

        .feature-card p {

            color: #aaa;

            line-height: 1.6;

        }

        

        /* How It Works Section */

        .how-it-works {

            padding: 100px 0;

            background-color: #000;

        }

        

        .steps {

            display: flex;

            justify-content: space-between;

            flex-wrap: wrap;

            margin-top: 50px;

        }

        

        .step {

            flex: 1;

            min-width: 250px;

            text-align: center;

            padding: 0 20px;

            position: relative;

            margin-bottom: 40px;

        }

        

        .step-number {

            width: 60px;

            height: 60px;

            background-color: #ff0000;

            color: #fff;

            border-radius: 50%;

            display: flex;

            align-items: center;

            justify-content: center;

            font-size: 24px;

            font-weight: bold;

            margin: 0 auto 20px;

        }

        

        .step h3 {

            font-size: 22px;

            margin-bottom: 15px;

            color: #fff;

        }

        

        .step p {

            color: #aaa;

            line-height: 1.6;

        }

        

        /* Testimonials Section */

        .testimonials {

            padding: 100px 0;

            background-color: #111;

        }

        

        .testimonial-grid {

            display: grid;

            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));

            gap: 30px;

            margin-top: 50px;

        }

        

        .testimonial-card {

            background-color: #1a1a1a;

            padding: 30px;

            border-radius: 10px;

            position: relative;

        }

        

        .testimonial-card::before {

            content: '"';

            font-size: 80px;

            color: #ff0000;

            opacity: 0.2;

            position: absolute;

            top: 10px;

            left: 20px;

        }

        

        .testimonial-content {

            margin-bottom: 20px;

            font-style: italic;

            color: #ddd;

            line-height: 1.6;

        }

        

        .testimonial-author {

            display: flex;

            align-items: center;

        }

        

        .author-img {

            width: 50px;

            height: 50px;

            border-radius: 50%;

            margin-right: 15px;

            object-fit: cover;

        }

        

        .author-info h4 {

            color: #fff;

            margin-bottom: 5px;

        }

        

        .author-info p {

            color: #aaa;

            font-size: 14px;

        }

        

        /* CTA Section */

        .cta-section {

            padding: 100px 0;

            background: linear-gradient(rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.8)), url('https://images.unsplash.com/photo-1551288049-bebda4e38f71?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80') no-repeat center center/cover;

            text-align: center;

        }

        

        .cta-section h2 {

            font-size: 36px;

            margin-bottom: 20px;

            color: #ff0000;

        }

        

        .cta-section p {

            font-size: 18px;

            margin-bottom: 30px;

            max-width: 700px;

            margin-left: auto;

            margin-right: auto;

        }

        

        /* Footer */

        footer {

            background-color: #000;

            padding: 50px 0 20px;

            border-top: 1px solid #ff0000;

        }

        

        .footer-content {

            display: grid;

            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));

            gap: 40px;

            margin-bottom: 40px;

        }

        

        .footer-column h3 {

            color: #ff0000;

            margin-bottom: 20px;

            font-size: 20px;

        }

        

        .footer-links {

            list-style: none;

        }

        

        .footer-links li {

            margin-bottom: 10px;

        }

        

        .footer-links a {

            color: #aaa;

            text-decoration: none;

            transition: color 0.3s;

        }

        

        .footer-links a:hover {

            color: #ff0000;

        }

        

        .social-links {

            display: flex;

            gap: 15px;

        }

        

        .social-links a {

            color: #fff;

            background-color: #333;

            width: 40px;

            height: 40px;

            border-radius: 50%;

            display: flex;

            align-items: center;

            justify-content: center;

            transition: all 0.3s;

        }

        

        .social-links a:hover {

            background-color: #ff0000;

            transform: translateY(-3px);

        }

        

        .copyright {

            text-align: center;

            padding-top: 20px;

            border-top: 1px solid #333;

            color: #aaa;

            font-size: 14px;

        }

        

        .disclaimer {

            background-color: #1a1a1a;

            padding: 20px;

            margin-top: 40px;

            border-radius: 5px;

            font-size: 14px;

            color: #aaa;

            line-height: 1.6;

        }

        

        .disclaimer h3 {

            color: #ff0000;

            margin-bottom: 10px;

        }

        

        /* Modal */

        .modal {

            display: none;

            position: fixed;

            z-index: 1000;

            left: 0;

            top: 0;

            width: 100%;

            height: 100%;

            background-color: rgba(0, 0, 0, 0.8);

            overflow: auto;

        }

        

        .modal-content {

            background-color: #111;

            margin: 10% auto;

            padding: 30px;

            border: 1px solid #ff0000;

            width: 80%;

            max-width: 600px;

            border-radius: 10px;

            position: relative;

            animation: modalopen 0.5s;

        }

        

        @keyframes modalopen {

            from {

                opacity: 0;

                transform: translateY(-50px);

            }

            to {

                opacity: 1;

                transform: translateY(0);

            }

        }

        

        .close-modal {

            position: absolute;

            top: 15px;

            right: 20px;

            color: #aaa;

            font-size: 28px;

            font-weight: bold;

            cursor: pointer;

            transition: color 0.3s;

        }

        

        .close-modal:hover {

            color: #ff0000;

        }

        

        .modal h2 {

            color: #ff0000;

            margin-bottom: 20px;

        }

        

        .modal p {

            margin-bottom: 20px;

            line-height: 1.6;

        }

        

        /* Responsive Styles */

        @media (max-width: 768px) {

            .nav-links {

                display: none;

            }

            

            .hero h1 {

                font-size: 36px;

            }

            

            .hero p {

                font-size: 18px;

            }

            

            .steps {

                flex-direction: column;

            }

            

            .step {

                margin-bottom: 40px;

            }

            

            .modal-content {

                width: 90%;

                margin: 20% auto;

            }

        }

    </style>

</head>

<body>

    <!-- Header -->

    <header>

        <div class="container">

            <nav>

                <a href="#" class="logo">PDF<span>Pro</span></a>

                <ul class="nav-links">

                    <li><a href="#features">Features</a></li>

                    <li><a href="#how-it-works">How It Works</a></li>

                    <li><a href="#testimonials">Testimonials</a></li>

                    <li><a href="#contact">Contact</a></li>

                </ul>

            </nav>

        </div>

    </header>


    <!-- Hero Section -->

    <section class="hero">

        <div class="container">

            <div class="hero-content">

                <h1>Edit PDFs Like Never Before</h1>

                <p>Powerful, intuitive PDF editing tools at your fingertips. Merge, split, compress, and convert PDFs with ease. No installation required.</p>

                <div class="hero-buttons">

                    <a href="#" class="cta-button" id="access-tool-btn">Access PDF Editor Now</a>

                    <a href="#features" class="secondary-button">Learn More</a>

                </div>

            </div>

        </div>

    </section>

<center>techpk</center>

    <!-- Features Section -->

    <section class="features" id="features">

        <div class="container">

            <div class="section-title">

                <h2>Powerful Features</h2>

                <p>Everything you need to work with PDFs efficiently and professionally</p>

            </div>

<center>techpk</center>

            <div class="features-grid">

                <div class="feature-card">

                    <div class="feature-icon">✏️</div>

                    <h3>Edit Text & Images</h3>

                    <p>Modify text, fonts, and images directly in your PDF files with our intuitive editor.</p>

                </div>

                <div class="feature-card">

                    <div class="feature-icon">🔀</div>

                    <h3>Merge & Split</h3>

                    <p>Combine multiple PDFs into one or split large documents into smaller files.</p>

                </div>

                <div class="feature-card">

                    <div class="feature-icon">📊</div>

                    <h3>Convert Formats</h3>

                    <p>Convert PDFs to Word, Excel, PowerPoint, JPG, and more with perfect formatting.</p>

                </div>

                <div class="feature-card">

                    <div class="feature-icon">🔒</div>

                    <h3>Password Protection</h3>

                    <p>Secure your sensitive documents with password encryption and permission controls.</p>

                </div>

                <div class="feature-card">

                    <div class="feature-icon">📝</div>

                    <h3>E-Signatures</h3>

                    <p>Sign documents electronically and request signatures from others.</p>

                </div>

                <div class="feature-card">

                    <div class="feature-icon">💾</div>

                    <h3>Cloud Integration</h3>

                    <p>Connect to Google Drive, Dropbox, and OneDrive for seamless file management.</p>

                </div>

            </div>

        </div>

    </section>


    <!-- How It Works Section -->

    <section class="how-it-works" id="how-it-works">

<center>techpk</center>

        <div class="container">

            <div class="section-title">

                <h2>How It Works</h2>

                <p>Get started in just three simple steps</p>

            </div>

            <div class="steps">

                <div class="step">

                    <div class="step-number">1</div>

                    <h3>Upload Your PDF</h3>

                    <p>Drag and drop your PDF file into our editor or select from your device or cloud storage.</p>

                </div>

                <div class="step">

                    <div class="step-number">2</div>

                    <h3>Edit & Customize</h3>

                    <p>Use our powerful tools to modify text, images, pages, and more to suit your needs.</p>

                </div>

                <div class="step">

                    <div class="step-number">3</div>

                    <h3>Download & Share</h3>

                    <p>Save your edited PDF to your device or share it directly via email or cloud services.</p>

                </div>

            </div>

        </div>

    </section>


    <!-- Testimonials Section -->

    <section class="testimonials" id="testimonials">

<center>techpk</center>

        <div class="container">

            <div class="section-title">

                <h2>What Our Users Say</h2>

                <p>Trusted by professionals and businesses worldwide</p>

            </div>

            <div class="testimonial-grid">

                <div class="testimonial-card">

                    <div class="testimonial-content">

                        <p>PDFPro has completely transformed how we handle documents in our law firm. The editing capabilities are exceptional and save us hours every week.</p>

                    </div>

                    <div class="testimonial-author">

                        <img src="https://randomuser.me/api/portraits/women/45.jpg" alt="Sarah Johnson" class="author-img">

                        <div class="author-info">

                            <h4>Sarah Johnson</h4>

                            <p>Senior Partner, Johnson & Associates</p>

                        </div>

                    </div>

                </div>

                <div class="testimonial-card">

                    <div class="testimonial-content">

                        <p>As a freelance designer, I need to edit PDFs regularly. PDFPro is by far the most intuitive and powerful tool I've used, and it's web-based!</p>

                    </div>

                    <div class="testimonial-author">

                        <img src="https://randomuser.me/api/portraits/men/32.jpg" alt="Michael Chen" class="author-img">

                        <div class="author-info">

                            <h4>Michael Chen</h4>

                            <p>Graphic Designer</p>

                        </div>

                    </div>

                </div>

                <div class="testimonial-card">

                    <div class="testimonial-content">

                        <p>Our university department switched to PDFPro last semester, and the feedback from both faculty and students has been overwhelmingly positive.</p>

                    </div>

                    <div class="testimonial-author">

                        <img src="https://randomuser.me/api/portraits/women/68.jpg" alt="Dr. Emily Rodriguez" class="author-img">

                        <div class="author-info">

                            <h4>Dr. Emily Rodriguez</h4>

                            <p>Department Head, Stanford University</p>

                        </div>

                    </div>

                </div>

            </div>

        </div>

    </section>


    <!-- CTA Section -->

    <section class="cta-section">

        <div class="container">

            <h2>Ready to Transform Your PDF Workflow?</h2>

            <p>Join thousands of professionals who trust PDFPro for all their document editing needs. No credit card required.</p>

            <a href="#" class="cta-button" id="final-cta-btn">Start Editing Now</a>

        </div>

    </section>


    <!-- Footer -->

    <footer id="contact">

        <div class="container">

            <div class="footer-content">

                <div class="footer-column">

                    <h3>PDFPro</h3>

                    <p>The most advanced online PDF editor with all the tools you need to work with PDFs efficiently.</p>

                    <div class="social-links">

                        <a href="https://www.youtube.com/@techpk1249"><i>f</i></a>

                        <a href="https://www.youtube.com/@techpk1249"><i>t</i></a>

                        <a href="https://www.youtube.com/@techpk1249"><i>in</i></a>

                        <a href="https://www.youtube.com/@techpk1249"><i>ig</i></a>

                    </div>

                </div>

                <div class="footer-column">

                    <h3>Features</h3>

                    <ul class="footer-links">

                        <li><a href="https://www.youtube.com/@techpk1249">PDF Editor</a></li>

                        <li><a href="https://www.youtube.com/@techpk1249">PDF Converter</a></li>

                        <li><a href="https://www.youtube.com/@techpk1249">PDF Compressor</a></li>

                        <li><a href="https://www.youtube.com/@techpk1249">PDF Merger</a></li>

                        <li><a href="https://www.youtube.com/@techpk1249">E-Signatures</a></li>

                    </ul>

                </div>

                <div class="footer-column">

                    <h3>Company</h3>

                    <ul class="footer-links">

                        <li><a href="https://www.youtube.com/@techpk1249">About Us</a></li>

                        <li><a href="https://www.youtube.com/@techpk1249">Careers</a></li>

                        <li><a href="https://www.youtube.com/@techpk1249">Blog</a></li>

                        <li><a href="https://www.youtube.com/@techpk1249">Press</a></li>

                        <li><a href="https://www.youtube.com/@techpk1249">Partners</a></li>

                    </ul>

                </div>

                <div class="footer-column">

                    <h3>Support</h3>

                    <ul class="footer-links">

                        <li><a href="https://www.youtube.com/@techpk1249">Help Center</a></li>

                        <li><a href="https://www.youtube.com/@techpk1249">Contact Us</a></li>

                        <li><a href="https://www.youtube.com/@techpk1249">Privacy Policy</a></li>

                        <li><a href="https://www.youtube.com/@techpk1249">Terms of Service</a></li>

                        <li><a href="https://www.youtube.com/@techpk1249">Cookies</a></li>

                    </ul>

                </div>

            </div>

            

            <div class="disclaimer">

                <h3>Disclaimer</h3>

                <p>PDFPro is an online tool for editing PDF documents. We take your privacy seriously - all file processing happens in your browser, and we don't store your documents on our servers after your session ends. For sensitive documents, we recommend using our password protection features.</p>

            </div>

            

            <div class="copyright">

                <p>&copy; 2023 PDFPro. All rights reserved.</p>

            </div>

        </div>

    </footer>


    <!-- Access Tool Modal -->

    <div class="modal" id="access-modal">

        <div class="modal-content">

            <span class="close-modal">&times;</span>

            <h2>Access PDF Editor Tool</h2>

            <p>You're about to access our powerful PDF Editor Tool. Please note that all file processing happens securely in your browser, and we don't store your documents permanently on our servers.</p>

            <p>For optimal performance, we recommend using the latest version of Chrome, Firefox, or Edge.</p>

            <div style="text-align: center; margin-top: 30px;">

                <a href="2nd.html" class="cta-button">Continue to PDF Editor</a>

            </div>

        </div>

    </div>


    <script>

        // Modal functionality

        const modal = document.getElementById('access-modal');

        const accessBtn1 = document.getElementById('access-tool-btn');

        const accessBtn2 = document.getElementById('final-cta-btn');

        const closeModal = document.querySelector('.close-modal');

        

        // Open modal when either button is clicked

        [accessBtn1, accessBtn2].forEach(btn => {

            btn.addEventListener('click', (e) => {

                e.preventDefault();

                modal.style.display = 'block';

                document.body.style.overflow = 'hidden'; // Prevent scrolling

            });

        });

        

        // Close modal when X is clicked

        closeModal.addEventListener('click', () => {

            modal.style.display = 'none';

            document.body.style.overflow = 'auto'; // Re-enable scrolling

        });

        

        // Close modal when clicking outside content

        window.addEventListener('click', (e) => {

            if (e.target === modal) {

                modal.style.display = 'none';

                document.body.style.overflow = 'auto';

            }

        });

        

        // Smooth scrolling for navigation links

        document.querySelectorAll('a[href^="#"]').forEach(anchor => {

            anchor.addEventListener('click', function(e) {

                if (this.getAttribute('href') !== '#') {

                    e.preventDefault();

                    const target = document.querySelector(this.getAttribute('href'));

                    if (target) {

                        window.scrollTo({

                            top: target.offsetTop - 80,

                            behavior: 'smooth'

                        });

                    }

                }

            });

        });

        

        // Header scroll effect

        window.addEventListener('scroll', () => {

            const header = document.querySelector('header');

            if (window.scrollY > 50) {

                header.style.backgroundColor = 'rgba(0, 0, 0, 0.95)';

                header.style.boxShadow = '0 5px 20px rgba(255, 0, 0, 0.1)';

            } else {

                header.style.backgroundColor = 'rgba(0, 0, 0, 0.9)';

                header.style.boxShadow = 'none';

            }

        });

    </script>

</body>

</html>

HTML Script # 02


<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Advanced PDF Editor</title>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">

    <style>

        :root {

            --primary-color: #e63946;

            --dark-bg: #1a1a1a;

            --light-bg: #2d2d2d;

            --text-light: #ffffff;

            --text-gray: #cccccc;

        }

        

        body {

            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

            margin: 0;

            padding: 0;

            background: var(--dark-bg);

            color: var(--text-light);

            height: 100vh;

            overflow: hidden;

        }

        

        .container {

            display: flex;

            flex-direction: column;

            height: 100vh;

        }

        

        header {

            background: var(--primary-color);

            color: white;

            padding: 12px 20px;

            display: flex;

            justify-content: space-between;

            align-items: center;

            box-shadow: 0 2px 10px rgba(0,0,0,0.3);

        }

        

        .logo {

            font-size: 1.5rem;

            font-weight: bold;

            display: flex;

            align-items: center;

            gap: 10px;

        }

        

        .file-actions {

            display: flex;

            gap: 10px;

        }

        

        button {

            padding: 8px 15px;

            border: none;

            border-radius: 4px;

            cursor: pointer;

            font-weight: 500;

            display: flex;

            align-items: center;

            gap: 8px;

            transition: all 0.2s;

        }

        

        .primary-btn {

            background: white;

            color: var(--primary-color);

        }

        

        .secondary-btn {

            background: rgba(255,255,255,0.1);

            color: white;

        }

        

        button:hover {

            transform: translateY(-2px);

        }

        

        .toolbars {

            display: flex;

            background: var(--light-bg);

            padding: 8px 15px;

            gap: 15px;

            border-bottom: 1px solid rgba(255,255,255,0.1);

        }

        

        .tool-group {

            display: flex;

            gap: 5px;

            align-items: center;

            padding-right: 15px;

            border-right: 1px solid rgba(255,255,255,0.1);

        }

        

        .tool-group:last-child {

            border-right: none;

        }

        

        .tool-btn {

            padding: 5px 10px;

            min-width: 30px;

            background: transparent;

            color: var(--text-gray);

            border-radius: 3px;

        }

        

        .tool-btn.active {

            background: rgba(230,57,70,0.3);

            color: white;

        }

        

        .tool-btn:hover {

            background: rgba(255,255,255,0.1);

        }

        

        .main {

            display: flex;

            flex: 1;

            overflow: hidden;

        }

        

        .sidebar {

            width: 250px;

            background: var(--light-bg);

            padding: 15px;

            overflow-y: auto;

            border-right: 1px solid rgba(255,255,255,0.1);

        }

        

        .pdf-viewer-container {

            flex: 1;

            overflow: auto;

            background: #525252;

            display: flex;

            justify-content: center;

            align-items: flex-start;

            position: relative;

        }

        

        #pdf-canvas {

            margin: 20px 0;

            box-shadow: 0 0 20px rgba(0,0,0,0.5);

        }

        

        #text-layer {

            position: absolute;

            top: 0;

            left: 0;

            width: 100%;

            height: 100%;

            pointer-events: none;

        }

        

        .text-annotation {

            position: absolute;

            border: 1px dashed rgba(230,57,70,0.5);

            background: rgba(230,57,70,0.1);

            pointer-events: auto;

            min-width: 100px;

            min-height: 30px;

        }

        

        .text-annotation.active {

            border: 2px solid var(--primary-color);

            background: rgba(230,57,70,0.2);

        }

        

        .text-annotation-content {

            width: 100%;

            height: 100%;

            padding: 8px;

            background: transparent;

            border: none;

            resize: none;

            font-family: inherit;

            color: #000;

            outline: none;

        }

        

        .text-annotation-toolbar {

            position: absolute;

            bottom: 100%;

            left: 0;

            background: var(--light-bg);

            padding: 5px;

            border-radius: 4px 4px 0 0;

            display: flex;

            gap: 5px;

            opacity: 0;

            transition: opacity 0.2s;

        }

        

        .text-annotation:hover .text-annotation-toolbar {

            opacity: 1;

        }

        

        .resize-handle {

            position: absolute;

            width: 10px;

            height: 10px;

            background: var(--primary-color);

            right: 0;

            bottom: 0;

            cursor: nwse-resize;

        }

        

        .sidebar-section {

            margin-bottom: 20px;

        }

        

        .sidebar-section h3 {

            font-size: 1rem;

            margin-bottom: 10px;

            color: var(--primary-color);

            display: flex;

            align-items: center;

            gap: 8px;

        }

        

        .annotations-list {

            display: flex;

            flex-direction: column;

            gap: 8px;

        }

        

        .annotation-item {

            background: rgba(255,255,255,0.05);

            padding: 8px;

            border-radius: 4px;

            cursor: pointer;

            font-size: 0.9rem;

        }

        

        .annotation-item:hover {

            background: rgba(230,57,70,0.2);

        }

        

        .modal {

            position: fixed;

            top: 0;

            left: 0;

            width: 100%;

            height: 100%;

            background: rgba(0,0,0,0.7);

            display: flex;

            justify-content: center;

            align-items: center;

            z-index: 1000;

            opacity: 0;

            pointer-events: none;

            transition: opacity 0.3s;

        }

        

        .modal.active {

            opacity: 1;

            pointer-events: all;

        }

        

        .modal-content {

            background: var(--light-bg);

            padding: 20px;

            border-radius: 8px;

            width: 400px;

            max-width: 90%;

        }

        

        .modal-title {

            font-size: 1.2rem;

            margin-bottom: 15px;

            color: var(--primary-color);

        }

        

        .form-group {

            margin-bottom: 15px;

        }

        

        .form-group label {

            display: block;

            margin-bottom: 5px;

            font-size: 0.9rem;

        }

        

        .form-group input, .form-group select {

            width: 100%;

            padding: 8px;

            border-radius: 4px;

            border: 1px solid rgba(255,255,255,0.1);

            background: rgba(0,0,0,0.3);

            color: white;

        }

        

        .modal-actions {

            display: flex;

            justify-content: flex-end;

            gap: 10px;

            margin-top: 20px;

        }

        

        .page-info {

            display: flex;

            align-items: center;

            gap: 10px;

            margin-left: auto;

        }

        

        .page-input {

            width: 50px;

            padding: 5px;

            text-align: center;

            background: rgba(0,0,0,0.3);

            border: 1px solid rgba(255,255,255,0.1);

            color: white;

            border-radius: 4px;

        }

    </style>

</head>

<body>

    <div class="container">

        <header>

            <div class="logo">

                <i class="fas fa-file-pdf"></i>

                <span>Advanced PDF Editor</span>

            </div>

            <div class="file-actions">

                <button class="primary-btn" id="open-pdf">

                    <i class="fas fa-folder-open"></i> Open PDF

                </button>

                <input type="file" id="pdf-upload" accept=".pdf" style="display: none;">

                <button class="secondary-btn" id="save-pdf">

                    <i class="fas fa-save"></i> Save

                </button>

            </div>

        </header>

       

        <div class="toolbars">

            <div class="tool-group">

                <button class="tool-btn active" id="select-tool" title="Select Tool">

                    <i class="fas fa-mouse-pointer"></i>

                </button>

                <button class="tool-btn" id="text-tool" title="Text Tool">

                    <i class="fas fa-font"></i>

                </button>

                <button class="tool-btn" id="draw-tool" title="Draw Tool">

                    <i class="fas fa-pen"></i>

                </button>

            </div>

            

            <div class="tool-group" id="text-format-tools" style="display: none;">

                <button class="tool-btn" id="bold-btn" title="Bold">

                    <i class="fas fa-bold"></i>

                </button>

                <button class="tool-btn" id="italic-btn" title="Italic">

                    <i class="fas fa-italic"></i>

                </button>

                <button class="tool-btn" id="underline-btn" title="Underline">

                    <i class="fas fa-underline"></i>

                </button>

                

                <select id="font-size" title="Font Size">

                    <option value="8">8pt</option>

                    <option value="10">10pt</option>

                    <option value="12" selected>12pt</option>

                    <option value="14">14pt</option>

                    <option value="18">18pt</option>

                    <option value="24">24pt</option>

                    <option value="36">36pt</option>

                </select>

                

                <button class="tool-btn" id="link-btn" title="Add Link">

                    <i class="fas fa-link"></i>

                </button>

            </div>

            

            <div class="tool-group">

                <button class="tool-btn" id="highlight-tool" title="Highlight">

                    <i class="fas fa-highlighter"></i>

                </button>

                <button class="tool-btn" id="shape-tool" title="Shapes">

                    <i class="fas fa-shapes"></i>

                </button>

                <button class="tool-btn" id="comment-tool" title="Comments">

                    <i class="fas fa-comment"></i>

                </button>

            </div>

            

            <div class="page-info">

                <button class="tool-btn" id="prev-page" title="Previous Page">

                    <i class="fas fa-chevron-left"></i>

                </button>

                <span>Page <input type="number" id="current-page" class="page-input" min="1" value="1"> of <span id="total-pages">1</span></span>

                <button class="tool-btn" id="next-page" title="Next Page">

                    <i class="fas fa-chevron-right"></i>

                </button>

                <button class="tool-btn" id="zoom-out" title="Zoom Out">

                    <i class="fas fa-search-minus"></i>

                </button>

                <span id="zoom-level">100%</span>

                <button class="tool-btn" id="zoom-in" title="Zoom In">

                    <i class="fas fa-search-plus"></i>

                </button>

            </div>

        </div>

        

        <div class="main">

            <div class="sidebar">

                <div class="sidebar-section">

                    <h3><i class="fas fa-layer-group"></i> Layers</h3>

                    <div class="annotations-list" id="annotations-list">

                        <div class="annotation-item">No annotations yet</div>

                    </div>

                </div>

                

                <div class="sidebar-section">

                    <h3><i class="fas fa-palette"></i> Properties</h3>

                    <div class="form-group">

                        <label>Text Color</label>

                        <input type="color" id="text-color" value="#000000">

                    </div>

                    <div class="form-group">

                        <label>Highlight Color</label>

                        <input type="color" id="highlight-color" value="#ffff00">

                    </div>

                </div>

            </div>

            

            <div class="pdf-viewer-container">

                <canvas id="pdf-canvas"></canvas>

                <div id="text-layer"></div>

            </div>

        </div>

    </div>

    

    <!-- Add Link Modal -->

    <div class="modal" id="link-modal">

        <div class="modal-content">

            <div class="modal-title">Add Hyperlink</div>

            <div class="form-group">

                <label>Link URL</label>

                <input type="text" id="link-url" placeholder="https://example.com">

            </div>

            <div class="form-group">

                <label>Link Text</label>

                <input type="text" id="link-text" placeholder="Click here">

            </div>

            <div class="modal-actions">

                <button class="secondary-btn" id="cancel-link">Cancel</button>

                <button class="primary-btn" id="apply-link">Apply</button>

            </div>

        </div>

    </div>


    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.min.js"></script>

    <script>

        // Initialize PDF.js

        pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.worker.min.js';


        // DOM elements

        const pdfUpload = document.getElementById('pdf-upload');

        const openPdfBtn = document.getElementById('open-pdf');

        const savePdfBtn = document.getElementById('save-pdf');

        const pdfCanvas = document.getElementById('pdf-canvas');

        const textLayer = document.getElementById('text-layer');

        const annotationsList = document.getElementById('annotations-list');

        const currentPageInput = document.getElementById('current-page');

        const totalPagesSpan = document.getElementById('total-pages');

        const zoomLevelSpan = document.getElementById('zoom-level');

        

        // Tool buttons

        const selectToolBtn = document.getElementById('select-tool');

        const textToolBtn = document.getElementById('text-tool');

        const drawToolBtn = document.getElementById('draw-tool');

        const highlightToolBtn = document.getElementById('highlight-tool');

        const shapeToolBtn = document.getElementById('shape-tool');

        const commentToolBtn = document.getElementById('comment-tool');

        

        // Text formatting tools

        const textFormatTools = document.getElementById('text-format-tools');

        const boldBtn = document.getElementById('bold-btn');

        const italicBtn = document.getElementById('italic-btn');

        const underlineBtn = document.getElementById('underline-btn');

        const fontSizeSelect = document.getElementById('font-size');

        const linkBtn = document.getElementById('link-btn');

        const textColorInput = document.getElementById('text-color');

        const highlightColorInput = document.getElementById('highlight-color');

        

        // Navigation buttons

        const prevPageBtn = document.getElementById('prev-page');

        const nextPageBtn = document.getElementById('next-page');

        const zoomInBtn = document.getElementById('zoom-in');

        const zoomOutBtn = document.getElementById('zoom-out');

        

        // Link modal elements

        const linkModal = document.getElementById('link-modal');

        const linkUrlInput = document.getElementById('link-url');

        const linkTextInput = document.getElementById('link-text');

        const cancelLinkBtn = document.getElementById('cancel-link');

        const applyLinkBtn = document.getElementById('apply-link');

        

        // PDF variables

        let pdfDoc = null;

        let currentPageNum = 1;

        let currentScale = 1.0;

        let currentTool = 'select';

        let activeAnnotation = null;

        let annotations = [];

        let canvasOffset = { top: 0, left: 0 };

        

        // Text formatting state

        let currentFormatting = {

            bold: false,

            italic: false,

            underline: false,

            fontSize: '12',

            textColor: '#000000',

            highlightColor: '#ffff00'

        };

        

        // Initialize event listeners

        function initEventListeners() {

            // File actions

            openPdfBtn.addEventListener('click', () => pdfUpload.click());

            pdfUpload.addEventListener('change', openPDF);

            savePdfBtn.addEventListener('click', savePDF);

            

            // Tool selection

            selectToolBtn.addEventListener('click', () => setTool('select'));

            textToolBtn.addEventListener('click', () => setTool('text'));

            drawToolBtn.addEventListener('click', () => setTool('draw'));

            highlightToolBtn.addEventListener('click', () => setTool('highlight'));

            shapeToolBtn.addEventListener('click', () => setTool('shape'));

            commentToolBtn.addEventListener('click', () => setTool('comment'));

            

            // Text formatting

            boldBtn.addEventListener('click', toggleBold);

            italicBtn.addEventListener('click', toggleItalic);

            underlineBtn.addEventListener('click', toggleUnderline);

            fontSizeSelect.addEventListener('change', updateFontSize);

            linkBtn.addEventListener('click', showLinkModal);

            textColorInput.addEventListener('change', updateTextColor);

            highlightColorInput.addEventListener('change', updateHighlightColor);

            

            // Navigation

            prevPageBtn.addEventListener('click', prevPage);

            nextPageBtn.addEventListener('click', nextPage);

            currentPageInput.addEventListener('change', goToPage);

            zoomInBtn.addEventListener('click', zoomIn);

            zoomOutBtn.addEventListener('click', zoomOut);

            

            // Link modal

            cancelLinkBtn.addEventListener('click', hideLinkModal);

            applyLinkBtn.addEventListener('click', applyLink);

            

            // Canvas click handler

            pdfCanvas.addEventListener('click', handleCanvasClick);

        }

        

        // Set current tool

        function setTool(tool) {

            currentTool = tool;

            

            // Update active tool button

            [selectToolBtn, textToolBtn, drawToolBtn, highlightToolBtn, shapeToolBtn, commentToolBtn].forEach(btn => {

                btn.classList.remove('active');

            });

            document.getElementById(`${tool}-tool`).classList.add('active');

            

            // Show/hide text formatting tools

            textFormatTools.style.display = tool === 'text' ? 'flex' : 'none';

            

            // Update status

            updateStatus(`Tool set to ${tool}`);

        }

        

        // Handle canvas click

        function handleCanvasClick(e) {

            if (currentTool === 'text') {

                addTextAnnotation(e);

            }

            // (Implement other tools here)

        }

        

        // Add text annotation

        function addTextAnnotation(e) {

            const rect = pdfCanvas.getBoundingClientRect();

            const x = e.clientX - rect.left;

            const y = e.clientY - rect.top;

            

            const textAnno = document.createElement('div');

            textAnno.className = 'text-annotation';

            textAnno.style.left = `${x}px`;

            textAnno.style.top = `${y}px`;

            

            // Create toolbar

            const toolbar = document.createElement('div');

            toolbar.className = 'text-annotation-toolbar';

            toolbar.innerHTML = `

                <button class="tool-btn" data-action="bold"><i class="fas fa-bold"></i></button>

                <button class="tool-btn" data-action="italic"><i class="fas fa-italic"></i></button>

                <button class="tool-btn" data-action="underline"><i class="fas fa-underline"></i></button>

                <button class="tool-btn" data-action="delete"><i class="fas fa-trash"></i></button>

            `;

            textAnno.appendChild(toolbar);

            

            // Create content editable div

            const content = document.createElement('div');

            content.className = 'text-annotation-content';

            content.contentEditable = true;

            content.style.fontSize = `${currentFormatting.fontSize}px`;

            content.style.color = currentFormatting.textColor;

            content.style.backgroundColor = currentFormatting.highlightColor;

            content.textContent = 'Type here...';

            

            textAnno.appendChild(content);

            

            // Add resize handle

            const resizeHandle = document.createElement('div');

            resizeHandle.className = 'resize-handle';

            textAnno.appendChild(resizeHandle);

            

            textLayer.appendChild(textAnno);

            

            // Focus the content

            content.focus();

            

            // Save annotation

            const annotation = {

                id: Date.now(),

                type: 'text',

                page: currentPageNum,

                x: x,

                y: y,

                width: 200,

                height: 100,

                content: '',

                formatting: {...currentFormatting}

            };

            

            annotations.push(annotation);

            updateAnnotationsList();

            

            // Make draggable

            makeDraggable(textAnno, annotation);

            

            // Make resizable

            makeResizable(textAnno, annotation);

            

            // Set active annotation

            setActiveAnnotation(textAnno, annotation);

            

            // Track changes

            content.addEventListener('input', () => {

                annotation.content = content.innerHTML;

            });

            

            // Handle toolbar actions

            toolbar.querySelectorAll('button').forEach(btn => {

                btn.addEventListener('click', (e) => {

                    e.stopPropagation();

                    const action = btn.getAttribute('data-action');

                    

                    if (action === 'delete') {

                        deleteAnnotation(annotation.id);

                        textAnno.remove();

                    } else if (action === 'bold') {

                        toggleBold();

                        applyFormatting(content, 'bold');

                    } else if (action === 'italic') {

                        toggleItalic();

                        applyFormatting(content, 'italic');

                    } else if (action === 'underline') {

                        toggleUnderline();

                        applyFormatting(content, 'underline');

                    }

                });

            });

            

            // Click handler to set active annotation

            textAnno.addEventListener('click', (e) => {

                e.stopPropagation();

                setActiveAnnotation(textAnno, annotation);

            });

            

            return textAnno;

        }

        

        // Make element draggable

        function makeDraggable(element, annotation) {

            let isDragging = false;

            let startX, startY;

            

            element.addEventListener('mousedown', (e) => {

                if (currentTool !== 'select') return;

                

                isDragging = true;

                startX = e.clientX - element.offsetLeft;

                startY = e.clientY - element.offsetTop;

                

                setActiveAnnotation(element, annotation);

                

                e.preventDefault();

            });

            

            document.addEventListener('mousemove', (e) => {

                if (!isDragging) return;

                

                const newLeft = e.clientX - startX;

                const newTop = e.clientY - startY;

                

                // Boundary checks

                if (newTop >= 0 && newTop + element.offsetHeight <= pdfCanvas.height) {

                    element.style.top = `${newTop}px`;

                    annotation.y = newTop;

                }

                

                if (newLeft >= 0 && newLeft + element.offsetWidth <= pdfCanvas.width) {

                    element.style.left = `${newLeft}px`;

                    annotation.x = newLeft;

                }

            });

            

            document.addEventListener('mouseup', () => {

                isDragging = false;

            });

        }

        

        // Make element resizable

        function makeResizable(element, annotation) {

            const resizeHandle = element.querySelector('.resize-handle');

            

            resizeHandle.addEventListener('mousedown', (e) => {

                e.stopPropagation();

                

                const startWidth = element.offsetWidth;

                const startHeight = element.offsetHeight;

                const startX = e.clientX;

                const startY = e.clientY;

                

                function doResize(e) {

                    const newWidth = startWidth + (e.clientX - startX);

                    const newHeight = startHeight + (e.clientY - startY);

                    

                    // Minimum size

                    if (newWidth > 50) {

                        element.style.width = `${newWidth}px`;

                        annotation.width = newWidth;

                    }

                    

                    if (newHeight > 30) {

                        element.style.height = `${newHeight}px`;

                        annotation.height = newHeight;

                    }

                }

                

                function stopResize() {

                    document.removeEventListener('mousemove', doResize);

                    document.removeEventListener('mouseup', stopResize);

                }

                

                document.addEventListener('mousemove', doResize);

                document.addEventListener('mouseup', stopResize);

                

                e.preventDefault();

            });

        }

        

        // Set active annotation

        function setActiveAnnotation(element, annotation) {

            // Remove active class from all annotations

            document.querySelectorAll('.text-annotation').forEach(el => {

                el.classList.remove('active');

            });

            

            if (element) {

                element.classList.add('active');

                activeAnnotation = annotation;

                

                // Update formatting tools to match active annotation

                if (annotation && annotation.formatting) {

                    currentFormatting = {...annotation.formatting};

                    updateFormattingUI();

                }

            } else {

                activeAnnotation = null;

            }

        }

        

        // Delete annotation

        function deleteAnnotation(id) {

            annotations = annotations.filter(anno => anno.id !== id);

            updateAnnotationsList();

        }

        

        // Update annotations list

        function updateAnnotationsList() {

            annotationsList.innerHTML = '';

            

            const pageAnnotations = annotations.filter(anno => anno.page === currentPageNum);

            

            if (pageAnnotations.length === 0) {

                annotationsList.innerHTML = '<div class="annotation-item">No annotations yet</div>';

                return;

            }

            

            pageAnnotations.forEach(anno => {

                const item = document.createElement('div');

                item.className = 'annotation-item';

                item.textContent = `${anno.type} annotation`;

                

                item.addEventListener('click', () => {

                    // Focus the annotation (implementation would require tracking DOM elements)

                });

                

                annotationsList.appendChild(item);

            });

        }

        

        // Text formatting functions

        function toggleBold() {

            currentFormatting.bold = !currentFormatting.bold;

            boldBtn.classList.toggle('active', currentFormatting.bold);

            applyCurrentFormatting();

        }

        

        function toggleItalic() {

            currentFormatting.italic = !currentFormatting.italic;

            italicBtn.classList.toggle('active', currentFormatting.italic);

            applyCurrentFormatting();

        }

        

        function toggleUnderline() {

            currentFormatting.underline = !currentFormatting.underline;

            underlineBtn.classList.toggle('active', currentFormatting.underline);

            applyCurrentFormatting();

        }

        

        function updateFontSize() {

            currentFormatting.fontSize = fontSizeSelect.value;

            applyCurrentFormatting();

        }

        

        function updateTextColor() {

            currentFormatting.textColor = textColorInput.value;

            applyCurrentFormatting();

        }

        

        function updateHighlightColor() {

            currentFormatting.highlightColor = highlightColorInput.value;

            applyCurrentFormatting();

        }

        

        function updateFormattingUI() {

            boldBtn.classList.toggle('active', currentFormatting.bold);

            italicBtn.classList.toggle('active', currentFormatting.italic);

            underlineBtn.classList.toggle('active', currentFormatting.underline);

            fontSizeSelect.value = currentFormatting.fontSize;

            textColorInput.value = currentFormatting.textColor;

            highlightColorInput.value = currentFormatting.highlightColor;

        }

        

        function applyCurrentFormatting() {

            if (!activeAnnotation) return;

            

            // Update annotation formatting

            activeAnnotation.formatting = {...currentFormatting};

            

            // Find the corresponding DOM element and apply formatting

            const textAnno = document.querySelector(`.text-annotation.active`);

            if (textAnno) {

                const content = textAnno.querySelector('.text-annotation-content');

                applyFormatting(content, 'all');

            }

        }

        

        function applyFormatting(element, type) {

            if (type === 'bold' || type === 'all') {

                element.style.fontWeight = currentFormatting.bold ? 'bold' : 'normal';

            }

            if (type === 'italic' || type === 'all') {

                element.style.fontStyle = currentFormatting.italic ? 'italic' : 'normal';

            }

            if (type === 'underline' || type === 'all') {

                element.style.textDecoration = currentFormatting.underline ? 'underline' : 'none';

            }

            if (type === 'all') {

                element.style.fontSize = `${currentFormatting.fontSize}px`;

                element.style.color = currentFormatting.textColor;

                element.style.backgroundColor = currentFormatting.highlightColor;

            }

        }

        

        // Link functions

        function showLinkModal() {

            linkUrlInput.value = '';

            linkTextInput.value = '';

            linkModal.classList.add('active');

        }

        

        function hideLinkModal() {

            linkModal.classList.remove('active');

        }

        

        function applyLink() {

            const url = linkUrlInput.value.trim();

            const text = linkTextInput.value.trim() || url;

            

            if (url && activeAnnotation) {

                const textAnno = document.querySelector(`.text-annotation.active`);

                if (textAnno) {

                    const content = textAnno.querySelector('.text-annotation-content');

                    const selection = window.getSelection();

                    

                    if (selection.toString()) {

                        // Wrap selected text in link

                        const range = selection.getRangeAt(0);

                        const link = document.createElement('a');

                        link.href = url;

                        link.textContent = text || selection.toString();

                        link.target = '_blank';

                        range.deleteContents();

                        range.insertNode(link);

                    } else {

                        // Insert new link

                        const link = document.createElement('a');

                        link.href = url;

                        link.textContent = text;

                        link.target = '_blank';

                        content.appendChild(link);

                    }

                    

                    // Update annotation content

                    activeAnnotation.content = content.innerHTML;

                }

            }

            

            hideLinkModal();

        }

        

        // PDF functions

        function openPDF(e) {

            const file = e.target.files[0];

            if (!file) return;

            

            updateStatus(`Loading ${file.name}...`);

            

            const fileReader = new FileReader();

            fileReader.onload = function() {

                const typedArray = new Uint8Array(this.result);

                

                pdfjsLib.getDocument(typedArray).promise.then(function(pdf) {

                    pdfDoc = pdf;

                    currentPageNum = 1;

                    currentScale = 1.0;

                    totalPagesSpan.textContent = pdf.numPages;

                    zoomLevelSpan.textContent = '100%';

                    

                    // Clear previous annotations

                    annotations = [];

                    updateAnnotationsList();

                    

                    // Render the first page

                    renderPage(currentPageNum);

                    

                    updateStatus(`Loaded: ${file.name}`);

                }).catch(function(error) {

                    updateStatus(`Error loading PDF: ${error.message}`);

                    console.error('PDF loading error:', error);

                });

            };

            fileReader.readAsArrayBuffer(file);

        }

        

        function savePDF() {

            if (!pdfDoc) {

                updateStatus("No PDF loaded to save");

                return;

            }

            

            // In a real implementation, you would:

            // 1. Collect all annotation data

            // 2. Use a library like pdf-lib to modify the PDF

            // 3. Generate a download link for the modified PDF

            

            updateStatus("PDF saved with annotations (simulated)");

            

            // Simulate saving

            const blob = new Blob([JSON.stringify(annotations)], { type: 'application/json' });

            const url = URL.createObjectURL(blob);

            const a = document.createElement('a');

            a.href = url;

            a.download = 'annotations.json';

            a.click();

            URL.revokeObjectURL(url);

        }

        

        function renderPage(num) {

            if (!pdfDoc) return;

            

            updateStatus(`Rendering page ${num}...`);

            pageRendering = true;

            

            pdfDoc.getPage(num).then(function(page) {

                const viewport = page.getViewport({ scale: currentScale });

                pdfCanvas.height = viewport.height;

                pdfCanvas.width = viewport.width;

                

                // Calculate canvas offset

                const container = document.querySelector('.pdf-viewer-container');

                const canvasRect = pdfCanvas.getBoundingClientRect();

                const containerRect = container.getBoundingClientRect();

                

                canvasOffset = {

                    top: canvasRect.top - containerRect.top + container.scrollTop,

                    left: canvasRect.left - containerRect.left + container.scrollLeft

                };

                

                // Render PDF page

                const renderContext = {

                    canvasContext: pdfCanvas.getContext('2d'),

                    viewport: viewport

                };

                

                const renderTask = page.render(renderContext);

                

                renderTask.promise.then(function() {

                    pageRendering = false;

                    currentPageInput.value = num;

                    updateStatus(`Page ${num} rendered`);

                    

                    // Load annotations for this page

                    loadAnnotations(num);

                    

                    if (pageNumPending !== null) {

                        renderPage(pageNumPending);

                        pageNumPending = null;

                    }

                });

            });

        }

        

        function loadAnnotations(pageNum) {

            // Clear existing annotations

            textLayer.innerHTML = '';

            

            // Filter annotations for current page

            const pageAnnotations = annotations.filter(anno => anno.page === pageNum);

            

            // Recreate annotations

            pageAnnotations.forEach(anno => {

                if (anno.type === 'text') {

                    const textAnno = document.createElement('div');

                    textAnno.className = 'text-annotation';

                    textAnno.style.left = `${anno.x}px`;

                    textAnno.style.top = `${anno.y}px`;

                    textAnno.style.width = `${anno.width}px`;

                    textAnno.style.height = `${anno.height}px`;

                    

                    // Create toolbar

                    const toolbar = document.createElement('div');

                    toolbar.className = 'text-annotation-toolbar';

                    toolbar.innerHTML = `

                        <button class="tool-btn" data-action="bold"><i class="fas fa-bold"></i></button>

                        <button class="tool-btn" data-action="italic"><i class="fas fa-italic"></i></button>

                        <button class="tool-btn" data-action="underline"><i class="fas fa-underline"></i></button>

                        <button class="tool-btn" data-action="delete"><i class="fas fa-trash"></i></button>

                    `;

                    textAnno.appendChild(toolbar);

                    

                    // Create content

                    const content = document.createElement('div');

                    content.className = 'text-annotation-content';

                    content.contentEditable = true;

                    content.innerHTML = anno.content || 'Type here...';

                    

                    // Apply formatting

                    if (anno.formatting) {

                        content.style.fontWeight = anno.formatting.bold ? 'bold' : 'normal';

                        content.style.fontStyle = anno.formatting.italic ? 'italic' : 'normal';

                        content.style.textDecoration = anno.formatting.underline ? 'underline' : 'none';

                        content.style.fontSize = `${anno.formatting.fontSize}px`;

                        content.style.color = anno.formatting.textColor;

                        content.style.backgroundColor = anno.formatting.highlightColor;

                    }

                    

                    textAnno.appendChild(content);

                    

                    // Add resize handle

                    const resizeHandle = document.createElement('div');

                    resizeHandle.className = 'resize-handle';

                    textAnno.appendChild(resizeHandle);

                    

                    textLayer.appendChild(textAnno);

                    

                    // Make interactive

                    makeDraggable(textAnno, anno);

                    makeResizable(textAnno, anno);

                    

                    // Click handler

                    textAnno.addEventListener('click', (e) => {

                        e.stopPropagation();

                        setActiveAnnotation(textAnno, anno);

                    });

                    

                    // Track changes

                    content.addEventListener('input', () => {

                        anno.content = content.innerHTML;

                    });

                    

                    // Handle toolbar actions

                    toolbar.querySelectorAll('button').forEach(btn => {

                        btn.addEventListener('click', (e) => {

                            e.stopPropagation();

                            const action = btn.getAttribute('data-action');

                            

                            if (action === 'delete') {

                                deleteAnnotation(anno.id);

                                textAnno.remove();

                            } else if (action === 'bold') {

                                toggleBold();

                                applyFormatting(content, 'bold');

                            } else if (action === 'italic') {

                                toggleItalic();

                                applyFormatting(content, 'italic');

                            } else if (action === 'underline') {

                                toggleUnderline();

                                applyFormatting(content, 'underline');

                            }

                        });

                    });

                }

            });

        }

        

        // Navigation functions

        function prevPage() {

            if (currentPageNum <= 1) return;

            currentPageNum--;

            queueRenderPage(currentPageNum);

        }

        

        function nextPage() {

            if (!pdfDoc || currentPageNum >= pdfDoc.numPages) return;

            currentPageNum++;

            queueRenderPage(currentPageNum);

        }

        

        function goToPage() {

            const pageNum = parseInt(currentPageInput.value);

            if (pageNum >= 1 && pageNum <= pdfDoc.numPages) {

                currentPageNum = pageNum;

                queueRenderPage(currentPageNum);

            }

        }

        

        function queueRenderPage(num) {

            if (pageRendering) {

                pageNumPending = num;

            } else {

                renderPage(num);

            }

        }

        

        // Zoom functions

        function zoomIn() {

            if (!pdfDoc) return;

            currentScale += 0.25;

            zoomLevelSpan.textContent = `${Math.round(currentScale * 100)}%`;

            queueRenderPage(currentPageNum);

        }

        

        function zoomOut() {

            if (!pdfDoc || currentScale <= 0.5) return;

            currentScale -= 0.25;

            zoomLevelSpan.textContent = `${Math.round(currentScale * 100)}%`;

            queueRenderPage(currentPageNum);

        }

        

        // Status update

        function updateStatus(message) {

            console.log(message);

            // In a real app, you might show this in a status bar

        }

        

        // Initialize the editor

        function init() {

            initEventListeners();

            setTool('select');

            updateStatus('PDF Editor ready');

        }

        

        // Start the editor when DOM is loaded

        document.addEventListener('DOMContentLoaded', init);

    </script>



</body>

</html>

No comments:

Post a Comment

If you have any question you can ask me feelfree.