feat: implement PDF page parsing, text extraction, and document modeling logic

This commit is contained in:
azeeee05
2026-07-07 19:03:11 +05:30
parent a383bd8704
commit 99f87eb7cf
8 changed files with 109 additions and 24 deletions
@@ -5,6 +5,7 @@
#include <string>
#include <vector>
#include <cstdint>
#include <array>
namespace pdfengine {
@@ -198,6 +199,7 @@ public:
std::string timestamp;
int pageIndex = 0;
std::vector<std::vector<Point2D>> paths;
std::vector<std::array<Point2D, 4>> quadPoints;
std::string fieldName;
std::string fieldValue;
+5 -11
View File
@@ -133,22 +133,19 @@ std::expected<void, EngineError> PdfiumDocument::applyOp_pageRotation(const nloh
#endif
}
std::expected<void, EngineError> PdfiumDocument::applyOp_pageDeletion(const nlohmann::json& op, int pageIndex) {
#ifdef PDFENGINE_WITH_PDFIUM
std::expected<void, EngineError> PdfiumDocument::applyOp_pageDeletion(const nlohmann::json& op, int pageIndex) {
if (pageCount() <= 1) {
spdlog::error("Cannot delete the only page in the document");
return std::unexpected(EngineError::Unknown);
}
FPDFPage_Delete(doc_, pageIndex);
return {};
#else
(void)op; (void)pageIndex;
return std::unexpected(EngineError::Unknown);
#endif
}
#endif
std::expected<void, EngineError> PdfiumDocument::applyOp_pageReorder(const nlohmann::json& op, int pageIndex) {
#ifdef PDFENGINE_WITH_PDFIUM
std::expected<void, EngineError> PdfiumDocument::applyOp_pageReorder(const nlohmann::json& op, int pageIndex) {
if (!op.contains("data") || !op["data"].is_object()) {
spdlog::error("page_reorder operation missing 'data' object");
return std::unexpected(EngineError::InvalidFormat);
@@ -170,10 +167,7 @@ std::expected<void, EngineError> PdfiumDocument::applyOp_pageReorder(const nlohm
return std::unexpected(EngineError::Unknown);
}
return {};
#else
(void)op; (void)pageIndex;
return std::unexpected(EngineError::Unknown);
#endif
}
#endif
}
}
+15
View File
@@ -614,6 +614,21 @@ std::expected<std::vector<PdfPage::AnnotationInfo>, EngineError> PdfiumPage::ext
}
if (!stroke.empty()) info.paths.push_back(std::move(stroke));
}
} else if (subtype == FPDF_ANNOT_HIGHLIGHT || subtype == FPDF_ANNOT_STRIKEOUT || subtype == FPDF_ANNOT_UNDERLINE || subtype == FPDF_ANNOT_SQUIGGLY) {
const double pageH = height();
size_t quadCount = FPDFAnnot_CountAttachmentPoints(annot);
for (size_t q = 0; q < quadCount; ++q) {
FS_QUADPOINTSF quad;
if (FPDFAnnot_GetAttachmentPoints(annot, q, &quad)) {
std::array<Point2D, 4> pts = {{
{static_cast<double>(quad.x1), pageH - static_cast<double>(quad.y1)},
{static_cast<double>(quad.x2), pageH - static_cast<double>(quad.y2)},
{static_cast<double>(quad.x3), pageH - static_cast<double>(quad.y3)},
{static_cast<double>(quad.x4), pageH - static_cast<double>(quad.y4)}
}};
info.quadPoints.push_back(pts);
}
}
}
result.push_back(info);