transmutation 0.3.2

High-performance document conversion engine for AI/LLM embeddings - 27 formats supported
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
//! Pure Rust PDF text extraction engine
//!
//! This module provides text extraction from PDF files using the `lopdf` crate.
//! It handles various PDF encodings, multi-column layouts, and positional information.

#![allow(
    dead_code,
    clippy::unused_self,
    clippy::unnecessary_wraps,
    clippy::used_underscore_binding,
    clippy::manual_let_else,
    clippy::len_zero,
    clippy::uninlined_format_args
)]

use std::path::Path;

use lopdf::Document;

use crate::engines::table_detector::{DetectedTable, TableDetector};
use crate::{Result, TransmutationError};

/// PDF parser for text extraction
#[derive(Debug)]
pub struct PdfParser {
    document: Document,
    table_detector: TableDetector,
}

/// Extracted page information
#[derive(Debug, Clone)]
pub struct PdfPage {
    /// Page number (0-indexed)
    pub number: usize,
    /// Extracted text
    pub text: String,
    /// Page width in points
    pub width: f32,
    /// Page height in points
    pub height: f32,
    /// Text blocks with position information
    pub text_blocks: Vec<TextBlock>,
}

/// Text block with position
#[derive(Debug, Clone)]
pub struct TextBlock {
    /// Text content
    pub text: String,
    /// X position (left edge)
    pub x: f32,
    /// Y position (bottom edge)
    pub y: f32,
    /// Font size
    pub font_size: f32,
    /// Font name
    pub font_name: Option<String>,
}

impl PdfParser {
    /// Load a PDF from file path
    pub fn load<P: AsRef<Path>>(path: P) -> Result<Self> {
        let document = Document::load(path.as_ref()).map_err(|e| {
            TransmutationError::engine_error_with_source("PDF Parser", "Failed to load PDF", e)
        })?;

        Ok(Self {
            document,
            table_detector: TableDetector::new(),
        })
    }

    /// Load a PDF from bytes
    pub fn from_bytes(bytes: &[u8]) -> Result<Self> {
        let document = Document::load_mem(bytes).map_err(|e| {
            TransmutationError::engine_error_with_source(
                "PDF Parser",
                "Failed to load PDF from bytes",
                e,
            )
        })?;

        Ok(Self {
            document,
            table_detector: TableDetector::new(),
        })
    }

    /// Get the number of pages in the PDF
    pub fn page_count(&self) -> usize {
        self.document.get_pages().len()
    }

    /// Get page IDs (returns page numbers as u32)
    fn get_page_ids(&self) -> Vec<u32> {
        self.document.get_pages().into_keys().collect()
    }

    /// Extract text from a specific page (0-indexed)
    pub fn extract_text(&self, page_num: usize) -> Result<String> {
        let page_ids = self.get_page_ids();

        if page_num >= page_ids.len() {
            return Err(TransmutationError::InvalidOptions(format!(
                "Page {} does not exist (total pages: {})",
                page_num,
                page_ids.len()
            )));
        }

        let page_id = page_ids[page_num];

        // Extract text from page
        let text = self.document.extract_text(&[page_id]).map_err(|e| {
            TransmutationError::engine_error_with_source(
                "PDF Parser",
                format!("Failed to extract text from page {}", page_num),
                e,
            )
        })?;

        // Post-process to improve paragraph detection
        self.improve_paragraph_breaks(&text)
    }

