Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
simple_with_v8.cc
Go to the documentation of this file.
1// Copyright 2020 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// No-frills example of how to initialize and call into a PDFium environment
6// including V8 support (but not XFA) from C++. Since the V8 API is in C++,
7// C++ is required in this case (not just C).
8
9#include <string.h>
10
11#include "public/fpdf_edit.h"
12#include "public/fpdf_formfill.h"
13#include "public/fpdfview.h"
14#include "v8/include/libplatform/libplatform.h"
15#include "v8/include/v8-array-buffer.h"
16#include "v8/include/v8-initialization.h"
17#include "v8/include/v8-isolate.h"
18
19int main(int argc, const char* argv[]) {
20 // V8 must be initialized before the PDFium library if using V8.
21 v8::V8::InitializeICUDefaultLocation(argv[0]);
22 v8::V8::InitializeExternalStartupData(argv[0]);
23 v8::Platform* platform = v8::platform::NewDefaultPlatform().release();
24 v8::V8::InitializePlatform(platform);
25 v8::V8::Initialize();
26
27 v8::Isolate::CreateParams params;
28 params.array_buffer_allocator = static_cast<v8::ArrayBuffer::Allocator*>(
29 FPDF_GetArrayBufferAllocatorSharedInstance());
30 v8::Isolate* isolate = v8::Isolate::New(params);
31
32 // The PDF library must be initialized before creating a document.
33 FPDF_LIBRARY_CONFIG config;
34 memset(&config, 0, sizeof(config));
35 config.version = 3;
36 config.m_pIsolate = isolate;
37 config.m_pPlatform = platform;
39
40 // The document must be created before creating a form-fill environment.
41 // Typically use FPDF_LoadDocument() for pre-existing documents. Here, we
42 // create a new blank document for simplicity.
43 FPDF_DOCUMENT doc = FPDF_CreateNewDocument();
44
45 IPDF_JSPLATFORM jsplatform;
46 memset(&jsplatform, 0, sizeof(jsplatform));
47
48 FPDF_FORMFILLINFO formfillinfo;
49 memset(&formfillinfo, 0, sizeof(formfillinfo));
50 formfillinfo.version = 1;
51 formfillinfo.m_pJsPlatform = &jsplatform;
52
53 FPDF_FORMHANDLE form_handle =
55
56 // Typically use FPDF_LoadPage() for pre-existing pages. Here, we
57 // create a new blank page for simplicity.
58 FPDF_PAGE page = FPDFPage_New(doc, 0, 640.0, 480.0);
59 FORM_OnAfterLoadPage(page, form_handle);
61
62 // Do actual work with the page here.
63
65 FORM_OnBeforeClosePage(page, form_handle);
67
72
73 isolate->Dispose();
74 v8::V8::ShutdownPlatform();
75 delete platform;
76
77 return 0;
78}
FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDFPage_New(FPDF_DOCUMENT document, int page_index, double width, double height)
FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_CreateNewDocument()
#define FPDFDOC_AACTION_WC
FPDF_EXPORT void FPDF_CALLCONV FORM_OnAfterLoadPage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle)
FPDF_EXPORT void FPDF_CALLCONV FORM_OnBeforeClosePage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle)
#define FPDFPAGE_AACTION_CLOSE
FPDF_EXPORT void FPDF_CALLCONV FORM_DoPageAAction(FPDF_PAGE page, FPDF_FORMHANDLE hHandle, int aaType)
FPDF_EXPORT void FPDF_CALLCONV FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, int aaType)
FPDF_EXPORT FPDF_FORMHANDLE FPDF_CALLCONV FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, FPDF_FORMFILLINFO *formInfo)
FPDF_EXPORT void FPDF_CALLCONV FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle)
#define FPDFPAGE_AACTION_OPEN
FPDF_EXPORT void FPDF_CALLCONV FPDF_DestroyLibrary()
FPDF_EXPORT void FPDF_CALLCONV FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG *config)
FPDF_EXPORT void FPDF_CALLCONV FPDF_CloseDocument(FPDF_DOCUMENT document)
FPDF_EXPORT void FPDF_CALLCONV FPDF_ClosePage(FPDF_PAGE page)
int main(int argc, const char *argv[])
IPDF_JSPLATFORM * m_pJsPlatform