# PDFiumVCL

## Overview

PDFiumVCL is a Delphi VCL component library that provides a complete Object Pascal wrapper for Google's PDFium PDF rendering engine. With this component, developers can easily implement PDF document viewing, editing, printing, and other features in Delphi/C++ Builder applications.

## Features

- **Complete PDFium API Wrapper** - Covers all functionality including document operations, page rendering, text extraction, form handling, and more
- **Wide Delphi Version Support** - From Delphi 5 to Delphi 12 Athens
- **Cross-Platform Compilation** - Supports both Win32 and Win64 target platforms
- **VCL Component Design** - Provides visual TPdf and TPdfView components
- **Rich Sample Programs** - Includes Delphi, C++ Builder, and Lazarus examples

## Directory Structure

```
PDFiumVCL/
├── Lib/                    # Core source code
│   ├── PDFium.pas          # Main unit - VCL component wrapper
│   ├── PDFiumVcl.inc       # Compiler conditional configuration
│   ├── FPdfView.pas        # PDFium core API bindings
│   ├── FPdfDoc.pas         # Document operations API
│   ├── FPdfText.pas        # Text extraction API
│   ├── FPdfEdit.pas        # Page editing API
│   ├── FPdfAnnot.pas       # Annotations API
│   ├── FPdfAttachment.pas  # Attachments API
│   ├── FPdfFormFill.pas    # Form filling API
│   ├── FPdfPageOps.pas     # Page operations API
│   ├── FPdfSignature.pas   # Signature API
│   ├── FPdfStructTree.pas  # Structure tree API
│   ├── FPdfDataAvail.pas   # Data availability API
│   ├── FPdfExtensions.pas  # Extensions API
│   ├── FPdfUtils.pas       # Utility functions
│   └── PDFiumReg.pas       # Component registration
├── DLLs/                   # PDFium dynamic link libraries
│   ├── pdfium32.dll        # 32-bit basic version
│   ├── pdfium64.dll        # 64-bit basic version
│   ├── pdfium32v8.dll      # 32-bit V8 engine version
│   └── pdfium64v8.dll      # 64-bit V8 engine version
├── Demo/                   # Sample programs
│   ├── Delphi/             # Delphi examples
│   ├── CBuilder/           # C++ Builder examples
│   └── Lazarus/            # Lazarus examples
└── HtmlHelp/               # Help documentation
```

## Core Components

### TPdf Component

TPdf is the primary PDF document processing component, inheriting from `TComponent`, providing the following functionality:

| Category | Key Methods/Properties |
|----------|----------------------|
| Document Operations | `LoadDocument`, `SaveAs`, `CreateDocument` |
| Page Navigation | `PageNumber`, `PageCount`, `PageWidth`, `PageHeight` |
| Page Rendering | `RenderPage`, `RenderTile` |
| Text Processing | `Text`, `FindFirst`, `FindNext`, `CharacterCount` |
| Bookmark Management | `Bookmarks`, `BookmarkChildren` |
| Link Handling | `LinkAnnotations`, `WebLinks` |
| Form Processing | `FormFieldCount`, `FormFieldInfo`, `FormType` |
| Annotation Operations | `AnnotationCount`, `CreateAnnotation`, `DeleteAnnotation` |
| Attachment Management | `AttachmentCount`, `Attachment`, `CreateAttachment` |
| Metadata Access | `Title`, `Author`, `Subject`, `Keywords`, `Creator`, `Producer` |

### TPdfView Component

TPdfView is a PDF viewer control, inheriting from `TScrollingWinControl`, providing the following features:

- Automatic scrolling and zoom support
- Page rotation (0°, 90°, 180°, 270°)
- Display modes (single page continuous, two page continuous)
- Text selection and search highlighting
- Link click navigation
- Form interaction support
- Coordinate transformation (device coordinates ↔ page coordinates)

## Architecture Design

### Layered Architecture