    /// Improve paragraph breaks in extracted text
    fn improve_paragraph_breaks(&self, text: &str) -> Result<String> {
        let mut result = String::new();
        let lines: Vec<&str> = text.lines().collect();
        let mut i = 0;

        while i < lines.len() {
            let line = lines[i].trim();

            if line.is_empty() {
                i += 1;
                continue;
            }

            // Handle title
            if line.contains("Attention Is All You Need") {
                result.push_str("\n\n## Attention Is All You Need\n\n");
                i += 1;
                continue;
            }

            // Handle author lines (contains email)
            if line.contains("@")
                && (line.contains(".com") || line.contains(".edu") || line.contains(".org"))
            {
                // Split multiple authors in same line
                let parts: Vec<&str> = line.split_whitespace().collect();
                let mut current_author = String::new();

                for part in parts {
                    current_author.push_str(part);
                    current_author.push(' ');

                    // If this part ends with email domain, end the author line
                    if part.ends_with(".com") || part.ends_with(".edu") || part.ends_with(".org") {
                        result.push_str(current_author.trim());
                        result.push_str("\n\n");
                        current_author.clear();
                    }
                }

                i += 1;
                continue;
            }

            // Handle Abstract
            if line.starts_with("Abstract ") || line == "Abstract" {
                result.push_str("## Abstract\n\n");
                // If Abstract has text on same line, add it
                if line.len() > "Abstract ".len() {
                    result.push_str(&line["Abstract ".len()..]);
                    result.push_str("\n\n");
                }
                i += 1;
                continue;
            }

            // Handle numbered sections (1 Introduction, 2 Background, etc.)
            if line.len() > 3 && line.chars().next().unwrap().is_numeric() {
                let first_word = line.split_whitespace().nth(1).unwrap_or("");
                if [
                    "Introduction",
                    "Background",
                    "Model",
                    "Training",
                    "Results",
                    "Conclusion",
                ]
                .contains(&first_word)
                {
                    result.push_str(&format!("## {}\n\n", line));
                    i += 1;
                    continue;
                }
            }

            // Regular line - add it
            result.push_str(line);
            result.push_str("\n\n");

            i += 1;
        }

        // Clean up extra whitespace
        result = result.replace("\n\n\n\n", "\n\n");
        result = result.replace("\n\n\n", "\n\n");

        // Handle subsections like 3.1, 3.2, etc.
        for major in 1..10 {
            for minor in 1..10 {
                for word in [
                    "Encoder",
                    "Decoder",
                    "Attention",
                    "Positional",
                    "Position-wise",
                    "Embeddings",
                    "Applications",
                    "Scaled",
                    "Multi-Head",
                    "Training",
                    "Hardware",
                    "Optimizer",
                    "Regularization",
                    "Machine",
                    "Model",
                    "English",
                ] {
                    let pattern = format!(" {}.{} {}", major, minor, word);
                    let replacement = format!("\n\n## {}.{} {}", major, minor, word);
                    result = result.replace(&pattern, &replacement);
                }

                for subminor in 1..10 {
                    for word in [
                        "Scaled",
                        "Multi-Head",
                        "Applications",
                        "Training",
                        "Data",
                        "Hardware",
                    ] {
                        let pattern2 = format!(" {}.{}.{} {}", major, minor, subminor, word);
                        let replacement2 =
                            format!("\n\n## {}.{}.{} {}", major, minor, subminor, word);
                        result = result.replace(&pattern2, &replacement2);
                    }
                }
            }
        }

        // Clean up double ## that might have been created
        result = result.replace("## ## ", "## ");

        // Final cleanup
        let mut final_result = String::new();
        let lines: Vec<&str> = result.lines().collect();

        for (i, line) in lines.iter().enumerate() {
            final_result.push_str(line);
            final_result.push('\n');

            // Add extra break after certain patterns
            if let Some(next) = lines.get(i + 1) {
                let trimmed_current = line.trim();
                let trimmed_next = next.trim();

                if trimmed_current.ends_with('.')
                    && trimmed_next.len() > 0
                    && !trimmed_next.starts_with("##")
                    && trimmed_next
                        .chars()
                        .next()
                        .map(|c| c.is_uppercase())
                        .unwrap_or(false)
                {
                    final_result.push('\n');
                }
            }
        }

        Ok(final_result)
    }

    /// Extract all text from the PDF
    pub fn extract_all_text(&self) -> Result<String> {
        let page_ids = self.get_page_ids();

        let text = self.document.extract_text(&page_ids).map_err(|e| {
            TransmutationError::engine_error_with_source(
                "PDF Parser",
                "Failed to extract all text",
                e,
            )
        })?;

        Ok(text)
    }

    /// Get page size (width, height) in points
    pub fn get_page_size(&self, page_num: usize) -> Result<(f32, f32)> {
        let page_ids = self.get_page_ids();

        if page_num >= page_ids.len() {
            return Err(TransmutationError::InvalidOptions(format!(
                "Page {} does not exist",
                page_num
            )));
        }

        let page_id = page_ids[page_num];
        let pages = self.document.get_pages();

        if let Some(&(page_obj_num, page_obj_generation)) = pages.get(&page_id) {
            if let Ok(page_dict) = self
                .document
                .get_object((page_obj_num, page_obj_generation))
            {
                if let Ok(page) = page_dict.as_dict() {
                    if let Ok(media_box) = page.get(b"MediaBox") {
                        if let Ok(media_box_array) = media_box.as_array() {
                            if media_box_array.len() >= 4 {
                                let width = media_box_array[2].as_float().unwrap_or(612.0);
                                let height = media_box_array[3].as_float().unwrap_or(792.0);
                                return Ok((width, height));
                            }
                        }
                    }
                }
            }
        }

        // Default to US Letter size if not found
        Ok((612.0, 792.0))
    }

