149 lines
No EOL
6.1 KiB
Markdown
149 lines
No EOL
6.1 KiB
Markdown
# MQLPDF — a PDF creation library in pure MQL5
| |
| |
Source code for the mql5.com article series **"Building a PDF Creation Library in MQL5"**.
| |
| |
Part 1: [https://www.mql5.com/en/articles/24094](https://www.mql5.com/en/articles/24094)
| |
| |
Part 2: [https://www.mql5.com/en/articles/24314](https://www.mql5.com/en/articles/24314)
| |
| |
Part 3: [https://www.mql5.com/en/articles/24568](https://www.mql5.com/en/articles/24568)
| |
| |
MQLPDF is developed step by step throughout the series, starting with the
| |
fundamentals of the PDF file format and gradually building the components needed
| |
to create complete PDF documents directly from MQL5.
| |
| |
The goal is not to wrap an external PDF library or rely on third-party tools.
| |
Instead, the series explores how a PDF document is structured internally and
| |
implements the required pieces in pure MQL5, eventually forming a reusable
| |
library for generating PDF files.
| |
| |
---
| |
| |
## Which version do I want?
| |
| |
**Use the release that matches the article you are reading.** Each part of the
| |
series has its own release, frozen at the state explained in that article. This
| |
means you can follow the implementation step by step without finding code that
| |
depends on concepts introduced only in later parts.
| |
| |
| Release | Article | What it adds |
| |
|---|---|---|
| |
| [`part-01`](https://forge.mql5.io/SandroBegashvil/MQLPDF/releases/tag/part-01) | [Part 1 — Writing a PDF by Hand](https://www.mql5.com/en/articles/24094) | Review the PDF structure and write the first PDFs |
| |
| [`part-02`](https://forge.mql5.io/SandroBegashvil/MQLPDF/releases/tag/part-02) | [Part 2 — Why PDFs Break](https://www.mql5.com/en/articles/24314) | Learn how a viewer opens a PDF backwards |
| |
| [`part-03`](https://forge.mql5.io/SandroBegashvil/MQLPDF/releases/tag/part-03) | [Part 3 — The Byte-Exact Writer](https://www.mql5.com/en/articles/24568) | Define basic libraries for PDF creation |
| |
| |
Later parts are added to this table as they are published. The `main` branch is
| |
always the newest state of the library and may therefore be ahead of the latest
| |
published article.
| |
| |
---
| |
| |
## Installing
| |
| |
Download the release archive that matches the article you are reading and
| |
extract it over your terminal's data folder (**File → Open Data Folder** in
| |
MetaTrader 5). The archive already has the correct directory structure, so the
| |
files land where they belong:
| |
| |
```text
| |
MQL5/
| |
├── Scripts/
| |
│ └── MQLPDF/
| |
│ ├── Part 01/
| |
│ │ └── Demo01_HelloPdf.mq5 // Write a simple PDF file by Hand
| |
│ ├── Part 02/
| |
│ │ ├── Demo02_BreakIt.mq5 // Create multiple PDF files (valid and invalid files)
| |
│ │ └── Demo02_Validate.mq5 // Check the validation of the files
| |
│ └── Part 03/
| |
│ ├── Demo03_HelloWriter.mq5 // rebuilds Part 1's file, then validates it
| |
│ └── Demo03_TextToPdf.mq5 // prints any text file to a paginated PDF
| |
└── Include/
| |
└── MQLPDF/
| |
├── PdfDefines.mqh // shared constants
| |
├── PdfBuffer.mqh // bytes, and the current offset
| |
├── PdfWriter.mqh // objects, the xref table, the trailer
| |
└── PdfValidate.mqh // carried over unchanged
| |
```
| |
| |
Then open the demo for the article in MetaEditor, compile it with **F7**, and
| |
run it as described in the corresponding article.
| |
| |
Library headers are included in the usual way:
| |
| |
```mql5
| |
#include <MQLPDF/...>
| |
```
| |
| |
Each release contains only the library components and demonstration files needed
| |
for that stage of the series, allowing the codebase to evolve alongside the
| |
articles.
| |
| |
---
| |
| |
## What is this series building?
| |
| |
A PDF file may look like a single document from the user's perspective, but
| |
internally it is a structured collection of objects, streams, references and
| |
other components. MQLPDF is built by exploring and implementing these concepts
| |
step by step.
| |
| |
As the series progresses, the library will gradually grow from low-level PDF
| |
file construction into a higher-level interface for creating documents.
| |
| |
The implementation may eventually cover concepts such as:
| |
| |
- PDF file and document structure
| |
- Objects and indirect references
| |
- Cross-reference information
| |
- Pages and page trees
| |
- Content streams
| |
- Text and fonts
| |
- Drawing operations and graphics
| |
- Images
| |
- Tables and higher-level document elements
| |
- Document layout and reusable components
| |
| |
The exact scope of each release follows the progression of the article series.
| |
| |
---
| |
| |
## Scope
| |
| |
MQLPDF is a **native MQL5 PDF generation library**. Its purpose is to allow MQL5
| |
programs to create PDF documents directly from code while keeping the underlying
| |
PDF structure accessible and understandable.
| |
| |
The project is developed as both a practical library and an educational journey.
| |
Rather than treating PDF generation as a black box, the series explains the
| |
format and the implementation decisions behind the code.
| |
| |
The final library is intended to provide progressively higher-level tools for
| |
creating documents, while the lower-level components remain available for users
| |
who need more control over the generated PDF.
| |
| |
---
| |
| |
## Removing it
| |
| |
All library files and demonstration programs are installed inside the terminal's
| |
data folder. Removing the `MQLPDF` folders from `MQL5/Include/` and
| |
`MQL5/Scripts/` removes the installed source code and demos.
| |
| |
Generated PDF files are handled by the corresponding demonstration or user
| |
program and may need to be removed separately if they are no longer required.
| |
| |
---
| |
| |
## Copyright and use
| |
| |
Copyright 2026, **Sandro Begashvili**
| |
| |
- mql5.com profile: [Sandro Begashvili on mql5.com](https://www.mql5.com/en/users/sandrobegashvil?utm_source=chatgpt.com)
| |
- Telegram: [MrMQL5Developer on Telegram](https://t.me/MrMQL5Developer?utm_source=chatgpt.com)
| |
| |
You are free to **use this code in your own projects and to extend it**,
| |
commercially or otherwise. The only thing asked in return is attribution: keep a
| |
mention of the author's mql5.com profile in the source you derive from it.
| |
| |
If you build something with it, I would genuinely like to see it — the Telegram
| |
link above is the fastest way to reach me. |