PDF SDK Documentation

Comprehensive Guide for Developers: Features, Integration, and API Reference

Loading...
Searching...
No Matches
core.h
1// Copyright (c) 2009-2025 Avanquest Software. All rights reserved.
2
3#ifndef PDFSDK_CXX_CORE_H_INCLUDED_
4#define PDFSDK_CXX_CORE_H_INCLUDED_
5
6#include <pdfsdk/core.h>
7#include <pdfsdk/cxx/action.h>
8#include <pdfsdk/cxx/annot.h>
10#include <pdfsdk/cxx/clip.h>
11#include <pdfsdk/cxx/collection.h>
12#include <pdfsdk/cxx/color.h>
14#include <pdfsdk/cxx/content.h>
15#include <pdfsdk/cxx/dest.h>
16#include <pdfsdk/cxx/document.h>
17#include <pdfsdk/cxx/element.h>
18#include <pdfsdk/cxx/filespec.h>
19#include <pdfsdk/cxx/font.h>
20#include <pdfsdk/cxx/form_field.h>
21#include <pdfsdk/cxx/function.h>
22#include <pdfsdk/cxx/gstate.h>
23#include <pdfsdk/cxx/object.h>
24#include <pdfsdk/cxx/optional_content.h>
25#include <pdfsdk/cxx/page.h>
27#include <pdfsdk/cxx/pattern.h>
28#include <pdfsdk/cxx/progress_monitor.h>
29#include <pdfsdk/cxx/read_stream.h>
30#include <pdfsdk/cxx/shading.h>
31#include <pdfsdk/cxx/soft_mask.h>
33#include <pdfsdk/cxx/struct_tree.h>
34#include <pdfsdk/cxx/text_run.h>
35#include <pdfsdk/cxx/write_stream.h>
36#include <pdfsdk/cxx/xgroup.h>
37#include <pdfsdk/cxx/xobject.h>
38
39namespace PDF {
40
53inline void Init(std::string_view licenseKey,
54 const std::filesystem::path& resourcesDir = std::filesystem::path(),
55 const std::filesystem::path& tempDir = std::filesystem::path(),
56 const std::filesystem::path& appDataDir = std::filesystem::path()) {
57 std::wstring resourcesDirStr = resourcesDir.wstring();
58 std::wstring tempDirStr = tempDir.wstring();
59 std::wstring appDataDirStr = appDataDir.wstring();
60
61 PDInitData initdata = {};
62 initdata.resourcesDirectoryPath = resourcesDirStr.c_str();
63 initdata.tempDirectoryPath = tempDirStr.c_str();
64 initdata.appDataDirectoryPath = appDataDirStr.c_str();
65
66 std::string licenseKeyStr{licenseKey};
67 PDF_CHECK_SUCCESS_X(PDInit(licenseKeyStr.c_str(), &initdata, "cxx"));
68}
69
76inline void Done() noexcept {
77 PDDone();
78}
79
87struct InitScope {
100 InitScope(const std::string& licenseKey,
101 const std::filesystem::path& resourcesDir = std::filesystem::path(),
102 const std::filesystem::path& tempDir = std::filesystem::path(),
103 const std::filesystem::path& appDataDir = std::filesystem::path()) {
104 Init(licenseKey, resourcesDir, tempDir, appDataDir);
105 }
106
113 ~InitScope() { Done(); }
114
115 InitScope(const InitScope&) = delete;
116 InitScope& operator=(const InitScope&) = delete;
117
118 InitScope(InitScope&&) = delete;
119 InitScope& operator=(InitScope&&) = delete;
120};
121
131inline PDAtom Atomize(const char* c_str) {
132 PDAtom atom = kPDAtomNull;
133 PDF_CHECK_SUCCESS_X(PDAtomPutString(c_str, &atom));
134 return atom;
135}
136
146inline PDAtom Atomize(const std::string& str) {
147 return Atomize(str.c_str());
148}
149
159inline PDAtom Atomize(std::string_view sv) {
160 return Atomize(std::string{sv});
161}
162
172inline std::string AtomToString(PDAtom atom) {
173 const char* str = "";
174 PDF_CHECK_SUCCESS_X(PDAtomGetString(atom, &str));
175 return str;
176}
177
178} // namespace PDF
179
180#endif // PDFSDK_CXX_CORE_H_INCLUDED_
Action API.
Annotation API.
Bookmark API.
Color Space API.
Page Text API.
Standard Security API.
Represents a scope for initializing and cleaning up the PDF SDK.
Definition core.h:87
InitScope(const std::string &licenseKey, const std::filesystem::path &resourcesDir=std::filesystem::path(), const std::filesystem::path &tempDir=std::filesystem::path(), const std::filesystem::path &appDataDir=std::filesystem::path())
Constructs an InitScope object and initializes the PDF SDK.
Definition core.h:100
~InitScope()
Destructs the InitScope object and cleans up the PDF SDK.
Definition core.h:113