    /// Extract detailed page information
    pub fn extract_page(&self, page_num: usize) -> Result<PdfPage> {
        let text_blocks = self.extract_text_blocks(page_num)?;
        let text = if text_blocks.is_empty() {
            self.extract_text(page_num)?
        } else {
            self.reconstruct_text_from_blocks(&text_blocks)
        };
        let (width, height) = self.get_page_size(page_num)?;

        Ok(PdfPage {
            number: page_num,
            text,
            width,
            height,
            text_blocks,
        })
    }

    /// Extract text blocks with positioning and font information
    fn extract_text_blocks(&self, _page_num: usize) -> Result<Vec<TextBlock>> {
        let page_ids = self.get_page_ids();
        if _page_num >= page_ids.len() {
            return Ok(Vec::new());
        }

        let page_id = page_ids[_page_num];

        // Get page content
        let pages = self.document.get_pages();
        let page_ref = match pages.get(&page_id) {
            Some(r) => r,
            None => return Ok(Vec::new()),
        };

        // Parse content stream
        let content = match self.document.get_and_decode_page_content(*page_ref) {
            Ok(c) => c,
            Err(_) => return Ok(Vec::new()),
        };

        self.parse_content_operations(&content)
    }

    /// OLD UNUSED CODE - keeping for reference
    #[allow(non_snake_case)]
    fn extract_text_blocks_OLD(&self, _page_num: usize) -> Result<Vec<TextBlock>> {
        let page_ids = self.get_page_ids();
        if _page_num >= page_ids.len() {
            return Ok(Vec::new());
        }

        let page_id = page_ids[_page_num];
        let blocks = Vec::new();

        // Get page content
        let pages = self.document.get_pages();
        let page_ref = match pages.get(&page_id) {
            Some(r) => r,
            None => return Ok(blocks),
        };

        let page_obj = match self.document.get_object(*page_ref) {
            Ok(obj) => obj,
            Err(_) => return Ok(blocks),
        };

        let page_dict = match page_obj.as_dict() {
            Ok(dict) => dict,
            Err(_) => return Ok(blocks),
        };

        // Get page content stream(s)
        let contents = match page_dict.get(b"Contents") {
            Ok(c) => c,
            Err(_) => return Ok(blocks),
        };

        // Decode content stream
        let content_data = match contents {
            lopdf::Object::Reference(r) => match self.document.get_object(*r) {
                Ok(obj) => match obj.as_stream() {
                    Ok(stream) => match stream.decode_content() {
                        Ok(data) => data,
                        Err(_) => return Ok(blocks),
                    },
                    Err(_) => return Ok(blocks),
                },
                Err(_) => return Ok(blocks),
            },
            _ => return Ok(blocks),
        };

        // Parse content stream operations
        self.parse_content_operations(&content_data)
    }

