7#include "fxjs/cjs_document.h"
13#include "constants/access_permissions.h"
14#include "core/fpdfapi/page/cpdf_pageimagecache.h"
15#include "core/fpdfapi/page/cpdf_pageobject.h"
16#include "core/fpdfapi/page/cpdf_textobject.h"
17#include "core/fpdfapi/parser/cpdf_array.h"
18#include "core/fpdfapi/parser/cpdf_dictionary.h"
19#include "core/fpdfapi/parser/cpdf_name.h"
20#include "core/fpdfapi/parser/cpdf_string.h"
21#include "core/fpdfdoc/cpdf_interactiveform.h"
22#include "core/fpdfdoc/cpdf_nametree.h"
23#include "fpdfsdk/cpdfsdk_annotiteration.h"
24#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
25#include "fpdfsdk/cpdfsdk_interactiveform.h"
26#include "fpdfsdk/cpdfsdk_pageview.h"
27#include "fxjs/cjs_annot.h"
28#include "fxjs/cjs_app.h"
29#include "fxjs/cjs_delaydata.h"
30#include "fxjs/cjs_event_context.h"
31#include "fxjs/cjs_field.h"
32#include "fxjs/cjs_icon.h"
33#include "fxjs/js_resources.h"
34#include "third_party/base/check.h"
35#include "third_party/base/containers/span.h"
36#include "v8/include/v8-container.h"
39 {
"ADBE", get_ADBE_static, set_ADBE_static},
40 {
"author", get_author_static, set_author_static},
41 {
"baseURL", get_base_URL_static, set_base_URL_static},
42 {
"bookmarkRoot", get_bookmark_root_static, set_bookmark_root_static},
43 {
"calculate", get_calculate_static, set_calculate_static},
44 {
"Collab", get_collab_static, set_collab_static},
45 {
"creationDate", get_creation_date_static, set_creation_date_static},
46 {
"creator", get_creator_static, set_creator_static},
47 {
"delay", get_delay_static, set_delay_static},
48 {
"dirty", get_dirty_static, set_dirty_static},
49 {
"documentFileName", get_document_file_name_static,
50 set_document_file_name_static},
51 {
"external", get_external_static, set_external_static},
52 {
"filesize", get_filesize_static, set_filesize_static},
53 {
"icons", get_icons_static, set_icons_static},
54 {
"info", get_info_static, set_info_static},
55 {
"keywords", get_keywords_static, set_keywords_static},
56 {
"layout", get_layout_static, set_layout_static},
57 {
"media", get_media_static, set_media_static},
58 {
"modDate", get_mod_date_static, set_mod_date_static},
59 {
"mouseX", get_mouse_x_static, set_mouse_x_static},
60 {
"mouseY", get_mouse_y_static, set_mouse_y_static},
61 {
"numFields", get_num_fields_static, set_num_fields_static},
62 {
"numPages", get_num_pages_static, set_num_pages_static},
63 {
"pageNum", get_page_num_static, set_page_num_static},
64 {
"pageWindowRect", get_page_window_rect_static,
65 set_page_window_rect_static},
66 {
"path", get_path_static, set_path_static},
67 {
"producer", get_producer_static, set_producer_static},
68 {
"subject", get_subject_static, set_subject_static},
69 {
"title", get_title_static, set_title_static},
70 {
"URL", get_URL_static, set_URL_static},
71 {
"zoom", get_zoom_static, set_zoom_static},
72 {
"zoomType", get_zoom_type_static, set_zoom_type_static}};
75 {
"addAnnot", addAnnot_static},
76 {
"addField", addField_static},
77 {
"addLink", addLink_static},
78 {
"addIcon", addIcon_static},
79 {
"calculateNow", calculateNow_static},
80 {
"closeDoc", closeDoc_static},
81 {
"createDataObject", createDataObject_static},
82 {
"deletePages", deletePages_static},
83 {
"exportAsText", exportAsText_static},
84 {
"exportAsFDF", exportAsFDF_static},
85 {
"exportAsXFDF", exportAsXFDF_static},
86 {
"extractPages", extractPages_static},
87 {
"getAnnot", getAnnot_static},
88 {
"getAnnots", getAnnots_static},
89 {
"getAnnot3D", getAnnot3D_static},
90 {
"getAnnots3D", getAnnots3D_static},
91 {
"getField", getField_static},
92 {
"getIcon", getIcon_static},
93 {
"getLinks", getLinks_static},
94 {
"getNthFieldName", getNthFieldName_static},
95 {
"getOCGs", getOCGs_static},
96 {
"getPageBox", getPageBox_static},
97 {
"getPageNthWord", getPageNthWord_static},
98 {
"getPageNthWordQuads", getPageNthWordQuads_static},
99 {
"getPageNumWords", getPageNumWords_static},
100 {
"getPrintParams", getPrintParams_static},
101 {
"getURL", getURL_static},
102 {
"gotoNamedDest", gotoNamedDest_static},
103 {
"importAnFDF", importAnFDF_static},
104 {
"importAnXFDF", importAnXFDF_static},
105 {
"importTextData", importTextData_static},
106 {
"insertPages", insertPages_static},
107 {
"mailDoc", mailDoc_static},
108 {
"mailForm", mailForm_static},
109 {
"print", print_static},
110 {
"removeField", removeField_static},
111 {
"replacePages", replacePages_static},
112 {
"resetForm", resetForm_static},
113 {
"removeIcon", removeIcon_static},
114 {
"saveAs", saveAs_static},
115 {
"submitForm", submitForm_static},
116 {
"syncAnnotScan", syncAnnotScan_static}};
118uint32_t CJS_Document::ObjDefnID = 0;
119const char CJS_Document::kName[] =
"Document";
129 JSConstructor<CJS_Document>, JSDestructor);
134CJS_Document::
CJS_Document(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
142CJS_Result CJS_Document::get_num_fields(CJS_Runtime* pRuntime) {
148 static_cast<
int>(pPDFForm->CountFields(WideString
())))
);
151CJS_Result CJS_Document::set_num_fields(CJS_Runtime* pRuntime,
152 v8::Local<v8::Value> vp) {
156CJS_Result CJS_Document::get_dirty(CJS_Runtime* pRuntime) {
160 return CJS_Result::Success(
161 pRuntime->NewBoolean(!!m_pFormFillEnv->GetChangeMark()));
164CJS_Result CJS_Document::set_dirty(CJS_Runtime* pRuntime,
165 v8::Local<v8::Value> vp) {
169 pRuntime->ToBoolean(vp) ? m_pFormFillEnv->SetChangeMark()
170 : m_pFormFillEnv->ClearChangeMark();
174CJS_Result CJS_Document::get_ADBE(CJS_Runtime* pRuntime) {
178CJS_Result CJS_Document::set_ADBE(CJS_Runtime* pRuntime,
179 v8::Local<v8::Value> vp) {
183CJS_Result CJS_Document::get_page_num(CJS_Runtime* pRuntime) {
187 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView();
194CJS_Result CJS_Document::set_page_num(CJS_Runtime* pRuntime,
195 v8::Local<v8::Value> vp) {
199 int iPageCount = m_pFormFillEnv->GetPageCount();
200 int iPageNum = pRuntime->ToInt32(vp);
201 if (iPageNum >= 0 && iPageNum < iPageCount)
202 m_pFormFillEnv->JS_docgotoPage(iPageNum);
203 else if (iPageNum >= iPageCount)
204 m_pFormFillEnv->JS_docgotoPage(iPageCount - 1);
205 else if (iPageNum < 0)
206 m_pFormFillEnv->JS_docgotoPage(0);
211CJS_Result CJS_Document::addAnnot(CJS_Runtime* pRuntime,
212 pdfium::span<v8::Local<v8::Value>> params) {
217CJS_Result CJS_Document::addField(CJS_Runtime* pRuntime,
218 pdfium::span<v8::Local<v8::Value>> params) {
224 CJS_Runtime* pRuntime,
225 pdfium::span<v8::Local<v8::Value>> params) {
231 CJS_Runtime* pRuntime,
232 pdfium::span<v8::Local<v8::Value>> params) {
238 CJS_Runtime* pRuntime,
239 pdfium::span<v8::Local<v8::Value>> params) {
244CJS_Result CJS_Document::getField(CJS_Runtime* pRuntime,
245 pdfium::span<v8::Local<v8::Value>> params) {
252 WideString wideName = pRuntime->ToWideString(params[0]);
254 if (pPDFForm->CountFields(wideName) <= 0)
257 v8::Local<v8::Object> pFieldObj = pRuntime->NewFXJSBoundObject(
258 CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
259 if (pFieldObj.IsEmpty())
262 auto* pJSField =
static_cast<CJS_Field*>(
263 CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pFieldObj));
267 pJSField->AttachField(
this, wideName);
273 CJS_Runtime* pRuntime,
274 pdfium::span<v8::Local<v8::Value>> params) {
275 if (params.size() != 1)
280 int nIndex = pRuntime->ToInt32(params[0]);
293 CJS_Runtime* pRuntime,
294 pdfium::span<v8::Local<v8::Value>> params) {
300 CJS_Runtime* pRuntime,
301 pdfium::span<v8::Local<v8::Value>> params) {
307 CJS_Runtime* pRuntime,
308 pdfium::span<v8::Local<v8::Value>> params) {
313CJS_Result CJS_Document::mailDoc(CJS_Runtime* pRuntime,
314 pdfium::span<v8::Local<v8::Value>> params) {
318 v8::LocalVector<v8::Value> newParams = ExpandKeywordParams(
319 pRuntime, params, 6,
"bUI",
"cTo",
"cCc",
"cBcc",
"cSubject",
"cMsg");
322 if (IsExpandedParamKnown(newParams[0]))
323 bUI = pRuntime->ToBoolean(newParams[0]);
326 if (IsExpandedParamKnown(newParams[1]))
327 cTo = pRuntime->ToWideString(newParams[1]);
330 if (IsExpandedParamKnown(newParams[2]))
331 cCc = pRuntime->ToWideString(newParams[2]);
334 if (IsExpandedParamKnown(newParams[3]))
335 cBcc = pRuntime->ToWideString(newParams[3]);
338 if (IsExpandedParamKnown(newParams[4]))
339 cSubject = pRuntime->ToWideString(newParams[4]);
342 if (IsExpandedParamKnown(newParams[5]))
343 cMsg = pRuntime->ToWideString(newParams[5]);
346 m_pFormFillEnv->JS_docmailForm(pdfium::span<
const uint8_t>(), bUI, cTo,
347 cSubject, cCc, cBcc, cMsg);
355CJS_Result CJS_Document::mailForm(CJS_Runtime* pRuntime,
356 pdfium::span<v8::Local<v8::Value>> params) {
361 if (!m_pFormFillEnv->HasPermissions(kExtractForAccessibility))
364 CPDFSDK_InteractiveForm* pInteractiveForm = GetSDKInteractiveForm();
369 v8::LocalVector<v8::Value> newParams = ExpandKeywordParams(
370 pRuntime, params, 6,
"bUI",
"cTo",
"cCc",
"cBcc",
"cSubject",
"cMsg");
373 if (IsExpandedParamKnown(newParams[0]))
374 bUI = pRuntime->ToBoolean(newParams[0]);
377 if (IsExpandedParamKnown(newParams[1]))
378 cTo = pRuntime->ToWideString(newParams[1]);
381 if (IsExpandedParamKnown(newParams[2]))
382 cCc = pRuntime->ToWideString(newParams[2]);
385 if (IsExpandedParamKnown(newParams[3]))
386 cBcc = pRuntime->ToWideString(newParams[3]);
389 if (IsExpandedParamKnown(newParams[4]))
390 cSubject = pRuntime->ToWideString(newParams[4]);
393 if (IsExpandedParamKnown(newParams[5]))
394 cMsg = pRuntime->ToWideString(newParams[5]);
397 m_pFormFillEnv->JS_docmailForm(sTextBuf.raw_span(), bUI, cTo, cSubject, cCc,
403CJS_Result CJS_Document::print(CJS_Runtime* pRuntime,
404 pdfium::span<v8::Local<v8::Value>> params) {
405 v8::LocalVector<v8::Value> newParams = ExpandKeywordParams(
406 pRuntime, params, 8,
"bUI",
"nStart",
"nEnd",
"bSilent",
"bShrinkToFit",
407 "bPrintAsImage",
"bReverse",
"bAnnotations");
410 if (IsExpandedParamKnown(newParams[0]))
411 bUI = pRuntime->ToBoolean(newParams[0]);
414 if (IsExpandedParamKnown(newParams[1]))
415 nStart = pRuntime->ToInt32(newParams[1]);
418 if (IsExpandedParamKnown(newParams[2]))
419 nEnd = pRuntime->ToInt32(newParams[2]);
421 bool bSilent =
false;
422 if (IsExpandedParamKnown(newParams[3]))
423 bSilent = pRuntime->ToBoolean(newParams[3]);
425 bool bShrinkToFit =
false;
426 if (IsExpandedParamKnown(newParams[4]))
427 bShrinkToFit = pRuntime->ToBoolean(newParams[4]);
429 bool bPrintAsImage =
false;
430 if (IsExpandedParamKnown(newParams[5]))
431 bPrintAsImage = pRuntime->ToBoolean(newParams[5]);
433 bool bReverse =
false;
434 if (IsExpandedParamKnown(newParams[6]))
435 bReverse = pRuntime->ToBoolean(newParams[6]);
437 bool bAnnotations =
false;
438 if (IsExpandedParamKnown(newParams[7]))
439 bAnnotations = pRuntime->ToBoolean(newParams[7]);
448 m_pFormFillEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit,
449 bPrintAsImage, bReverse, bAnnotations);
457 CJS_Runtime* pRuntime,
458 pdfium::span<v8::Local<v8::Value>> params) {
459 if (params.size() != 1)
464 if (!m_pFormFillEnv->HasPermissions(
465 pdfium::access_permissions::kModifyContent |
466 pdfium::access_permissions::kModifyAnnotation)) {
470 WideString sFieldName = pRuntime->ToWideString(params[0]);
471 CPDFSDK_InteractiveForm* pInteractiveForm = GetSDKInteractiveForm();
472 std::vector<ObservedPtr<CPDFSDK_Widget>> widgets;
473 pInteractiveForm->GetWidgets(sFieldName, &widgets);
477 for (
const auto& pWidget : widgets) {
481 IPDF_Page* pPage = pWidget->GetPage();
487 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage);
491 CFX_FloatRect rcAnnot = pWidget->GetRect();
492 rcAnnot.Inflate(1.0f, 1.0f, 1.0f, 1.0f);
494 std::vector<CFX_FloatRect> aRefresh(1, rcAnnot);
495 pPageView->UpdateRects(aRefresh);
497 m_pFormFillEnv->SetChangeMark();
505CJS_Result CJS_Document::resetForm(CJS_Runtime* pRuntime,
506 pdfium::span<v8::Local<v8::Value>> params) {
510 if (!m_pFormFillEnv->HasPermissions(
511 pdfium::access_permissions::kModifyContent |
512 pdfium::access_permissions::kModifyAnnotation |
513 pdfium::access_permissions::kFillForm)) {
518 if (params.empty()) {
520 m_pFormFillEnv->SetChangeMark();
524 v8::Local<v8::Array> array;
525 if (params[0]->IsString()) {
526 array = pRuntime->NewArray();
527 pRuntime->PutArrayElement(array, 0, params[0]);
529 array = pRuntime->ToArray(params[0]);
532 std::vector<CPDF_FormField*> aFields;
533 for (size_t i = 0; i < pRuntime->GetArrayLength(array); ++i) {
535 pRuntime->ToWideString(pRuntime->GetArrayElement(array, i));
536 const size_t jsz = pPDFForm->CountFields(swVal);
537 for (size_t j = 0; j < jsz; ++j)
538 aFields.push_back(pPDFForm->GetField(j, swVal));
541 if (!aFields.empty()) {
542 pPDFForm->ResetForm(aFields,
true);
543 m_pFormFillEnv->SetChangeMark();
549CJS_Result CJS_Document::saveAs(CJS_Runtime* pRuntime,
550 pdfium::span<v8::Local<v8::Value>> params) {
556 CJS_Runtime* pRuntime,
557 pdfium::span<v8::Local<v8::Value>> params) {
561CJS_Result CJS_Document::submitForm(CJS_Runtime* pRuntime,
562 pdfium::span<v8::Local<v8::Value>> params) {
563 size_t nSize = params.size();
573 v8::Local<v8::Array> aFields;
577 if (params[0]->IsString()) {
578 strURL = pRuntime->ToWideString(params[0]);
580 bFDF = pRuntime->ToBoolean(params[1]);
582 bEmpty = pRuntime->ToBoolean(params[2]);
584 aFields = pRuntime->ToArray(params[3]);
585 }
else if (params[0]->IsObject()) {
586 v8::Local<v8::Object> pObj = pRuntime->ToObject(params[0]);
587 v8::Local<v8::Value> pValue = pRuntime->GetObjectProperty(pObj,
"cURL");
588 if (!pValue.IsEmpty())
589 strURL = pRuntime->ToWideString(pValue);
591 bFDF = pRuntime->ToBoolean(pRuntime->GetObjectProperty(pObj,
"bFDF"));
592 bEmpty = pRuntime->ToBoolean(pRuntime->GetObjectProperty(pObj,
"bEmpty"));
593 aFields = pRuntime->ToArray(pRuntime->GetObjectProperty(pObj,
"aFields"));
597 if (pRuntime->GetArrayLength(aFields) == 0 && bEmpty) {
598 if (pPDFForm->CheckRequiredFields(
nullptr,
true)) {
606 std::vector<CPDF_FormField*> fieldObjects;
607 for (size_t i = 0; i < pRuntime->GetArrayLength(aFields); ++i) {
609 pRuntime->ToWideString(pRuntime->GetArrayElement(aFields, i));
610 const size_t jsz = pPDFForm->CountFields(sName);
611 for (size_t j = 0; j < jsz; ++j) {
616 fieldObjects.push_back(pField);
620 if (pPDFForm->CheckRequiredFields(&fieldObjects,
true)) {
622 GetSDKInteractiveForm()->SubmitFields(strURL, fieldObjects,
true, !bFDF);
629 m_pFormFillEnv.Reset(pFormFillEnv);
632CJS_Result CJS_Document::get_bookmark_root(CJS_Runtime* pRuntime) {
636CJS_Result CJS_Document::set_bookmark_root(CJS_Runtime* pRuntime,
637 v8::Local<v8::Value> vp) {
641CJS_Result CJS_Document::get_author(CJS_Runtime* pRuntime) {
642 return getPropertyInternal(pRuntime,
"Author");
645CJS_Result CJS_Document::set_author(CJS_Runtime* pRuntime,
646 v8::Local<v8::Value> vp) {
651CJS_Result CJS_Document::get_info(CJS_Runtime* pRuntime) {
655 RetainPtr<
const CPDF_Dictionary> pDictionary =
656 m_pFormFillEnv->GetPDFDocument()->GetInfo();
660 WideString cwAuthor = pDictionary->GetUnicodeTextFor(
"Author");
661 WideString cwTitle = pDictionary->GetUnicodeTextFor(
"Title");
662 WideString cwSubject = pDictionary->GetUnicodeTextFor(
"Subject");
663 WideString cwKeywords = pDictionary->GetUnicodeTextFor(
"Keywords");
664 WideString cwCreator = pDictionary->GetUnicodeTextFor(
"Creator");
665 WideString cwProducer = pDictionary->GetUnicodeTextFor(
"Producer");
666 WideString cwCreationDate = pDictionary->GetUnicodeTextFor(
"CreationDate");
667 WideString cwModDate = pDictionary->GetUnicodeTextFor(
"ModDate");
668 WideString cwTrapped = pDictionary->GetUnicodeTextFor(
"Trapped");
670 v8::Local<v8::Object> pObj = pRuntime->NewObject();
671 pRuntime->PutObjectProperty(pObj,
"Author",
672 pRuntime->NewString(cwAuthor.AsStringView()));
673 pRuntime->PutObjectProperty(pObj,
"Title",
674 pRuntime->NewString(cwTitle.AsStringView()));
675 pRuntime->PutObjectProperty(pObj,
"Subject",
676 pRuntime->NewString(cwSubject.AsStringView()));
677 pRuntime->PutObjectProperty(pObj,
"Keywords",
678 pRuntime->NewString(cwKeywords.AsStringView()));
679 pRuntime->PutObjectProperty(pObj,
"Creator",
680 pRuntime->NewString(cwCreator.AsStringView()));
681 pRuntime->PutObjectProperty(pObj,
"Producer",
682 pRuntime->NewString(cwProducer.AsStringView()));
683 pRuntime->PutObjectProperty(
684 pObj,
"CreationDate", pRuntime->NewString(cwCreationDate.AsStringView()));
685 pRuntime->PutObjectProperty(pObj,
"ModDate",
686 pRuntime->NewString(cwModDate.AsStringView()));
687 pRuntime->PutObjectProperty(pObj,
"Trapped",
688 pRuntime->NewString(cwTrapped.AsStringView()));
692 for (
const auto& it : locker) {
693 const ByteString& bsKey = it.first;
694 const RetainPtr<CPDF_Object>& pValueObj = it.second;
695 if (pValueObj->IsString() || pValueObj->IsName()) {
696 pRuntime->PutObjectProperty(
697 pObj, bsKey.AsStringView(),
698 pRuntime->NewString(pValueObj->GetUnicodeText().AsStringView()));
699 }
else if (pValueObj->IsNumber()) {
700 pRuntime->PutObjectProperty(pObj, bsKey.AsStringView(),
701 pRuntime->NewNumber(pValueObj->GetNumber()));
702 }
else if (pValueObj->IsBoolean()) {
703 pRuntime->PutObjectProperty(
704 pObj, bsKey.AsStringView(),
705 pRuntime->NewBoolean(!!pValueObj->GetInteger()));
708 return CJS_Result::Success(pObj);
711CJS_Result CJS_Document::set_info(CJS_Runtime* pRuntime,
712 v8::Local<v8::Value> vp) {
716CJS_Result CJS_Document::getPropertyInternal(CJS_Runtime* pRuntime,
717 const ByteString& propName) {
722 m_pFormFillEnv->GetPDFDocument()->GetInfo();
727 pDictionary->GetUnicodeTextFor(propName).AsStringView())
);
730CJS_Result CJS_Document::get_creation_date(CJS_Runtime* pRuntime) {
731 return getPropertyInternal(pRuntime,
"CreationDate");
734CJS_Result CJS_Document::set_creation_date(CJS_Runtime* pRuntime,
735 v8::Local<v8::Value> vp) {
740CJS_Result CJS_Document::get_creator(CJS_Runtime* pRuntime) {
741 return getPropertyInternal(pRuntime,
"Creator");
744CJS_Result CJS_Document::set_creator(CJS_Runtime* pRuntime,
745 v8::Local<v8::Value> vp) {
750CJS_Result CJS_Document::get_delay(CJS_Runtime* pRuntime) {
756CJS_Result CJS_Document::set_delay(CJS_Runtime* pRuntime,
757 v8::Local<v8::Value> vp) {
762 if (!m_pFormFillEnv->HasPermissions(kModifyContent))
765 m_bDelay = pRuntime->ToBoolean(vp);
771 std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess;
772 DelayDataToProcess.swap(m_DelayData);
773 for (
const auto& pData : DelayDataToProcess)
774 CJS_Field::DoDelay(m_pFormFillEnv.Get(), pData.get());
779CJS_Result CJS_Document::get_keywords(CJS_Runtime* pRuntime) {
780 return getPropertyInternal(pRuntime,
"Keywords");
783CJS_Result CJS_Document::set_keywords(CJS_Runtime* pRuntime,
784 v8::Local<v8::Value> vp) {
789CJS_Result CJS_Document::get_mod_date(CJS_Runtime* pRuntime) {
790 return getPropertyInternal(pRuntime,
"ModDate");
793CJS_Result CJS_Document::set_mod_date(CJS_Runtime* pRuntime,
794 v8::Local<v8::Value> vp) {
799CJS_Result CJS_Document::get_producer(CJS_Runtime* pRuntime) {
800 return getPropertyInternal(pRuntime,
"Producer");
803CJS_Result CJS_Document::set_producer(CJS_Runtime* pRuntime,
804 v8::Local<v8::Value> vp) {
809CJS_Result CJS_Document::get_subject(CJS_Runtime* pRuntime) {
810 return getPropertyInternal(pRuntime,
"Subject");
813CJS_Result CJS_Document::set_subject(CJS_Runtime* pRuntime,
814 v8::Local<v8::Value> vp) {
819CJS_Result CJS_Document::get_title(CJS_Runtime* pRuntime) {
822 return getPropertyInternal(pRuntime,
"Title");
825CJS_Result CJS_Document::set_title(CJS_Runtime* pRuntime,
826 v8::Local<v8::Value> vp) {
831CJS_Result CJS_Document::get_num_pages(CJS_Runtime* pRuntime) {
834 return CJS_Result::Success(
835 pRuntime->NewNumber(m_pFormFillEnv->GetPageCount()));
838CJS_Result CJS_Document::set_num_pages(CJS_Runtime* pRuntime,
839 v8::Local<v8::Value> vp) {
843CJS_Result CJS_Document::get_external(CJS_Runtime* pRuntime) {
848CJS_Result CJS_Document::set_external(CJS_Runtime* pRuntime,
849 v8::Local<v8::Value> vp) {
853CJS_Result CJS_Document::get_filesize(CJS_Runtime* pRuntime) {
857CJS_Result CJS_Document::set_filesize(CJS_Runtime* pRuntime,
858 v8::Local<v8::Value> vp) {
862CJS_Result CJS_Document::get_mouse_x(CJS_Runtime* pRuntime) {
866CJS_Result CJS_Document::set_mouse_x(CJS_Runtime* pRuntime,
867 v8::Local<v8::Value> vp) {
871CJS_Result CJS_Document::get_mouse_y(CJS_Runtime* pRuntime) {
875CJS_Result CJS_Document::set_mouse_y(CJS_Runtime* pRuntime,
876 v8::Local<v8::Value> vp) {
880CJS_Result CJS_Document::get_URL(CJS_Runtime* pRuntime) {
883 return CJS_Result::Success(
884 pRuntime->NewString(m_pFormFillEnv->JS_docGetFilePath().AsStringView()));
887CJS_Result CJS_Document::set_URL(CJS_Runtime* pRuntime,
888 v8::Local<v8::Value> vp) {
892CJS_Result CJS_Document::get_base_URL(CJS_Runtime* pRuntime) {
893 return CJS_Result::Success(pRuntime->NewString(m_cwBaseURL.AsStringView()));
896CJS_Result CJS_Document::set_base_URL(CJS_Runtime* pRuntime,
897 v8::Local<v8::Value> vp) {
898 m_cwBaseURL = pRuntime->ToWideString(vp);
902CJS_Result CJS_Document::get_calculate(CJS_Runtime* pRuntime) {
906 CPDFSDK_InteractiveForm* pInteractiveForm = GetSDKInteractiveForm();
911CJS_Result CJS_Document::set_calculate(CJS_Runtime* pRuntime,
912 v8::Local<v8::Value> vp) {
916 CPDFSDK_InteractiveForm* pInteractiveForm = GetSDKInteractiveForm();
921CJS_Result CJS_Document::get_document_file_name(CJS_Runtime* pRuntime) {
925 WideString wsFilePath = m_pFormFillEnv->JS_docGetFilePath();
926 size_t i = wsFilePath.GetLength();
928 if (wsFilePath[i - 1] == L'\\' || wsFilePath[i - 1] == L'/')
931 if (i > 0 && i < wsFilePath.GetLength()) {
933 pRuntime->NewString(wsFilePath.AsStringView().Substr(i))
);
938CJS_Result CJS_Document::set_document_file_name(CJS_Runtime* pRuntime,
939 v8::Local<v8::Value> vp) {
943CJS_Result CJS_Document::get_path(CJS_Runtime* pRuntime) {
946 return CJS_Result::Success(pRuntime->NewString(
947 CJS_App::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath())
951CJS_Result CJS_Document::set_path(CJS_Runtime* pRuntime,
952 v8::Local<v8::Value> vp) {
956CJS_Result CJS_Document::get_page_window_rect(CJS_Runtime* pRuntime) {
960CJS_Result CJS_Document::set_page_window_rect(CJS_Runtime* pRuntime,
961 v8::Local<v8::Value> vp) {
965CJS_Result CJS_Document::get_layout(CJS_Runtime* pRuntime) {
969CJS_Result CJS_Document::set_layout(CJS_Runtime* pRuntime,
970 v8::Local<v8::Value> vp) {
974CJS_Result CJS_Document::addLink(CJS_Runtime* pRuntime,
975 pdfium::span<v8::Local<v8::Value>> params) {
979CJS_Result CJS_Document::closeDoc(CJS_Runtime* pRuntime,
980 pdfium::span<v8::Local<v8::Value>> params) {
984CJS_Result CJS_Document::getPageBox(CJS_Runtime* pRuntime,
985 pdfium::span<v8::Local<v8::Value>> params) {
989CJS_Result CJS_Document::getAnnot(CJS_Runtime* pRuntime,
990 pdfium::span<v8::Local<v8::Value>> params) {
991 if (params.size() != 2)
996 int nPageNo = pRuntime->ToInt32(params[0]);
997 WideString swAnnotName = pRuntime->ToWideString(params[1]);
998 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageViewAtIndex(nPageNo);
1004 for (
const auto& pSDKAnnotCur : annot_iteration) {
1005 auto* pBAAnnot = pSDKAnnotCur->AsBAAnnot();
1006 if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) {
1007 pSDKBAAnnot = pBAAnnot;
1014 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
1015 CJS_Annot::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
1019 auto* pJS_Annot =
static_cast<CJS_Annot*>(
1020 CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
1024 pJS_Annot->SetSDKAnnot(pSDKBAAnnot);
1028CJS_Result CJS_Document::getAnnots(CJS_Runtime* pRuntime,
1029 pdfium::span<v8::Local<v8::Value>> params) {
1030 if (!m_pFormFillEnv)
1036 int nPageNo = m_pFormFillEnv->GetPageCount();
1037 v8::Local<v8::Array> annots = pRuntime->NewArray();
1038 for (
int i = 0; i < nPageNo; ++i) {
1039 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageViewAtIndex(i);
1044 for (
const auto& pSDKAnnotCur : annot_iteration) {
1046 return CJS_Result::Failure(JSMessage::kBadObjectError);
1048 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
1049 CJS_Annot::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
1051 return CJS_Result::Failure(JSMessage::kBadObjectError);
1053 auto* pJS_Annot =
static_cast<CJS_Annot*>(
1054 CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
1055 pJS_Annot->SetSDKAnnot(pSDKAnnotCur->AsBAAnnot());
1056 pRuntime->PutArrayElement(
1058 pJS_Annot ? v8::Local<v8::Value>(pJS_Annot->ToV8Object())
1059 : v8::Local<v8::Value>());
1062 return CJS_Result::Success(annots);
1065CJS_Result CJS_Document::getAnnot3D(CJS_Runtime* pRuntime,
1066 pdfium::span<v8::Local<v8::Value>> params) {
1071 CJS_Runtime* pRuntime,
1072 pdfium::span<v8::Local<v8::Value>> params) {
1076CJS_Result CJS_Document::getOCGs(CJS_Runtime* pRuntime,
1077 pdfium::span<v8::Local<v8::Value>> params) {
1081CJS_Result CJS_Document::getLinks(CJS_Runtime* pRuntime,
1082 pdfium::span<v8::Local<v8::Value>> params) {
1086CJS_Result CJS_Document::addIcon(CJS_Runtime* pRuntime,
1087 pdfium::span<v8::Local<v8::Value>> params) {
1088 if (params.size() != 2)
1091 if (!params[1]->IsObject())
1094 v8::Local<v8::Object> pObj = pRuntime->ToObject(params[1]);
1095 if (!JSGetObject<CJS_Icon>(pRuntime->GetIsolate(), pObj))
1098 WideString swIconName = pRuntime->ToWideString(params[0]);
1099 m_IconNames.push_back(swIconName);
1103CJS_Result CJS_Document::get_icons(CJS_Runtime* pRuntime) {
1106 if (m_IconNames.empty())
1109 v8::Local<v8::Array> Icons = pRuntime->NewArray();
1111 for (
const auto& name : m_IconNames) {
1112 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
1113 CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
1115 return CJS_Result::Failure(JSMessage::kBadObjectError);
1117 auto* pJS_Icon =
static_cast<CJS_Icon*>(
1118 CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
1119 pJS_Icon->SetIconName(name);
1120 pRuntime->PutArrayElement(Icons, i++,
1122 ? v8::Local<v8::Value>(pJS_Icon->ToV8Object())
1123 : v8::Local<v8::Value>());
1125 return CJS_Result::Success(Icons);
1128CJS_Result CJS_Document::set_icons(CJS_Runtime* pRuntime,
1129 v8::Local<v8::Value> vp) {
1133CJS_Result CJS_Document::getIcon(CJS_Runtime* pRuntime,
1134 pdfium::span<v8::Local<v8::Value>> params) {
1135 if (params.size() != 1)
1138 WideString swIconName = pRuntime->ToWideString(params[0]);
1139 auto it = std::find(m_IconNames.begin(), m_IconNames.end(), swIconName);
1140 if (it == m_IconNames.end())
1143 v8::Local<v8::Object> pObj = pRuntime->NewFXJSBoundObject(
1144 CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
1148 auto* pJSIcon =
static_cast<CJS_Icon*>(
1149 CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
1153 pJSIcon->SetIconName(*it);
1157CJS_Result CJS_Document::removeIcon(CJS_Runtime* pRuntime,
1158 pdfium::span<v8::Local<v8::Value>> params) {
1164 CJS_Runtime* pRuntime,
1165 pdfium::span<v8::Local<v8::Value>> params) {
1170CJS_Result CJS_Document::get_media(CJS_Runtime* pRuntime) {
1174CJS_Result CJS_Document::set_media(CJS_Runtime* pRuntime,
1175 v8::Local<v8::Value> vp) {
1180 CJS_Runtime* pRuntime,
1181 pdfium::span<v8::Local<v8::Value>> params) {
1182 if (!m_pFormFillEnv)
1185 if (!m_pFormFillEnv->HasPermissions(
1186 pdfium::access_permissions::kModifyContent |
1187 pdfium::access_permissions::kModifyAnnotation |
1188 pdfium::access_permissions::kFillForm)) {
1196CJS_Result CJS_Document::get_collab(CJS_Runtime* pRuntime) {
1200CJS_Result CJS_Document::set_collab(CJS_Runtime* pRuntime,
1201 v8::Local<v8::Value> vp) {
1206 CJS_Runtime* pRuntime,
1207 pdfium::span<v8::Local<v8::Value>> params) {
1208 if (!m_pFormFillEnv)
1212 if (!m_pFormFillEnv->HasPermissions(kExtractForAccessibility))
1217 int nPageNo = params.size() > 0 ? pRuntime->ToInt32(params[0]) : 0;
1218 int nWordNo = params.size() > 1 ? pRuntime->ToInt32(params[1]) : 0;
1219 bool bStrip = params.size() > 2 ? pRuntime->ToBoolean(params[2]) :
true;
1221 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument();
1226 pDocument->GetMutablePageDictionary(nPageNo);
1230 auto page = pdfium::MakeRetain<CPDF_Page>(pDocument,
std::move(pPageDict));
1231 page->AddPageImageCache();
1232 page->ParseContent();
1236 for (
auto& pPageObj : *page) {
1237 if (pPageObj->IsText()) {
1238 CPDF_TextObject* pTextObj = pPageObj->AsText();
1239 int nObjWords = pTextObj->CountWords();
1240 if (nWords + nObjWords >= nWordNo) {
1241 swRet = pTextObj->GetWordString(nWordNo - nWords);
1244 nWords += nObjWords;
1254 CJS_Runtime* pRuntime,
1255 pdfium::span<v8::Local<v8::Value>> params) {
1256 if (!m_pFormFillEnv)
1260 if (!m_pFormFillEnv->HasPermissions(kExtractForAccessibility))
1267 CJS_Runtime* pRuntime,
1268 pdfium::span<v8::Local<v8::Value>> params) {
1269 if (!m_pFormFillEnv)
1273 if (!m_pFormFillEnv->HasPermissions(kExtractForAccessibility))
1276 int nPageNo = params.size() > 0 ? pRuntime->ToInt32(params[0]) : 0;
1277 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument();
1282 pDocument->GetMutablePageDictionary(nPageNo);
1286 auto page = pdfium::MakeRetain<CPDF_Page>(pDocument,
std::move(pPageDict));
1287 page->AddPageImageCache();
1288 page->ParseContent();
1291 for (
auto& pPageObj : *page) {
1292 if (pPageObj->IsText())
1293 nWords += pPageObj->AsText()->CountWords();
1299 CJS_Runtime* pRuntime,
1300 pdfium::span<v8::Local<v8::Value>> params) {
1304CJS_Result CJS_Document::get_zoom(CJS_Runtime* pRuntime) {
1308CJS_Result CJS_Document::set_zoom(CJS_Runtime* pRuntime,
1309 v8::Local<v8::Value> vp) {
1313CJS_Result CJS_Document::get_zoom_type(CJS_Runtime* pRuntime) {
1317CJS_Result CJS_Document::set_zoom_type(CJS_Runtime* pRuntime,
1318 v8::Local<v8::Value> vp) {
1323 CJS_Runtime* pRuntime,
1324 pdfium::span<v8::Local<v8::Value>> params) {
1330 CJS_Runtime* pRuntime,
1331 pdfium::span<v8::Local<v8::Value>> params) {
1337 CJS_Runtime* pRuntime,
1338 pdfium::span<v8::Local<v8::Value>> params) {
1344 CJS_Runtime* pRuntime,
1345 pdfium::span<v8::Local<v8::Value>> params) {
1350CJS_Result CJS_Document::getURL(CJS_Runtime* pRuntime,
1351 pdfium::span<v8::Local<v8::Value>> params) {
1357 CJS_Runtime* pRuntime,
1358 pdfium::span<v8::Local<v8::Value>> params) {
1359 if (params.size() != 1)
1362 if (!m_pFormFillEnv)
1365 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument();
1366 RetainPtr<
const CPDF_Array> dest_array = CPDF_NameTree::LookupNamedDest(
1367 pDocument, pRuntime->ToByteString(params[0]));
1372 std::vector<
float> positions = dest.GetScrollPositionArray();
1374 m_pFormFillEnv->DoGoToAction(dest.GetDestPageIndex(pDocument),
1375 dest.GetZoomMode(), positions);
1381 m_DelayData.push_back(std::move(pData));
1385 int nControlIndex) {
1386 std::vector<std::unique_ptr<CJS_DelayData>> delayed_data;
1387 auto iter = m_DelayData.begin();
1388 while (iter != m_DelayData.end()) {
1390 if ((*old)->sFieldName == sFieldName &&
1391 (*old)->nControlIndex == nControlIndex) {
1392 delayed_data.push_back(
std::move(*old));
1393 m_DelayData.erase(old);
1397 for (
const auto& pData : delayed_data)
1398 CJS_Field::DoDelay(m_pFormFillEnv.Get(), pData.get());
1405CPDFSDK_InteractiveForm* CJS_Document::GetSDKInteractiveForm() {
1406 return m_pFormFillEnv->GetInteractiveForm();
void DoFieldDelay(const WideString &sFieldName, int nControlIndex)
CJS_Document(v8::Local< v8::Object > pObject, CJS_Runtime *pRuntime)
void SetFormFillEnv(CPDFSDK_FormFillEnvironment *pFormFillEnv)
void AddDelayData(std::unique_ptr< CJS_DelayData > pData)
static uint32_t GetObjDefnID()
static void DefineJSObjects(CFXJS_Engine *pEngine)
bool IsUserGesture() const
static void DefineProps(CFXJS_Engine *pEngine, uint32_t nObjDefnID, pdfium::span< const JSPropertySpec > consts)
CJS_Runtime * GetRuntime() const
static void DefineMethods(CFXJS_Engine *pEngine, uint32_t nObjDefnID, pdfium::span< const JSMethodSpec > consts)
static CJS_Result Success()
static CJS_Result Failure(JSMessage id)
static CJS_Result Failure(const WideString &str)
CJS_EventContext * GetCurrentEventContext() const
CPDFSDK_AnnotIteration(CPDFSDK_PageView *page_view)
@ kUserGestureRequiredError