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 // from C. The PDFium API is compatible with C (the C++ internals are hidden
7 // beneath it).
8
9 #include <string.h>
10
11 #include "public/fpdf_edit.h"
12 #include "public/fpdf_formfill.h"
13 #include "public/fpdfview.h"
14
main(int argc,const char * argv[])15 int main(int argc, const char* argv[]) {
16 // The PDF library must be initialized before creating a document.
17 FPDF_LIBRARY_CONFIG config;
18 memset(&config, 0, sizeof(config));
19 config.version = 3;
20 FPDF_InitLibraryWithConfig(&config);
21
22 // The document must be created before creating a form-fill environment.
23 // Typically use FPDF_LoadDocument() for pre-existing documents. Here, we
24 // create a new blank document for simplicity.
25 FPDF_DOCUMENT doc = FPDF_CreateNewDocument();
26
27 FPDF_FORMFILLINFO formfillinfo;
28 memset(&formfillinfo, 0, sizeof(formfillinfo));
29 formfillinfo.version = 1;
30
31 FPDF_FORMHANDLE form_handle =
32 FPDFDOC_InitFormFillEnvironment(doc, &formfillinfo);
33
34 // Typically use FPDF_LoadPage() for pre-existing pages. Here, we
35 // create a new blank page for simplicity.
36 FPDF_PAGE page = FPDFPage_New(doc, 0, 640.0, 480.0);
37 FORM_OnAfterLoadPage(page, form_handle);
38 FORM_DoPageAAction(page, form_handle, FPDFPAGE_AACTION_OPEN);
39
40 // Do actual work with the page here.
41
42 FORM_DoPageAAction(page, form_handle, FPDFPAGE_AACTION_CLOSE);
43 FORM_OnBeforeClosePage(page, form_handle);
44 FPDF_ClosePage(page);
45
46 FORM_DoDocumentAAction(form_handle, FPDFDOC_AACTION_WC);
47 FPDFDOC_ExitFormFillEnvironment(form_handle);
48 FPDF_CloseDocument(doc);
49 FPDF_DestroyLibrary();
50
51 return 0;
52 }
53