    /// Parse PDF content operations to extract text blocks
    fn parse_content_operations(
        &self,
        content: &lopdf::content::Content,
    ) -> Result<Vec<TextBlock>> {
        let mut blocks = Vec::new();
        let mut current_x = 0.0;
        let mut current_y = 0.0;
        let mut current_font_size = 12.0;
        let mut line_start_x = 0.0;
        let mut line_start_y = 0.0;

        for operation in &content.operations {
            match operation.operator.as_ref() {
                // BT - Begin text object (reset position)
                "BT" => {
                    current_x = 0.0;
                    current_y = 0.0;
                    line_start_x = 0.0;
                    line_start_y = 0.0;
                }

                // ET - End text object
                "ET" => {}

                // Tm - Text matrix (sets absolute position)
                "Tm" if operation.operands.len() >= 6 => {
                    // Matrix: [a b c d e f] where e=x, f=y
                    if let (Ok(x), Ok(y)) = (
                        operation.operands[4].as_float(),
                        operation.operands[5].as_float(),
                    ) {
                        current_x = x;
                        current_y = y;
                        line_start_x = current_x;
                        line_start_y = current_y;
                    }
                }

                // Td - Move text position (relative)
                "Td" if operation.operands.len() >= 2 => {
                    if let (Ok(tx), Ok(ty)) = (
                        operation.operands[0].as_float(),
                        operation.operands[1].as_float(),
                    ) {
                        current_x += tx;
                        current_y += ty;
                    }
                }

                // TD - Move text position and set leading
                "TD" if operation.operands.len() >= 2 => {
                    if let (Ok(tx), Ok(ty)) = (
                        operation.operands[0].as_float(),
                        operation.operands[1].as_float(),
                    ) {
                        current_x += tx;
                        current_y += ty;
                        line_start_x = current_x;
                        line_start_y = current_y;
                    }
                }

                // T* - Move to start of next line
                "T*" => {
                    current_x = line_start_x;
                    current_y = line_start_y - current_font_size * 1.2; // Typical leading
                    line_start_y = current_y;
                }

                // Tf - Set font and size
                "Tf" if operation.operands.len() >= 2 => {
                    if let Ok(size) = operation.operands[1].as_float() {
                        current_font_size = size;
                    }
                }

                // Tj - Show text
                "Tj" if operation.operands.len() >= 1 => {
                    if let Ok(text_bytes) = operation.operands[0].as_str() {
                        let text = String::from_utf8_lossy(text_bytes).to_string();
                        if !text.trim().is_empty() {
                            let text_len = text.len();
                            blocks.push(TextBlock {
                                text,
                                x: current_x,
                                y: current_y,
                                font_size: current_font_size,
                                font_name: None,
                            });
                            // Advance X position (rough estimate)
                            current_x += text_len as f32 * current_font_size * 0.5;
                        }
                    }
                }

                // TJ - Show text with positioning array
                "TJ" if operation.operands.len() >= 1 => {
                    if let Ok(array) = operation.operands[0].as_array() {
                        let mut combined_text = String::new();
                        for item in array {
                            if let Ok(text_bytes) = item.as_str() {
                                let part = String::from_utf8_lossy(text_bytes);
                                combined_text.push_str(&part);
                            } else if let Ok(num) = item.as_float() {
                                // Negative numbers indicate space adjustment
                                if num < -100.0 {
                                    combined_text.push(' ');
                                }
                            }
                        }
                        if !combined_text.trim().is_empty() {
                            blocks.push(TextBlock {
                                text: combined_text.clone(),
                                x: current_x,
                                y: current_y,
                                font_size: current_font_size,
                                font_name: None,
                            });
                            // Advance X position
                            current_x += combined_text.len() as f32 * current_font_size * 0.5;
                        }
                    }
                }

                // ' - Move to next line and show text
                "'" if operation.operands.len() >= 1 => {
                    current_x = line_start_x;
                    current_y = line_start_y - current_font_size * 1.2;
                    line_start_y = current_y;

                    if let Ok(text_bytes) = operation.operands[0].as_str() {
                        let text = String::from_utf8_lossy(text_bytes).to_string();
                        if !text.trim().is_empty() {
                            blocks.push(TextBlock {
                                text,
                                x: current_x,
                                y: current_y,
                                font_size: current_font_size,
                                font_name: None,
                            });
                        }
                    }
                }

                _ => {}
            }
        }

        Ok(blocks)
    }

    /// Estimate font size from text content heuristics
    fn estimate_font_size(&self, line: &str) -> f32 {
        let trimmed = line.trim();

        // Very short lines in ALL CAPS or with numbers (like titles)
        if trimmed.len() < 50
            && trimmed.chars().filter(|c| c.is_uppercase()).count() > trimmed.len() / 2
        {
            return 18.0; // Likely a heading
        }

        // Lines starting with numbered sections
        if trimmed.starts_with(|c: char| c.is_numeric()) && trimmed.contains("Introduction")
            || trimmed.contains("Abstract")
            || trimmed.contains("Conclusion")
        {
            return 16.0; // Section heading
        }

        // Lines starting with subsection numbers like "3.1"
        if trimmed
            .chars()
            .take(5)
            .filter(|c| c.is_numeric() || *c == '.')
            .count()
            >= 3
        {
            return 14.0; // Subsection
        }

        // Default body text
        10.0
    }

    /// Reconstruct text from blocks in reading order
    fn reconstruct_text_from_blocks(&self, blocks: &[TextBlock]) -> String {
        blocks
            .iter()
            .map(|b| b.text.as_str())
            .collect::<Vec<_>>()
            .join("\n")
    }

    /// Extract all pages with detailed information
    pub fn extract_all_pages(&self) -> Result<Vec<PdfPage>> {
        let page_count = self.page_count();
        let mut pages = Vec::with_capacity(page_count);

        for i in 0..page_count {
            pages.push(self.extract_page(i)?);
        }

        Ok(pages)
    }