```
┌─────────────────────────────────────────┐
│           VCL Components                │
│  ┌─────────────┐  ┌─────────────────┐   │
│  │    TPdf     │  │    TPdfView     │   │
│  └─────────────┘  └─────────────────┘   │
├─────────────────────────────────────────┤
│         API Binding Layer               │
│  ┌────────┐ ┌────────┐ ┌────────────┐   │
│  │FPdfView│ │FPdfDoc │ │FPdfText... │   │
│  └────────┘ └────────┘ └────────────┘   │
├─────────────────────────────────────────┤
│         PDFium DLL (C Library)          │
│  ┌────────────────────────────────────┐ │
│  │  pdfium32.dll / pdfium64.dll       │ │
│  └────────────────────────────────────┘ │
└─────────────────────────────────────────┘
```

### Core Type Definitions

```pascal
// Page rotation
TRotation = (ro0, ro90, ro180, ro270);

// Page display mode
TPageMode = (pmNone, pmOutline, pmThumbs, pmFullScreen, 
             pmOptionalContentGroup, pmAttachments, pmUnknown);

// PDF action types
TPdfAction = (acUnsupported, acGoto, acGotoRemote, acUri, acLaunch);

// PDF version
TPdfVersion = (pvUnknown, pv10, pv11, pv12, pv13, pv14, pv15, pv16, pv17);

// Render options
TRenderOption = (reAnnotations, reLcd, reNoNativeText, reGrayscale, 
                 reDebugInfo, reNoCatchException, reLimitCache, reHalftone, 
                 rePrinting, reReverseByteOrder, reNoSmoothText, 
                 reNoSmoothImage, reNoSmoothPath);
```

### Handle Management

The component internally uses PDFium's opaque pointers for resource management:

```pascal
// Document handle
FDocument: FPDF_DOCUMENT;

// Page handle
FPage: FPDF_PAGE;

// Text page handle
FTextPage: FPDF_TEXTPAGE;

// Form handle
FFormHandle: FPDF_FORMHANDLE;

// Search handle
FFind: FPDF_SCHHANDLE;
```

## Compiler Compatibility

PDFiumVCL supports the following Delphi versions:

| Version Flag | Delphi Version |
|--------------|----------------|
| D5 | Delphi 5 |
| D6+ | Delphi 6 and above |
| D7+ | Delphi 7 and above |
| D2009+ | Delphi 2009 and above (Unicode support) |
| XE2+ | Delphi XE2 and above (Win64 support) |
| D12+ | Delphi 12 Athens |

## Installation

1. Add the `Lib` directory to Delphi's library path
2. Open the appropriate package file (e.g., `PDFiumVcl370.dpk`)
3. Compile and install the package
4. Ensure PDFium DLL files are in the application directory or system path

## Sample Programs

The Demo directory contains rich sample programs:

| Sample Name | Description |
|-------------|-------------|
| PdfViewer | PDF viewer |
| MultiPageViewer | Multi-page viewer |
| PrintPDF | PDF printing |
| PDFtoJpg | PDF to JPG conversion |
| ExtractText | Text extraction |
| ExtractImages | Image extraction |
| CreatePDF | Create PDF |
| MergePDF | Merge PDFs |
| SplitPDF | Split PDF |
| ImageToPDF | Image to PDF conversion |
| Attachment | Attachment operations |
| FontProperties | Font properties |
| SplitView | Split view |

## Dependencies

- **PDFium DLL** - Google PDFium rendering engine
  - `pdfium32.dll` / `pdfium64.dll` - Basic version
  - `pdfium32v8.dll` / `pdfium64v8.dll` - V8 JavaScript engine version (for XFA forms)

## License

- PDFiumVCL Components: Copyright (c) 2024-2025 loslab.com
- PDFium Library: Subject to [PDFium License](DLLs/PDFium-LICENSE)

## Support

- Project Homepage: https://loslab.com
- Issue Reporting: Please submit via the project issue tracker

---