    /// Get PDF metadata
    pub fn get_metadata(&self) -> PdfMetadata {
        let mut metadata = PdfMetadata::default();

        if let Ok(info_dict) = self.document.trailer.get(b"Info") {
            if let Ok(info) = info_dict.as_dict() {
                // Extract title
                if let Ok(title) = info.get(b"Title") {
                    if let Ok(title_bytes) = title.as_str() {
                        metadata.title = Some(String::from_utf8_lossy(title_bytes).to_string());
                    }
                }

                // Extract author
                if let Ok(author) = info.get(b"Author") {
                    if let Ok(author_bytes) = author.as_str() {
                        metadata.author = Some(String::from_utf8_lossy(author_bytes).to_string());
                    }
                }

                // Extract creation date
                if let Ok(created) = info.get(b"CreationDate") {
                    if let Ok(created_bytes) = created.as_str() {
                        metadata.created = Some(String::from_utf8_lossy(created_bytes).to_string());
                    }
                }

                // Extract modification date
                if let Ok(modified) = info.get(b"ModDate") {
                    if let Ok(modified_bytes) = modified.as_str() {
                        metadata.modified =
                            Some(String::from_utf8_lossy(modified_bytes).to_string());
                    }
                }

                // Extract subject
                if let Ok(subject) = info.get(b"Subject") {
                    if let Ok(subject_bytes) = subject.as_str() {
                        metadata.subject = Some(String::from_utf8_lossy(subject_bytes).to_string());
                    }
                }

                // Extract keywords
                if let Ok(keywords) = info.get(b"Keywords") {
                    if let Ok(keywords_bytes) = keywords.as_str() {
                        metadata.keywords =
                            Some(String::from_utf8_lossy(keywords_bytes).to_string());
                    }
                }

                // Extract producer
                if let Ok(producer) = info.get(b"Producer") {
                    if let Ok(producer_bytes) = producer.as_str() {
                        metadata.producer =
                            Some(String::from_utf8_lossy(producer_bytes).to_string());
                    }
                }
            }
        }

        metadata.page_count = self.page_count();
        metadata
    }

    /// Check if PDF is encrypted
    pub fn is_encrypted(&self) -> bool {
        self.document.is_encrypted()
    }

    /// Get PDF version
    pub fn version(&self) -> String {
        self.document.version.clone()
    }

    /// Extract tables from a specific page
    pub fn extract_tables(&self, page_num: usize) -> Result<Vec<DetectedTable>> {
        let text = self.extract_text(page_num)?;
        Ok(self.table_detector.detect_tables(&text))
    }

    /// Extract tables from all pages
    pub fn extract_all_tables(&self) -> Result<Vec<(usize, Vec<DetectedTable>)>> {
        let page_count = self.page_count();
        let mut all_tables = Vec::new();

        for page_num in 0..page_count {
            let tables = self.extract_tables(page_num)?;
            if !tables.is_empty() {
                all_tables.push((page_num, tables));
            }
        }

        Ok(all_tables)
    }
}

/// PDF metadata
#[derive(Debug, Clone, Default)]
pub struct PdfMetadata {
    /// Document title
    pub title: Option<String>,
    /// Author
    pub author: Option<String>,
    /// Creation date (PDF date format)
    pub created: Option<String>,
    /// Modification date (PDF date format)
    pub modified: Option<String>,
    /// Subject
    pub subject: Option<String>,
    /// Keywords
    pub keywords: Option<String>,
    /// Producer (PDF software)
    pub producer: Option<String>,
    /// Total page count
    pub page_count: usize,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_pdf_metadata_default() {
        let metadata = PdfMetadata::default();
        assert_eq!(metadata.page_count, 0);
        assert!(metadata.title.is_none());
    }

    #[test]
    fn test_text_block_creation() {
        let block = TextBlock {
            text: "Hello".to_string(),
            x: 10.0,
            y: 20.0,
            font_size: 12.0,
            font_name: Some("Arial".to_string()),
        };
        assert_eq!(block.text, "Hello");
        assert_eq!(block.font_size, 12.0);
    }

    #[test]
    fn test_pdf_page_creation() {
        let page = PdfPage {
            number: 0,
            text: "Page content".to_string(),
            width: 612.0,
            height: 792.0,
            text_blocks: vec![],
        };
        assert_eq!(page.number, 0);
        assert_eq!(page.width, 612.0);
    }

    // Integration tests require actual PDF files
    // These will be added in tests/pdf_parser_tests.rs with fixtures
}