Inflict PDF_ENABLE_XFA ifdefs on XFA fpdfsdk/

R=thestig@chromium.org

Review URL: https://codereview.chromium.org/1477583002 .
diff --git a/fpdfsdk/include/formfiller/FFL_ComboBox.h b/fpdfsdk/include/formfiller/FFL_ComboBox.h
index ce244d8..f8f5c3c 100644
--- a/fpdfsdk/include/formfiller/FFL_ComboBox.h
+++ b/fpdfsdk/include/formfiller/FFL_ComboBox.h
@@ -55,9 +55,11 @@
   // IPWL_Edit_Notify:
   void OnAddUndo(CPWL_Edit* pEdit) override;
 
+#ifdef PDF_ENABLE_XFA
   // CFFL_FormFiller:
   FX_BOOL IsFieldFull(CPDFSDK_PageView* pPageView) override;
 
+#endif
  private:
   CFX_WideString GetSelectExportText();
 
diff --git a/fpdfsdk/include/formfiller/FFL_FormFiller.h b/fpdfsdk/include/formfiller/FFL_FormFiller.h
index 5cfa2b6..83b9902 100644
--- a/fpdfsdk/include/formfiller/FFL_FormFiller.h
+++ b/fpdfsdk/include/formfiller/FFL_FormFiller.h
@@ -120,8 +120,10 @@
   virtual FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView);
   virtual void SaveData(CPDFSDK_PageView* pPageView);
 
+#ifdef PDF_ENABLE_XFA
   virtual FX_BOOL IsFieldFull(CPDFSDK_PageView* pPageView);
 
+#endif
   CPWL_Wnd* GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew);
   void DestroyPDFWindow(CPDFSDK_PageView* pPageView);
   void EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow);
diff --git a/fpdfsdk/include/formfiller/FFL_IFormFiller.h b/fpdfsdk/include/formfiller/FFL_IFormFiller.h
index 79a8964..bfdce10 100644
--- a/fpdfsdk/include/formfiller/FFL_IFormFiller.h
+++ b/fpdfsdk/include/formfiller/FFL_IFormFiller.h
@@ -112,6 +112,7 @@
                   FX_BOOL& bReset,
                   FX_BOOL& bExit,
                   FX_UINT nFlag);
+#ifdef PDF_ENABLE_XFA
   void OnClick(CPDFSDK_Widget* pWidget,
                CPDFSDK_PageView* pPageView,
                FX_BOOL& bReset,
@@ -132,6 +133,7 @@
                   FX_BOOL& bReset,
                   FX_BOOL& bExit,
                   FX_UINT nFlag);
+#endif
 
  private:
   using CFFL_Widget2Filler = std::map<CPDFSDK_Annot*, CFFL_FormFiller*>;
@@ -151,17 +153,21 @@
                          FX_BOOL& bRC,
                          FX_BOOL& bExit,
                          FX_DWORD nFlag) override;
+#ifdef PDF_ENABLE_XFA
   void OnPopupPreOpen(void* pPrivateData,
                       FX_BOOL& bExit,
                       FX_DWORD nFlag) override;
   void OnPopupPostOpen(void* pPrivateData,
                        FX_BOOL& bExit,
                        FX_DWORD nFlag) override;
+#endif
 
   void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot);
+#ifdef PDF_ENABLE_XFA
   void SetFocusAnnotTab(CPDFSDK_Annot* pWidget,
                         FX_BOOL bSameField,
                         FX_BOOL bNext);
+#endif
 
   CPDFDoc_Environment* m_pApp;
   CFFL_Widget2Filler m_Maps;
diff --git a/fpdfsdk/include/formfiller/FFL_TextField.h b/fpdfsdk/include/formfiller/FFL_TextField.h
index 49a0f24..a6065fe 100644
--- a/fpdfsdk/include/formfiller/FFL_TextField.h
+++ b/fpdfsdk/include/formfiller/FFL_TextField.h
@@ -56,9 +56,11 @@
   // IPWL_Edit_Notify:
   void OnAddUndo(CPWL_Edit* pEdit) override;
 
+#ifdef PDF_ENABLE_XFA
   // CFFL_FormFiller:
   FX_BOOL IsFieldFull(CPDFSDK_PageView* pPageView) override;
 
+#endif
  private:
   CBA_FontMap* m_pFontMap;
   FFL_TextFieldState m_State;
diff --git a/fpdfsdk/include/fsdk_annothandler.h b/fpdfsdk/include/fsdk_annothandler.h
index 19051ee..d43bc7b 100644
--- a/fpdfsdk/include/fsdk_annothandler.h
+++ b/fpdfsdk/include/fsdk_annothandler.h
@@ -12,8 +12,10 @@
 
 #include "core/include/fxcrt/fx_basic.h"
 
+#ifdef PDF_ENABLE_XFA
 #define FSDK_XFAWIDGET_TYPENAME "XFAWidget"
 
+#endif
 class CFFL_IFormFiller;
 class CFX_RenderDevice;
 class CPDFDoc_Environment;
@@ -37,9 +39,11 @@
   virtual CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot,
                                   CPDFSDK_PageView* pPage) = 0;
 
+#ifdef PDF_ENABLE_XFA
   virtual CPDFSDK_Annot* NewAnnot(IXFA_Widget* hWidget,
                                   CPDFSDK_PageView* pPage) = 0;
 
+#endif
   virtual void ReleaseAnnot(CPDFSDK_Annot* pAnnot) = 0;
 
   virtual void DeleteAnnot(CPDFSDK_Annot* pAnnot) = 0;
@@ -124,8 +128,10 @@
 
   virtual FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;
   virtual FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) = 0;
+#ifdef PDF_ENABLE_XFA
   virtual FX_BOOL OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
                                     CPDFSDK_Annot* pNewAnnot) = 0;
+#endif
 };
 
 class CPDFSDK_BFAnnotHandler : public IPDFSDK_AnnotHandler {
@@ -139,8 +145,10 @@
   CFX_ByteString GetName() override { return CFX_ByteString("WidgetHandler"); }
   FX_BOOL CanAnswer(CPDFSDK_Annot* pAnnot) override;
   CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) override;
+#ifdef PDF_ENABLE_XFA
   CPDFSDK_Annot* NewAnnot(IXFA_Widget* hWidget,
                           CPDFSDK_PageView* pPage) override;
+#endif
   void ReleaseAnnot(CPDFSDK_Annot* pAnnot) override;
   void DeleteAnnot(CPDFSDK_Annot* pAnnot) override {}
   CPDF_Rect GetViewBBox(CPDFSDK_PageView* pPageView,
@@ -213,10 +221,12 @@
   void OnSelected(CPDFSDK_Annot* pAnnot) override {}
   FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) override;
   FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) override;
+#ifdef PDF_ENABLE_XFA
   FX_BOOL OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot,
                             CPDFSDK_Annot* pNewAnnot) override {
     return TRUE;
   }
+#endif
 
   void SetFormFiller(CFFL_IFormFiller* pFiller) { m_pFormFiller = pFiller; }
   CFFL_IFormFiller* GetFormFiller() { return m_pFormFiller; }
@@ -226,6 +236,7 @@
   CFFL_IFormFiller* m_pFormFiller;
 };
 
+#ifdef PDF_ENABLE_XFA
 class CPDFSDK_XFAAnnotHandler : public IPDFSDK_AnnotHandler {
  public:
   explicit CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp);
@@ -339,6 +350,7 @@
   CPDFDoc_Environment* m_pApp;
 };
 
+#endif
 #define CBA_AnnotHandlerArray CFX_ArrayTemplate<IPDFSDK_AnnotHandler*>
 class CPDFSDK_AnnotHandlerMgr {
  public:
@@ -352,8 +364,10 @@
 
   virtual CPDFSDK_Annot* NewAnnot(CPDF_Annot* pAnnot,
                                   CPDFSDK_PageView* pPageView);
+#ifdef PDF_ENABLE_XFA
   virtual CPDFSDK_Annot* NewAnnot(IXFA_Widget* pAnnot,
                                   CPDFSDK_PageView* pPageView);
+#endif
   virtual void ReleaseAnnot(CPDFSDK_Annot* pAnnot);
 
   virtual void Annot_OnCreate(CPDFSDK_Annot* pAnnot);
@@ -415,8 +429,10 @@
 
   virtual FX_BOOL Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
   virtual FX_BOOL Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag);
+#ifdef PDF_ENABLE_XFA
   virtual FX_BOOL Annot_OnChangeFocus(CPDFSDK_Annot* pSetAnnot,
                                       CPDFSDK_Annot* pKillAnnot);
+#endif
 
   virtual CPDF_Rect Annot_OnGetViewBBox(CPDFSDK_PageView* pPageView,
                                         CPDFSDK_Annot* pAnnot);
diff --git a/fpdfsdk/include/fsdk_baseannot.h b/fpdfsdk/include/fsdk_baseannot.h
index 441036a..ce65383 100644
--- a/fpdfsdk/include/fsdk_baseannot.h
+++ b/fpdfsdk/include/fsdk_baseannot.h
@@ -16,7 +16,11 @@
 #include "core/include/fpdfdoc/fpdf_doc.h"
 #include "core/include/fxcrt/fx_basic.h"
 #include "fpdfsdk/include/fsdk_define.h"
+#ifndef PDF_ENABLE_XFA
+#include "fx_systemhandler.h"
+#else
 #include "fpdfsdk/include/fx_systemhandler.h"
+#endif
 
 class CPDFSDK_PageView;
 class CPDF_Annot;
@@ -72,15 +76,19 @@
   explicit CPDFSDK_Annot(CPDFSDK_PageView* pPageView);
   virtual ~CPDFSDK_Annot() {}
 
+#ifdef PDF_ENABLE_XFA
   virtual FX_BOOL IsXFAField() { return FALSE; }
 
+#endif
   virtual FX_FLOAT GetMinWidth() const;
   virtual FX_FLOAT GetMinHeight() const;
   // define layout order to 5.
   virtual int GetLayoutOrder() const { return 5; }
 
   virtual CPDF_Annot* GetPDFAnnot() const { return nullptr; }
+#ifdef PDF_ENABLE_XFA
   virtual IXFA_Widget* GetXFAWidget() const { return nullptr; }
+#endif
 
   virtual CFX_ByteString GetType() const { return ""; }
   virtual CFX_ByteString GetSubType() const { return ""; }
@@ -94,7 +102,9 @@
 
   UnderlyingPageType* GetUnderlyingPage();
   CPDF_Page* GetPDFPage();
+#ifdef PDF_ENABLE_XFA
   CPDFXFA_Page* GetPDFXFAPage();
+#endif
 
   void SetPage(CPDFSDK_PageView* pPageView) { m_pPageView = pPageView; }
   CPDFSDK_PageView* GetPageView() const { return m_pPageView; }
@@ -118,7 +128,9 @@
   CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView);
   ~CPDFSDK_BAAnnot() override {}
 
+#ifdef PDF_ENABLE_XFA
   FX_BOOL IsXFAField() override;
+#endif
   CFX_ByteString GetType() const override;
   CFX_ByteString GetSubType() const override;
   void SetRect(const CPDF_Rect& rect) override;
diff --git a/fpdfsdk/include/fsdk_baseform.h b/fpdfsdk/include/fsdk_baseform.h
index e648558..0b6a04e 100644
--- a/fpdfsdk/include/fsdk_baseform.h
+++ b/fpdfsdk/include/fsdk_baseform.h
@@ -31,6 +31,7 @@
 class CPDF_FormField;
 struct CPWL_Color;
 
+#ifdef PDF_ENABLE_XFA
 typedef enum _PDFSDK_XFAAActionType {
   PDFSDK_XFA_Click = 0,
   PDFSDK_XFA_Full,
@@ -38,6 +39,7 @@
   PDFSDK_XFA_PostOpen
 } PDFSDK_XFAAActionType;
 
+#endif
 typedef struct _PDFSDK_FieldAction {
   _PDFSDK_FieldAction() {
     bModifier = FALSE;
@@ -66,6 +68,7 @@
 
 class CPDFSDK_Widget : public CPDFSDK_BAAnnot {
  public:
+#ifdef PDF_ENABLE_XFA
   IXFA_Widget* GetMixXFAWidget() const;
   IXFA_Widget* GetGroupMixXFAWidget();
   IXFA_WidgetHandler* GetXFAWidgetHandler() const;
@@ -88,6 +91,7 @@
                                   CPDF_FormField* pFormField,
                                   CPDF_FormControl* pFormControl);
 
+#endif
   CPDFSDK_Widget(CPDF_Annot* pAnnot,
                  CPDFSDK_PageView* pPageView,
                  CPDFSDK_InterForm* pInterForm);
@@ -115,7 +119,11 @@
   FX_FLOAT GetFontSize() const;
 
   int GetSelectedIndex(int nIndex) const;
+#ifndef PDF_ENABLE_XFA
+  CFX_WideString GetValue() const;
+#else
   CFX_WideString GetValue(FX_BOOL bDisplay = TRUE) const;
+#endif
   CFX_WideString GetDefaultValue() const;
   CFX_WideString GetOptionLabel(int nIndex) const;
   int CountOptions() const;
@@ -129,7 +137,9 @@
   */
   int GetAlignment() const;
   int GetMaxLen() const;
+#ifdef PDF_ENABLE_XFA
   CFX_WideString GetName() const;
+#endif
   CFX_WideString GetAlternateName() const;
 
   // Set Properties.
@@ -140,7 +150,9 @@
   void ClearSelection(FX_BOOL bNotify);
   void SetTopVisibleIndex(int index);
 
+#ifdef PDF_ENABLE_XFA
   void ResetAppearance(FX_BOOL bValueChanged);
+#endif
   void ResetAppearance(const FX_WCHAR* sValue, FX_BOOL bValueChanged);
   void ResetFieldAppearance(FX_BOOL bValueChanged);
   void UpdateField();
@@ -197,15 +209,21 @@
 
   FX_BOOL HitTest(FX_FLOAT pageX, FX_FLOAT pageY);
 
+#ifndef PDF_ENABLE_XFA
+ private:
+#endif
   CPDFSDK_InterForm* m_pInterForm;
   FX_BOOL m_bAppModified;
   int32_t m_nAppAge;
   int32_t m_nValueAge;
+#ifdef PDF_ENABLE_XFA
 
   mutable IXFA_Widget* m_hMixXFAWidget;
   mutable IXFA_WidgetHandler* m_pWidgetHandler;
+#endif
 };
 
+#ifdef PDF_ENABLE_XFA
 class CPDFSDK_XFAWidget : public CPDFSDK_Annot {
  public:
   CPDFSDK_XFAWidget(IXFA_Widget* pAnnot,
@@ -230,6 +248,7 @@
   CFX_MapPtrTemplate<IXFA_Widget*, CPDFSDK_XFAWidget*>
 #define CPDFSDK_FieldSynchronizeMap CFX_MapPtrTemplate<CPDF_FormField*, int>
 
+#endif
 class CPDFSDK_InterForm : public CPDF_FormNotify {
  public:
   explicit CPDFSDK_InterForm(CPDFSDK_Document* pDocument);
@@ -250,19 +269,23 @@
   void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget);
   void RemoveMap(CPDF_FormControl* pControl);
 
+#ifdef PDF_ENABLE_XFA
   void AddXFAMap(IXFA_Widget* hWidget, CPDFSDK_XFAWidget* pWidget);
   void RemoveXFAMap(IXFA_Widget* hWidget);
   CPDFSDK_XFAWidget* GetXFAWidget(IXFA_Widget* hWidget);
 
+#endif
   void EnableCalculate(FX_BOOL bEnabled);
   FX_BOOL IsCalculateEnabled() const;
 
+#ifdef PDF_ENABLE_XFA
   void XfaEnableCalculate(FX_BOOL bEnabled);
   FX_BOOL IsXfaCalculateEnabled() const;
 
   FX_BOOL IsXfaValidationsEnabled();
   void XfaSetValidationsEnabled(FX_BOOL bEnabled);
 
+#endif
 #ifdef _WIN32
   CPDF_Stream* LoadImageFromFile(const CFX_WideString& sFile);
 #endif
@@ -300,8 +323,10 @@
                                    CFX_ByteTextBuf& textBuf);
   CFX_WideString GetTemporaryFileName(const CFX_WideString& sFileExt);
 
+#ifdef PDF_ENABLE_XFA
   void SynchronizeField(CPDF_FormField* pFormField, FX_BOOL bSynchronizeElse);
 
+#endif
  private:
   // CPDF_FormNotify
   int BeforeValueChange(const CPDF_FormField* pField,
@@ -328,11 +353,15 @@
   CPDFSDK_Document* m_pDocument;
   CPDF_InterForm* m_pInterForm;
   CPDFSDK_WidgetMap m_Map;
+#ifdef PDF_ENABLE_XFA
   CPDFSDK_XFAWidgetMap m_XFAMap;
   CPDFSDK_FieldSynchronizeMap m_FieldSynchronizeMap;
+#endif
   FX_BOOL m_bCalculate;
+#ifdef PDF_ENABLE_XFA
   FX_BOOL m_bXfaCalculate;
   FX_BOOL m_bXfaValidationsEnabled;
+#endif
   FX_BOOL m_bBusy;
 
  public:
@@ -344,7 +373,11 @@
   FX_COLORREF GetHighlightColor(int nFieldType);
 
  private:
+#ifndef PDF_ENABLE_XFA
+  static const int kNumFieldTypes = 6;
+#else
   static const int kNumFieldTypes = 7;
+#endif
   FX_COLORREF m_aHighlightColor[kNumFieldTypes];
   uint8_t m_iHighlightAlpha;
   FX_BOOL m_bNeedHightlight[kNumFieldTypes];
diff --git a/fpdfsdk/include/fsdk_define.h b/fpdfsdk/include/fsdk_define.h
index 89c8f6c..4dfe5c2 100644
--- a/fpdfsdk/include/fsdk_define.h
+++ b/fpdfsdk/include/fsdk_define.h
@@ -7,23 +7,31 @@
 #ifndef FPDFSDK_INCLUDE_FSDK_DEFINE_H_
 #define FPDFSDK_INCLUDE_FSDK_DEFINE_H_
 
+#ifndef PDF_ENABLE_XFA
+#include "core/include/fpdfapi/fpdfapi.h"
+#else
 #include "../../xfa/include/fwl/adapter/fwl_adaptertimermgr.h"
 #include "../../xfa/include/fxbarcode/BC_BarCode.h"
 #include "../../xfa/include/fxfa/fxfa.h"
 #include "../../xfa/include/fxgraphics/fx_graphics.h"
 #include "../../xfa/include/fxjse/fxjse.h"
+#endif
 #include "core/include/fpdfapi/fpdf_module.h"
 #include "core/include/fpdfapi/fpdf_pageobj.h"
 #include "core/include/fpdfapi/fpdf_parser.h"
 #include "core/include/fpdfapi/fpdf_render.h"
 #include "core/include/fpdfapi/fpdf_serial.h"
+#ifdef PDF_ENABLE_XFA
 #include "core/include/fpdfapi/fpdfapi.h"
+#endif
 #include "core/include/fpdfdoc/fpdf_doc.h"
 #include "core/include/fpdfdoc/fpdf_vt.h"
 #include "core/include/fxge/fx_ge.h"
 #include "core/include/fxge/fx_ge_win32.h"
+#ifdef PDF_ENABLE_XFA
 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h"
 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h"
+#endif
 #include "public/fpdfview.h"
 
 #ifdef _WIN32
@@ -55,12 +63,15 @@
   void Release() override { delete this; }
   FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
 
+#ifdef PDF_ENABLE_XFA
   virtual CFX_ByteString GetFullPath() { return ""; }
   virtual FX_BOOL GetByte(FX_DWORD pos, uint8_t& ch);
   virtual FX_BOOL GetBlock(FX_DWORD pos, uint8_t* pBuf, FX_DWORD size);
 
+#endif
  private:
   FPDF_FILEACCESS m_FileAccess;
+#ifdef PDF_ENABLE_XFA
   uint8_t m_Buffer[512];
   FX_DWORD m_BufferOffset;
 };
@@ -87,13 +98,19 @@
  protected:
   FPDF_FILEHANDLER* m_pFS;
   FX_FILESIZE m_nCurPos;
+#endif
 };
 
 // Object types for public FPDF_ types; these correspond to next layer down
 // from fpdfsdk. For master, these are CPDF_ types, but for XFA, these are
 // CPDFXFA_ types.
+#ifndef PDF_ENABLE_XFA
+using UnderlyingDocumentType = CPDF_Document;
+using UnderlyingPageType = CPDF_Page;
+#else
 using UnderlyingDocumentType = CPDFXFA_Document;
 using UnderlyingPageType = CPDFXFA_Page;
+#endif
 
 // Conversions to/from underlying types.
 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc);
diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h
index 3fc40ba..4b217f1 100644
--- a/fpdfsdk/include/fsdk_mgr.h
+++ b/fpdfsdk/include/fsdk_mgr.h
@@ -10,8 +10,10 @@
 #include <map>
 
 #include "core/include/fpdftext/fpdf_text.h"
+#ifdef PDF_ENABLE_XFA
 #include "fpdfxfa/fpdfxfa_doc.h"
 #include "fpdfxfa/fpdfxfa_page.h"
+#endif
 #include "fsdk_actionhandler.h"
 #include "fsdk_annothandler.h"
 #include "fsdk_baseannot.h"
@@ -38,12 +40,14 @@
   CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo);
   ~CPDFDoc_Environment();
 
+#ifdef PDF_ENABLE_XFA
   void Release() {
     if (m_pInfo && m_pInfo->Release)
       m_pInfo->Release(m_pInfo);
     delete this;
   }
 
+#endif
   void FFI_Invalidate(FPDF_PAGE page,
                       double left,
                       double top,
@@ -208,6 +212,7 @@
                                 sizeOfArray);
   }
 
+#ifdef PDF_ENABLE_XFA
   void FFI_DisplayCaret(FPDF_PAGE page,
                         FPDF_BOOL bVisible,
                         double left,
@@ -446,6 +451,7 @@
     return L"";
   }
 
+#endif
   FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
   void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; }
   CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; }
@@ -482,19 +488,29 @@
   // Gets the document object for the next layer down; for master this is
   // a CPDF_Document, but for XFA it is a CPDFXFA_Document.
   UnderlyingDocumentType* GetUnderlyingDocument() const {
+#ifndef PDF_ENABLE_XFA
+    return GetPDFDocument();
+#else
     return GetXFADocument();
+#endif
   }
 
   // Gets the CPDF_Document, either directly in master, or from the
   // CPDFXFA_Document for XFA.
+#ifndef PDF_ENABLE_XFA
+  CPDF_Document* GetPDFDocument() const { return m_pDoc; }
+#else
   CPDF_Document* GetPDFDocument() const {
     return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr;
   }
 
   // Gets the XFA document directly (XFA-only).
   CPDFXFA_Document* GetXFADocument() const { return m_pDoc; }
+#endif
 
+#ifdef PDF_ENABLE_XFA
   int GetPageViewCount() const { return m_pageMap.size(); }
+#endif
   CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage,
                                 FX_BOOL ReNew = TRUE);
   CPDFSDK_PageView* GetPageView(int nIndex);
@@ -548,8 +564,12 @@
   ~CPDFSDK_PageView();
   void PageView_OnDraw(CFX_RenderDevice* pDevice,
                        CPDF_Matrix* pUser2Device,
+#ifndef PDF_ENABLE_XFA
+                       CPDF_RenderOptions* pOptions);
+#else
                        CPDF_RenderOptions* pOptions,
                        const FX_RECT& pClip);
+#endif
   const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
   CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
   const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
@@ -567,20 +587,28 @@
   CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict);
   CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict);
   CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot);
+#ifdef PDF_ENABLE_XFA
   CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot);
+#endif
   FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
   size_t CountAnnots() const;
   CPDFSDK_Annot* GetAnnot(size_t nIndex);
   CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
+#ifndef PDF_ENABLE_XFA
+  CPDF_Page* GetPDFPage() { return m_page; }
+#else
   CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget);
   CPDFXFA_Page* GetPDFXFAPage() { return m_page; }
   CPDF_Page* GetPDFPage();
+#endif
   CPDF_Document* GetPDFDocument();
   CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; }
   FX_BOOL OnLButtonDown(const CPDF_Point& point, FX_UINT nFlag);
   FX_BOOL OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag);
+#ifdef PDF_ENABLE_XFA
   FX_BOOL OnRButtonDown(const CPDF_Point& point, FX_UINT nFlag);
   FX_BOOL OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag);
+#endif
   FX_BOOL OnChar(int nChar, FX_UINT nFlag);
   FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
   FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
@@ -604,6 +632,9 @@
   FX_BOOL IsValid() { return m_bValid; }
   void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; }
   FX_BOOL IsLocked() { return m_bLocked; }
+#ifndef PDF_ENABLE_XFA
+  void TakeOverPage() { m_bTakeOverPage = TRUE; }
+#endif
 
  private:
   void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice,
@@ -614,12 +645,19 @@
   nonstd::unique_ptr<CPDF_AnnotList> m_pAnnotList;
   std::vector<CPDFSDK_Annot*> m_fxAnnotArray;
   CPDFSDK_Document* m_pSDKDoc;
+#ifndef PDF_ENABLE_XFA
+  CPDFSDK_Widget* m_CaptureWidget;
+#else
   CPDFSDK_Annot* m_CaptureWidget;
+#endif
   FX_BOOL m_bEnterWidget;
   FX_BOOL m_bExitWidget;
   FX_BOOL m_bOnWidget;
   FX_BOOL m_bValid;
   FX_BOOL m_bLocked;
+#ifndef PDF_ENABLE_XFA
+  FX_BOOL m_bTakeOverPage;
+#endif
 };
 
 template <class TYPE>
diff --git a/fpdfsdk/include/javascript/IJavaScript.h b/fpdfsdk/include/javascript/IJavaScript.h
index f654696..7eab25f 100644
--- a/fpdfsdk/include/javascript/IJavaScript.h
+++ b/fpdfsdk/include/javascript/IJavaScript.h
@@ -7,7 +7,9 @@
 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_IJAVASCRIPT_H_
 #define FPDFSDK_INCLUDE_JAVASCRIPT_IJAVASCRIPT_H_
 
+#ifdef PDF_ENABLE_XFA
 #include "../../../xfa/include/fxjse/fxjse.h"
+#endif
 #include "core/include/fxcrt/fx_string.h"
 #include "core/include/fxcrt/fx_system.h"
 
@@ -149,11 +151,13 @@
                       const wchar_t* script,
                       CFX_WideString* info) = 0;
 
+#ifdef PDF_ENABLE_XFA
   virtual FX_BOOL GetHValueByName(const CFX_ByteStringC& utf8Name,
                                   FXJSE_HVALUE hValue) = 0;
   virtual FX_BOOL SetHValueByName(const CFX_ByteStringC& utf8Name,
                                   FXJSE_HVALUE hValue) = 0;
 
+#endif
  protected:
   IJS_Runtime() {}
 };
diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h
index 97f96f6..992721e 100644
--- a/fpdfsdk/include/jsapi/fxjs_v8.h
+++ b/fpdfsdk/include/jsapi/fxjs_v8.h
@@ -27,10 +27,12 @@
 class IJS_Context;  // A description of the event that caused JS execution.
 class IJS_Runtime;  // A native runtime, typically owns the v8::Context.
 
+#ifdef PDF_ENABLE_XFA
 // FXJS_V8 places no interpreation on this calass; it merely passes it
 // along to XFA.
 class CFXJSE_RuntimeData;
 
+#endif
 enum FXJSOBJTYPE {
   FXJSOBJTYPE_DYNAMIC = 0,  // Created by native method and returned to JS.
   FXJSOBJTYPE_STATIC,       // Created by init and hung off of global object.
@@ -49,10 +51,16 @@
   static FXJS_PerIsolateData* Get(v8::Isolate* pIsolate);
 
   std::vector<CFXJS_ObjDefinition*> m_ObjectDefnArray;
+#ifdef PDF_ENABLE_XFA
   CFXJSE_RuntimeData* m_pFXJSERuntimeData;
+#endif
 
  protected:
+#ifndef PDF_ENABLE_XFA
+  FXJS_PerIsolateData() {}
+#else
   FXJS_PerIsolateData() : m_pFXJSERuntimeData(nullptr) {}
+#endif
 };
 
 extern const wchar_t kFXJSValueNameString[];
@@ -137,11 +145,13 @@
                          std::vector<v8::Global<v8::Object>*>* pStaticObjects);
 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate);
 
+#ifdef PDF_ENABLE_XFA
 // Called as part of FXJS_InitializeRuntime, exposed so PDF can make its
 // own contexts compatible with XFA or vice versa.
 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context,
                                  IJS_Runtime* pIRuntime);
 
+#endif
 // Called after FXJS_InitializeRuntime call made.
 int FXJS_Execute(v8::Isolate* pIsolate,
                  IJS_Context* pJSContext,
diff --git a/fpdfsdk/include/pdfwindow/PWL_Edit.h b/fpdfsdk/include/pdfwindow/PWL_Edit.h
index 1a8db78..edb605c 100644
--- a/fpdfsdk/include/pdfwindow/PWL_Edit.h
+++ b/fpdfsdk/include/pdfwindow/PWL_Edit.h
@@ -33,6 +33,7 @@
                                  FX_BOOL& bRC,
                                  FX_BOOL& bExit,
                                  FX_DWORD nFlag) = 0;
+#ifdef PDF_ENABLE_XFA
 
   virtual void OnPopupPreOpen(void* pPrivateData,
                               FX_BOOL& bExit,
@@ -40,6 +41,7 @@
   virtual void OnPopupPostOpen(void* pPrivateData,
                                FX_BOOL& bExit,
                                FX_DWORD nFlag) = 0;
+#endif
 };
 
 class CPWL_Edit : public CPWL_EditCtrl, public IFX_Edit_OprNotify {
diff --git a/fpdfsdk/src/formfiller/FFL_ComboBox.cpp b/fpdfsdk/src/formfiller/FFL_ComboBox.cpp
index 348d5d1..a348d05 100644
--- a/fpdfsdk/src/formfiller/FFL_ComboBox.cpp
+++ b/fpdfsdk/src/formfiller/FFL_ComboBox.cpp
@@ -256,6 +256,7 @@
   return pRet;
 }
 
+#ifdef PDF_ENABLE_XFA
 FX_BOOL CFFL_ComboBox::IsFieldFull(CPDFSDK_PageView* pPageView) {
   if (CPWL_ComboBox* pComboBox =
           static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, FALSE))) {
@@ -265,6 +266,7 @@
   return FALSE;
 }
 
+#endif
 void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) {
   ASSERT(m_pApp != NULL);
 
diff --git a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp
index 9817f05..867bda0 100644
--- a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp
+++ b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp
@@ -562,10 +562,12 @@
 
 void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView) {}
 
+#ifdef PDF_ENABLE_XFA
 FX_BOOL CFFL_FormFiller::IsFieldFull(CPDFSDK_PageView* pPageView) {
   return FALSE;
 }
 
+#endif
 void CFFL_FormFiller::SetChangeMark() {
   m_pApp->FFI_OnChange();
 }
diff --git a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
index a12d84e..3257faa 100644
--- a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
+++ b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
@@ -277,10 +277,12 @@
     OnButtonUp(pWidget, pPageView, bReset, bExit, nFlags);
     if (bExit)
       return TRUE;
+#ifdef PDF_ENABLE_XFA
 
     OnClick(pWidget, pPageView, bReset, bExit, nFlags);
     if (bExit)
       return TRUE;
+#endif
   }
   return bRet;
 }
@@ -796,6 +798,7 @@
   }
 }
 
+#ifdef PDF_ENABLE_XFA
 void CFFL_IFormFiller::OnClick(CPDFSDK_Widget* pWidget,
                                CPDFSDK_PageView* pPageView,
                                FX_BOOL& bReset,
@@ -978,6 +981,7 @@
   }
 }
 
+#endif
 FX_BOOL CFFL_IFormFiller::IsValidAnnot(CPDFSDK_PageView* pPageView,
                                        CPDFSDK_Annot* pAnnot) {
   if (pPageView)
@@ -1002,6 +1006,7 @@
   CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE);
   ASSERT(pFormFiller != NULL);
 
+#ifdef PDF_ENABLE_XFA
   if (pFormFiller->IsFieldFull(pData->pPageView)) {
     FX_BOOL bFullExit = FALSE;
     FX_BOOL bFullReset = FALSE;
@@ -1013,6 +1018,7 @@
     }
   }
 
+#endif
   if (!m_bNotifying) {
     if (pData->pWidget->GetAAction(CPDF_AAction::KeyStroke)) {
       m_bNotifying = TRUE;
diff --git a/fpdfsdk/src/formfiller/FFL_TextField.cpp b/fpdfsdk/src/formfiller/FFL_TextField.cpp
index 3c0cdeb..2962451 100644
--- a/fpdfsdk/src/formfiller/FFL_TextField.cpp
+++ b/fpdfsdk/src/formfiller/FFL_TextField.cpp
@@ -268,6 +268,7 @@
   return pRet;
 }
 
+#ifdef PDF_ENABLE_XFA
 FX_BOOL CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) {
   if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) {
     return pWnd->IsTextFull();
@@ -276,6 +277,7 @@
   return FALSE;
 }
 
+#endif
 void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) {
   ASSERT(m_pApp != NULL);
 
diff --git a/fpdfsdk/src/fpdf_ext.cpp b/fpdfsdk/src/fpdf_ext.cpp
index db84f97..910c2c7 100644
--- a/fpdfsdk/src/fpdf_ext.cpp
+++ b/fpdfsdk/src/fpdf_ext.cpp
@@ -6,7 +6,9 @@
 
 #include "public/fpdf_ext.h"
 
+#ifdef PDF_ENABLE_XFA
 #include "../include/fpdfxfa/fpdfxfa_doc.h"
+#endif
 #include "core/include/fxcrt/fx_xml.h"
 #include "fpdfsdk/include/fsdk_define.h"
 
@@ -175,6 +177,15 @@
   const CXML_Element* pElement = metaData.GetRoot();
   if (pElement)
     CheckSharedForm(pElement, "workflowType");
+#ifndef PDF_ENABLE_XFA
+
+  // XFA Forms
+  CPDF_InterForm* pInterForm = new CPDF_InterForm(pDoc, FALSE);
+  if (pInterForm->HasXFAForm()) {
+    FPDF_UnSupportError(FPDF_UNSP_DOC_XFAFORM);
+  }
+  delete pInterForm;
+#endif
 }
 
 DLLEXPORT int FPDFDoc_GetPageMode(FPDF_DOCUMENT document) {
diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp
index 7c757cb..75ed27c 100644
--- a/fpdfsdk/src/fpdfeditpage.cpp
+++ b/fpdfsdk/src/fpdfeditpage.cpp
@@ -6,9 +6,11 @@
 
 #include "public/fpdf_edit.h"
 
+#ifdef PDF_ENABLE_XFA
 #include "../include/fpdfxfa/fpdfxfa_app.h"
 #include "../include/fpdfxfa/fpdfxfa_doc.h"
 #include "../include/fpdfxfa/fpdfxfa_page.h"
+#endif
 #include "fpdfsdk/include/fsdk_define.h"
 #include "public/fpdf_formfill.h"
 
@@ -81,9 +83,15 @@
   pPageDict->SetAt("Rotate", new CPDF_Number(0));
   pPageDict->SetAt("Resources", new CPDF_Dictionary);
 
+#ifndef PDF_ENABLE_XFA
+  CPDF_Page* pPage = new CPDF_Page;
+  pPage->Load(pDoc, pPageDict);
+  pPage->ParseContent();
+#else
   CPDFXFA_Page* pPage =
       new CPDFXFA_Page((CPDFXFA_Document*)document, page_index);
   pPage->LoadPDFPage(pPageDict);
+#endif
 
   return pPage;
 }
diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp
index 0798c4e..95defc5 100644
--- a/fpdfsdk/src/fpdfformfill.cpp
+++ b/fpdfsdk/src/fpdfformfill.cpp
@@ -6,9 +6,11 @@
 
 #include "public/fpdf_formfill.h"
 
+#ifdef PDF_ENABLE_XFA
 #include "../include/fpdfxfa/fpdfxfa_app.h"
 #include "../include/fpdfxfa/fpdfxfa_doc.h"
 #include "../include/fpdfxfa/fpdfxfa_page.h"
+#endif
 #include "fpdfsdk/include/fsdk_define.h"
 #include "fpdfsdk/include/fsdk_mgr.h"
 #include "public/fpdfview.h"
@@ -45,6 +47,15 @@
   if (!hHandle)
     return -1;
   CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
+#ifndef PDF_ENABLE_XFA
+  if (!pPage)
+    return -1;
+  CPDF_InterForm interform(pPage->m_pDocument, FALSE);
+  CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(
+      pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr);
+  if (!pFormCtrl)
+    return -1;
+#else
   if (pPage) {
     CPDF_InterForm interform(pPage->m_pDocument, FALSE);
     CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(
@@ -99,8 +110,14 @@
 
     pWidgetIterator->Release();
   }
+#endif
 
+#ifndef PDF_ENABLE_XFA
+  CPDF_FormField* pFormField = pFormCtrl->GetField();
+  return pFormField ? pFormField->GetFieldType() : -1;
+#else
   return -1;
+#endif
 }
 
 DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
@@ -129,7 +146,11 @@
 DLLEXPORT FPDF_FORMHANDLE STDCALL
 FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document,
                                 FPDF_FORMFILLINFO* formInfo) {
+#ifndef PDF_ENABLE_XFA
+  const int kRequiredVersion = 1;
+#else
   const int kRequiredVersion = 2;
+#endif
   if (!formInfo || formInfo->version != kRequiredVersion)
     return nullptr;
 
@@ -138,10 +159,14 @@
     return nullptr;
 
   CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo);
+#ifndef PDF_ENABLE_XFA
+  pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv));
+#else
   pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv));
 
   CPDFXFA_App* pApp = CPDFXFA_App::GetInstance();
   pApp->AddFormFillEnv(pEnv);
+#endif
   return pEnv;
 }
 
@@ -149,9 +174,19 @@
 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
   if (!hHandle)
     return;
+#ifndef PDF_ENABLE_XFA
+
+  CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
+  if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) {
+    pEnv->SetSDKDocument(NULL);
+    delete pSDKDoc;
+  }
+  delete pEnv;
+#else
   CPDFXFA_App* pApp = CPDFXFA_App::GetInstance();
   pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle);
   delete (CPDFDoc_Environment*)hHandle;
+#endif
 }
 
 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle,
@@ -193,6 +228,7 @@
   return pPageView->OnLButtonUp(pt, modifier);
 }
 
+#ifdef PDF_ENABLE_XFA
 DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
                                                FPDF_PAGE page,
                                                int modifier,
@@ -219,6 +255,7 @@
   return pPageView->OnRButtonUp(pt, modifier);
 }
 
+#endif
 DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle,
                                            FPDF_PAGE page,
                                            int nKeyCode,
@@ -276,18 +313,40 @@
   if (!pPage)
     return;
 
+#ifndef PDF_ENABLE_XFA
+  CPDF_RenderOptions options;
+  if (flags & FPDF_LCD_TEXT)
+    options.m_Flags |= RENDER_CLEARTYPE;
+  else
+    options.m_Flags &= ~RENDER_CLEARTYPE;
+#else
   CPDFXFA_Document* pDocument = pPage->GetDocument();
   if (!pDocument)
     return;
+#endif
 
+#ifndef PDF_ENABLE_XFA
+  // Grayscale output
+  if (flags & FPDF_GRAYSCALE) {
+    options.m_ColorMode = RENDER_COLOR_GRAY;
+    options.m_ForeColor = 0;
+    options.m_BackColor = 0xffffff;
+  }
+#else
   CPDF_Document* pPDFDoc = pDocument->GetPDFDoc();
   if (!pPDFDoc)
     return;
+#endif
 
+#ifndef PDF_ENABLE_XFA
+  options.m_AddFlags = flags >> 8;
+  options.m_pOCContext = new CPDF_OCContext(pPage->m_pDocument);
+#else
   CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
   CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument();
   if (!pFXDoc)
     return;
+#endif
 
   CFX_AffineMatrix matrix;
   pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
@@ -303,13 +362,19 @@
 #else
   nonstd::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice);
 #endif
+#ifdef PDF_ENABLE_XFA
 
   if (!pDevice)
     return;
+#endif
   pDevice->Attach((CFX_DIBitmap*)bitmap);
   pDevice->SaveState();
   pDevice->SetClip_Rect(&clip);
 
+#ifndef PDF_ENABLE_XFA
+  if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage))
+    pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options);
+#else
   CPDF_RenderOptions options;
   if (flags & FPDF_LCD_TEXT)
     options.m_Flags |= RENDER_CLEARTYPE;
@@ -327,9 +392,11 @@
 
   if (CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage))
     pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip);
+#endif
 
   pDevice->RestoreState();
   delete options.m_pOCContext;
+#ifdef PDF_ENABLE_XFA
   options.m_pOCContext = NULL;
 }
 DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document,
@@ -580,6 +647,7 @@
 
   stringArr->Add(bsStr);
   return TRUE;
+#endif
 }
 
 DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle,
diff --git a/fpdfsdk/src/fpdfsave.cpp b/fpdfsdk/src/fpdfsave.cpp
index f643f70..a3a91c7 100644
--- a/fpdfsdk/src/fpdfsave.cpp
+++ b/fpdfsdk/src/fpdfsave.cpp
@@ -6,12 +6,16 @@
 
 #include "public/fpdf_save.h"
 
+#ifdef PDF_ENABLE_XFA
 #include "../include/fpdfxfa/fpdfxfa_app.h"
 #include "../include/fpdfxfa/fpdfxfa_doc.h"
 #include "../include/fpdfxfa/fpdfxfa_util.h"
+#endif
 #include "fpdfsdk/include/fsdk_define.h"
 #include "public/fpdf_edit.h"
+#ifdef PDF_ENABLE_XFA
 #include "public/fpdf_formfill.h"
+#endif
 
 #if _FX_OS_ == _FX_ANDROID_
 #include "time.h"
@@ -56,6 +60,7 @@
   delete this;
 }
 
+#ifdef PDF_ENABLE_XFA
 #define XFA_DATASETS 0
 #define XFA_FORMS 1
 
@@ -279,6 +284,7 @@
   return _SaveXFADocumentData(pDocument, fileList);
 }
 
+#endif
 FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document,
                          FPDF_FILEWRITE* pFileWrite,
                          FPDF_DWORD flags,
@@ -288,10 +294,12 @@
   if (!pPDFDoc)
     return 0;
 
+#ifdef PDF_ENABLE_XFA
   CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
   CFX_PtrArray fileList;
   _SendPreSaveToXFADoc(pDoc, fileList);
 
+#endif
   if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) {
     flags = 0;
   }
@@ -309,12 +317,14 @@
   pStreamWrite = new CFX_IFileWrite;
   pStreamWrite->Init(pFileWrite);
   bRet = FileMaker.Create(pStreamWrite, flags);
+#ifdef PDF_ENABLE_XFA
   _SendPostSaveToXFADoc(pDoc);
   for (int i = 0; i < fileList.GetSize(); i++) {
     IFX_FileStream* pFile = (IFX_FileStream*)fileList.GetAt(i);
     pFile->Release();
   }
   fileList.RemoveAll();
+#endif
   pStreamWrite->Release();
   return bRet;
 }
diff --git a/fpdfsdk/src/fpdftext.cpp b/fpdfsdk/src/fpdftext.cpp
index ac4e01e..741bbe7 100644
--- a/fpdfsdk/src/fpdftext.cpp
+++ b/fpdfsdk/src/fpdftext.cpp
@@ -6,8 +6,10 @@
 
 #include "public/fpdf_text.h"
 
+#ifdef PDF_ENABLE_XFA
 #include "../include/fpdfxfa/fpdfxfa_doc.h"
 #include "../include/fpdfxfa/fpdfxfa_page.h"
+#endif
 #include "core/include/fpdfdoc/fpdf_doc.h"
 #include "core/include/fpdftext/fpdf_text.h"
 #include "fpdfsdk/include/fsdk_define.h"
@@ -20,9 +22,13 @@
   CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page);
   if (!pPDFPage)
     return nullptr;
+#ifndef PDF_ENABLE_XFA
+  CPDF_ViewerPreferences viewRef(pPDFPage->m_pDocument);
+#else
   CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
   CPDFXFA_Document* pDoc = pPage->GetDocument();
   CPDF_ViewerPreferences viewRef(pDoc->GetPDFDoc());
+#endif
   IPDF_TextPage* textpage =
       IPDF_TextPage::CreateTextPage(pPDFPage, viewRef.IsDirectionR2L());
   textpage->ParseTextPage();
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index 2066631..d47e2b0 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -6,11 +6,13 @@
 
 #include "public/fpdfview.h"
 
+#ifdef PDF_ENABLE_XFA
 #include "../include/fpdfxfa/fpdfxfa_app.h"
 #include "../include/fpdfxfa/fpdfxfa_doc.h"
 #include "../include/fpdfxfa/fpdfxfa_page.h"
 #include "../include/fpdfxfa/fpdfxfa_util.h"
 #include "core/include/fpdfapi/fpdf_module.h"
+#endif
 #include "core/include/fxcodec/fx_codec.h"
 #include "core/include/fxcrt/fx_safe_types.h"
 #include "fpdfsdk/include/fsdk_define.h"
@@ -18,7 +20,9 @@
 #include "fpdfsdk/include/fsdk_rendercontext.h"
 #include "fpdfsdk/include/javascript/IJavaScript.h"
 #include "public/fpdf_ext.h"
+#ifdef PDF_ENABLE_XFA
 #include "public/fpdf_formfill.h"
+#endif
 #include "public/fpdf_progressive.h"
 #include "third_party/base/nonstd_unique_ptr.h"
 #include "third_party/base/numerics/safe_conversions_impl.h"
@@ -36,16 +40,27 @@
 }
 
 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) {
+#ifndef PDF_ENABLE_XFA
+  return UnderlyingFromFPDFDocument(doc);
+#else
   return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr;
+#endif
 }
 
 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) {
+#ifndef PDF_ENABLE_XFA
+  return FPDFDocumentFromUnderlying(doc);
+#else
   return doc ? FPDFDocumentFromUnderlying(
                    new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance()))
              : nullptr;
+#endif
 }
 
 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) {
+#ifndef PDF_ENABLE_XFA
+  return UnderlyingFromFPDFPage(page);
+#else
   return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr;
 }
 
@@ -126,10 +141,12 @@
     return TRUE;
 
   return m_pFS->Flush(m_pFS->clientData) == 0;
+#endif
 }
 
 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) {
   m_FileAccess = *pFileAccess;
+#ifdef PDF_ENABLE_XFA
   m_BufferOffset = (FX_DWORD)-1;
 }
 
@@ -157,6 +174,7 @@
   if (pos + size > m_FileAccess.m_FileLen)
     return FALSE;
   return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size);
+#endif
 }
 
 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer,
@@ -218,13 +236,22 @@
   pModuleMgr->SetCodecModule(g_pCodecModule);
   pModuleMgr->InitPageModule();
   pModuleMgr->InitRenderModule();
+#ifndef PDF_ENABLE_XFA
+  pModuleMgr->LoadEmbeddedGB1CMaps();
+  pModuleMgr->LoadEmbeddedJapan1CMaps();
+  pModuleMgr->LoadEmbeddedCNS1CMaps();
+  pModuleMgr->LoadEmbeddedKorea1CMaps();
+#else
   CPDFXFA_App::GetInstance()->Initialize();
+#endif
   if (cfg && cfg->version >= 2)
     IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate);
 }
 
 DLLEXPORT void STDCALL FPDF_DestroyLibrary() {
+#ifdef PDF_ENABLE_XFA
   CPDFXFA_App::ReleaseInstance();
+#endif
   CPDF_ModuleMgr::Destroy();
   CFX_GEModule::Destroy();
 
@@ -285,6 +312,9 @@
     ProcessParseError(err_code);
     return NULL;
   }
+#ifndef PDF_ENABLE_XFA
+  return pParser->GetDocument();
+#else
   CPDF_Document* pPDFDoc = pParser->GetDocument();
   if (!pPDFDoc)
     return NULL;
@@ -327,6 +357,7 @@
 
 DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) {
   return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc();
+#endif
 }
 
 class CMemFile final : public IFX_FileRead {
@@ -415,7 +446,11 @@
 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) {
   CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
   if (!pDoc)
+#ifndef PDF_ENABLE_XFA
+    return 0;
+#else
     return (FX_DWORD)-1;
+#endif
 
   CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict();
   return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1;
@@ -444,7 +479,17 @@
   if (page_index < 0 || page_index >= pDoc->GetPageCount())
     return nullptr;
 
+#ifndef PDF_ENABLE_XFA
+  CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
+  if (pDict == NULL)
+    return NULL;
+  CPDF_Page* pPage = new CPDF_Page;
+  pPage->Load(pDoc, pDict);
+  pPage->ParseContent();
+  return pPage;
+#else
   return pDoc->GetPage(page_index);
+#endif
 }
 
 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) {
@@ -669,13 +714,36 @@
 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) {
   if (!page)
     return;
+#ifndef PDF_ENABLE_XFA
+  CPDFSDK_PageView* pPageView =
+      (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page);
+  if (pPageView && pPageView->IsLocked()) {
+    pPageView->TakeOverPage();
+    return;
+  }
+  delete (CPDF_Page*)page;
+#else
 
   CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
   pPage->Release();
+#endif
 }
 
 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) {
+#ifndef PDF_ENABLE_XFA
+  CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+  if (!pDoc)
+    return;
+
+  CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
+  if (!pParser) {
+    delete pDoc;
+    return;
+  }
+  delete pParser;
+#else
   delete CPDFDocumentFromFPDFDocument(document);
+#endif
 }
 
 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() {
@@ -695,8 +763,24 @@
   if (page == NULL || page_x == NULL || page_y == NULL)
     return;
   UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
+#ifndef PDF_ENABLE_XFA
+
+  CPDF_Matrix page2device;
+  pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y,
+                          rotate);
+  CPDF_Matrix device2page;
+  device2page.SetReverse(page2device);
+
+  FX_FLOAT page_x_f, page_y_f;
+  device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f,
+                        page_y_f);
+
+  *page_x = (page_x_f);
+  *page_y = (page_y_f);
+#else
   pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x,
                       device_y, page_x, page_y);
+#endif
 }
 
 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page,
@@ -714,8 +798,21 @@
   UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
   if (!pPage)
     return;
+#ifndef PDF_ENABLE_XFA
+  CPDF_Matrix page2device;
+  pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y,
+                          rotate);
+
+  FX_FLOAT device_x_f, device_y_f;
+  page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f,
+                        device_y_f);
+
+  *device_x = FXSYS_round(device_x_f);
+  *device_y = FXSYS_round(device_y_f);
+#else
   pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y,
                       device_x, device_y);
+#endif
 }
 
 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width,
@@ -830,6 +927,14 @@
     pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE;
   if (flags & FPDF_RENDER_FORCEHALFTONE)
     pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE;
+#ifndef PDF_ENABLE_XFA
+  if (flags & FPDF_RENDER_NO_SMOOTHTEXT)
+    pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH;
+  if (flags & FPDF_RENDER_NO_SMOOTHIMAGE)
+    pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH;
+  if (flags & FPDF_RENDER_NO_SMOOTHPATH)
+    pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH;
+#endif
   // Grayscale output
   if (flags & FPDF_GRAYSCALE) {
     pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY;
@@ -879,16 +984,28 @@
   if (!pDoc)
     return FALSE;
 
+#ifndef PDF_ENABLE_XFA
+  CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
+  if (!pDict)
+#else
   int count = pDoc->GetPageCount();
   if (page_index < 0 || page_index >= count)
     return FALSE;
 
   CPDFXFA_Page* pPage = pDoc->GetPage(page_index);
   if (!pPage)
+#endif
     return FALSE;
 
+#ifndef PDF_ENABLE_XFA
+  CPDF_Page page;
+  page.Load(pDoc, pDict);
+  *width = page.GetPageWidth();
+  *height = page.GetPageHeight();
+#else
   *width = pPage->GetPageWidth();
   *height = pPage->GetPageHeight();
+#endif
 
   return TRUE;
 }
@@ -965,6 +1082,7 @@
   return name_tree.LookupNamedDest(pDoc, name);
 }
 
+#ifdef PDF_ENABLE_XFA
 FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) {
   if (!str)
     return -1;
@@ -1017,6 +1135,7 @@
   return 0;
 }
 
+#endif
 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
                                               int index,
                                               void* buffer,
diff --git a/fpdfsdk/src/fpdfview_c_api_test.c b/fpdfsdk/src/fpdfview_c_api_test.c
index 344b029..fdf83be 100644
--- a/fpdfsdk/src/fpdfview_c_api_test.c
+++ b/fpdfsdk/src/fpdfview_c_api_test.c
@@ -104,8 +104,10 @@
     CHK(FORM_OnMouseMove);
     CHK(FORM_OnLButtonDown);
     CHK(FORM_OnLButtonUp);
+#ifdef PDF_ENABLE_XFA
     CHK(FORM_OnRButtonDown);
     CHK(FORM_OnRButtonUp);
+#endif
     CHK(FORM_OnKeyDown);
     CHK(FORM_OnKeyUp);
     CHK(FORM_OnChar);
@@ -117,6 +119,7 @@
     CHK(FPDF_SetFormFieldHighlightAlpha);
     CHK(FPDF_RemoveFormFieldHighlight);
     CHK(FPDF_FFLDraw);
+#ifdef PDF_ENABLE_XFA
     CHK(FPDF_HasXFAField);
     CHK(FPDF_LoadXFA);
     CHK(FPDF_Widget_Undo);
@@ -131,6 +134,7 @@
     CHK(FPDF_StringHandleGetStringByIndex);
     CHK(FPDF_StringHandleRelease);
     CHK(FPDF_StringHandleAddString);
+#endif
 
     // fpdf_ppo.h
     CHK(FPDF_ImportPages);
@@ -227,9 +231,11 @@
     CHK(FPDF_CountNamedDests);
     CHK(FPDF_GetNamedDestByName);
     CHK(FPDF_GetNamedDest);
+#ifdef PDF_ENABLE_XFA
     CHK(FPDF_BStr_Init);
     CHK(FPDF_BStr_Set);
     CHK(FPDF_BStr_Clear);
+#endif
 
     return 1;
 }
diff --git a/fpdfsdk/src/fsdk_annothandler.cpp b/fpdfsdk/src/fsdk_annothandler.cpp
index 5edd88a..aa38384 100644
--- a/fpdfsdk/src/fsdk_annothandler.cpp
+++ b/fpdfsdk/src/fsdk_annothandler.cpp
@@ -6,8 +6,10 @@
 
 #include <algorithm>
 
+#ifdef PDF_ENABLE_XFA
 #include "../include/fpdfxfa/fpdfxfa_doc.h"
 #include "../include/fpdfxfa/fpdfxfa_util.h"
+#endif
 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h"
 #include "fpdfsdk/include/fsdk_annothandler.h"
 #include "fpdfsdk/include/fsdk_define.h"
@@ -19,10 +21,12 @@
   CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
   pHandler->SetFormFiller(m_pApp->GetIFormFiller());
   RegisterAnnotHandler(pHandler);
+#ifdef PDF_ENABLE_XFA
 
   CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler =
       new CPDFSDK_XFAAnnotHandler(m_pApp);
   RegisterAnnotHandler(pXFAAnnotHandler);
+#endif
 }
 
 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {
@@ -66,6 +70,7 @@
   return new CPDFSDK_BAAnnot(pAnnot, pPageView);
 }
 
+#ifdef PDF_ENABLE_XFA
 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(IXFA_Widget* pAnnot,
                                                  CPDFSDK_PageView* pPageView) {
   ASSERT(pAnnot != NULL);
@@ -79,6 +84,7 @@
   return NULL;
 }
 
+#endif
 void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
   ASSERT(pAnnot != NULL);
 
@@ -121,8 +127,10 @@
   CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
   if (pPDFAnnot)
     return GetAnnotHandler(pPDFAnnot->GetSubType());
+#ifdef PDF_ENABLE_XFA
   if (pAnnot->GetXFAWidget())
     return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME);
+#endif
   return nullptr;
 }
 
@@ -142,8 +150,10 @@
   if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
     pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
   } else {
+#ifdef PDF_ENABLE_XFA
     if (pAnnot->IsXFAField())
       return;
+#endif
     static_cast<CPDFSDK_BAAnnot*>(pAnnot)
         ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
   }
@@ -315,6 +325,7 @@
   return FALSE;
 }
 
+#ifdef PDF_ENABLE_XFA
 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(
     CPDFSDK_Annot* pSetAnnot,
     CPDFSDK_Annot* pKillAnnot) {
@@ -330,6 +341,7 @@
   return TRUE;
 }
 
+#endif
 CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
     CPDFSDK_PageView* pPageView,
     CPDFSDK_Annot* pAnnot) {
@@ -353,6 +365,10 @@
 
 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
                                                      FX_BOOL bNext) {
+#ifndef PDF_ENABLE_XFA
+  CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");
+  return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
+#else
   CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
   CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
   if (pPage == NULL)
@@ -381,6 +397,7 @@
 
   pWidgetIterator->Release();
   return pPageView->GetAnnotByXFAWidget(hNextFocus);
+#endif
 }
 
 FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
@@ -424,11 +441,13 @@
   return pWidget;
 }
 
+#ifdef PDF_ENABLE_XFA
 CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(IXFA_Widget* hWidget,
                                                 CPDFSDK_PageView* pPage) {
   return NULL;
 }
 
+#endif
 void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
   ASSERT(pAnnot != NULL);
 
@@ -662,6 +681,7 @@
     }
   }
 
+#ifdef PDF_ENABLE_XFA
   CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
   CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
   CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
@@ -670,6 +690,7 @@
       pWidget->ResetAppearance(FALSE);
   }
 
+#endif
   if (m_pFormFiller)
     m_pFormFiller->OnLoad(pAnnot);
 }
@@ -725,6 +746,7 @@
   return rect.Contains(point.x, point.y);
 }
 
+#ifdef PDF_ENABLE_XFA
 #define FWL_WGTHITTEST_Unknown 0
 #define FWL_WGTHITTEST_Client 1     // arrow
 #define FWL_WGTHITTEST_Titlebar 11  // caption
@@ -1143,6 +1165,7 @@
   return dwFWLFlag;
 }
 
+#endif
 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
                                              bool bReverse)
     : m_bReverse(bReverse), m_pos(0) {
diff --git a/fpdfsdk/src/fsdk_baseannot.cpp b/fpdfsdk/src/fsdk_baseannot.cpp
index cecf5f7..2453ec5 100644
--- a/fpdfsdk/src/fsdk_baseannot.cpp
+++ b/fpdfsdk/src/fsdk_baseannot.cpp
@@ -5,7 +5,9 @@
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
 #include "core/include/fxcrt/fx_ext.h"
+#ifdef PDF_ENABLE_XFA
 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h"
+#endif
 #include "fpdfsdk/include/fsdk_baseannot.h"
 #include "fpdfsdk/include/fsdk_define.h"
 #include "fpdfsdk/include/fsdk_mgr.h"
@@ -967,10 +969,12 @@
   return CPDF_Action();
 }
 
+#ifdef PDF_ENABLE_XFA
 FX_BOOL CPDFSDK_BAAnnot::IsXFAField() {
   return FALSE;
 }
 
+#endif
 void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice,
                                    CPDF_Matrix* pUser2Device,
                                    CPDF_RenderOptions* pOptions) {
@@ -982,7 +986,11 @@
 }
 
 UnderlyingPageType* CPDFSDK_Annot::GetUnderlyingPage() {
+#ifndef PDF_ENABLE_XFA
+  return GetPDFPage();
+#else
   return GetPDFXFAPage();
+#endif
 }
 
 CPDF_Page* CPDFSDK_Annot::GetPDFPage() {
@@ -990,9 +998,11 @@
     return m_pPageView->GetPDFPage();
   return NULL;
 }
+#ifdef PDF_ENABLE_XFA
 
 CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() {
   if (m_pPageView)
     return m_pPageView->GetPDFXFAPage();
   return NULL;
 }
+#endif
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
index af6a8e5..c09182e 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -4,8 +4,10 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+#ifdef PDF_ENABLE_XFA
 #include "../include/fpdfxfa/fpdfxfa_doc.h"
 #include "../include/fpdfxfa/fpdfxfa_util.h"
+#endif
 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h"
 #include "fpdfsdk/include/fsdk_actionhandler.h"
 #include "fpdfsdk/include/fsdk_baseannot.h"
@@ -26,14 +28,19 @@
     : CPDFSDK_BAAnnot(pAnnot, pPageView),
       m_pInterForm(pInterForm),
       m_nAppAge(0),
+#ifndef PDF_ENABLE_XFA
+      m_nValueAge(0) {
+#else
       m_nValueAge(0),
       m_hMixXFAWidget(NULL),
       m_pWidgetHandler(NULL) {
+#endif
   ASSERT(m_pInterForm != NULL);
 }
 
 CPDFSDK_Widget::~CPDFSDK_Widget() {}
 
+#ifdef PDF_ENABLE_XFA
 IXFA_Widget* CPDFSDK_Widget::GetMixXFAWidget() const {
   CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
   CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
@@ -456,6 +463,7 @@
 #endif  // PDF_ENABLE_XFA
 }
 
+#endif
 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(
     CPDF_Annot::AppearanceMode mode) {
   CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
@@ -502,12 +510,14 @@
 }
 
 FX_BOOL CPDFSDK_Widget::IsAppearanceValid() {
+#ifdef PDF_ENABLE_XFA
   CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
   CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
   int nDocType = pDoc->GetDocType();
   if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA)
     return TRUE;
 
+#endif
   return CPDFSDK_BAAnnot::IsAppearanceValid();
 }
 
@@ -550,11 +560,13 @@
   return pCtrl->GetRotation() % 360;
 }
 
+#ifdef PDF_ENABLE_XFA
 CFX_WideString CPDFSDK_Widget::GetName() const {
   CPDF_FormField* pFormField = GetFormField();
   return pFormField->GetFullName();
 }
 
+#endif
 FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const {
   CPDF_FormControl* pFormCtrl = GetFormControl();
   ASSERT(pFormCtrl != NULL);
@@ -606,6 +618,7 @@
 
 int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
 #ifdef PDF_ENABLE_XFA
+#ifdef PDF_ENABLE_XFA
   if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
     if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
       if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
@@ -616,10 +629,14 @@
   }
 #endif  // PDF_ENABLE_XFA
 
+#endif
   CPDF_FormField* pFormField = GetFormField();
   return pFormField->GetSelectedIndex(nIndex);
 }
 
+#ifndef PDF_ENABLE_XFA
+CFX_WideString CPDFSDK_Widget::GetValue() const {
+#else
 CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const {
 #ifdef PDF_ENABLE_XFA
   if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
@@ -634,6 +651,7 @@
   }
 #endif  // PDF_ENABLE_XFA
 
+#endif
   CPDF_FormField* pFormField = GetFormField();
   return pFormField->GetValue();
 }
@@ -661,6 +679,7 @@
 
 FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
 #ifdef PDF_ENABLE_XFA
+#ifdef PDF_ENABLE_XFA
   if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
     if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
       if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
@@ -673,6 +692,7 @@
   }
 #endif  // PDF_ENABLE_XFA
 
+#endif
   CPDF_FormField* pFormField = GetFormField();
   return pFormField->IsItemSelected(nIndex);
 }
@@ -684,6 +704,7 @@
 
 FX_BOOL CPDFSDK_Widget::IsChecked() const {
 #ifdef PDF_ENABLE_XFA
+#ifdef PDF_ENABLE_XFA
   if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
     if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
       if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
@@ -694,6 +715,7 @@
   }
 #endif  // PDF_ENABLE_XFA
 
+#endif
   CPDF_FormControl* pFormCtrl = GetFormControl();
   return pFormCtrl->IsChecked();
 }
@@ -721,10 +743,12 @@
 
   pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
                            bNotify);
+#ifdef PDF_ENABLE_XFA
   if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
     ResetAppearance(TRUE);
   if (!bNotify)
     Synchronize(TRUE);
+#endif
 }
 
 void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) {
@@ -732,9 +756,11 @@
   ASSERT(pFormField != NULL);
 
   pFormField->SetValue(sValue, bNotify);
+#ifdef PDF_ENABLE_XFA
 
   if (!bNotify)
     Synchronize(TRUE);
+#endif
 }
 
 void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {}
@@ -745,9 +771,11 @@
   ASSERT(pFormField != NULL);
 
   pFormField->SetItemSelection(index, bSelected, bNotify);
+#ifdef PDF_ENABLE_XFA
 
   if (!bNotify)
     Synchronize(TRUE);
+#endif
 }
 
 void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) {
@@ -755,9 +783,11 @@
   ASSERT(pFormField != NULL);
 
   pFormField->ClearSelection(bNotify);
+#ifdef PDF_ENABLE_XFA
 
   if (!bNotify)
     Synchronize(TRUE);
+#endif
 }
 
 void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
@@ -774,6 +804,7 @@
   return m_bAppModified;
 }
 
+#ifdef PDF_ENABLE_XFA
 void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) {
   switch (GetFieldType()) {
     case FIELDTYPE_TEXTFIELD:
@@ -791,6 +822,7 @@
   }
 }
 
+#endif
 void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue,
                                      FX_BOOL bValueChanged) {
   SetAppModified();
@@ -1642,12 +1674,14 @@
     FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;
     FX_FLOAT fFontSize = GetFontSize();
 
+#ifdef PDF_ENABLE_XFA
     CFX_WideString sValueTmp;
     if (!sValue && (NULL != this->GetMixXFAWidget())) {
       sValueTmp = GetValue(TRUE);
       sValue = sValueTmp;
     }
 
+#endif
     if (nMaxLen > 0) {
       if (bCharArray) {
         pEdit->SetCharArray(nMaxLen);
@@ -1956,6 +1990,7 @@
                                   CPDFSDK_PageView* pPageView) {
   CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
   CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+#ifdef PDF_ENABLE_XFA
 
   CPDFXFA_Document* pDoc = pDocument->GetXFADocument();
   if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
@@ -1995,6 +2030,7 @@
     }
   }
 
+#endif
   CPDF_Action action = GetAAction(type);
 
   if (action && action.GetType() != CPDF_Action::Unknown) {
@@ -2067,6 +2103,7 @@
   return FALSE;
 }
 
+#ifdef PDF_ENABLE_XFA
 CPDFSDK_XFAWidget::CPDFSDK_XFAWidget(IXFA_Widget* pAnnot,
                                      CPDFSDK_PageView* pPageView,
                                      CPDFSDK_InterForm* pInterForm)
@@ -2095,12 +2132,15 @@
                        rcBBox.top + rcBBox.height);
 }
 
+#endif
 CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)
     : m_pDocument(pDocument),
       m_pInterForm(NULL),
       m_bCalculate(TRUE),
+#ifdef PDF_ENABLE_XFA
       m_bXfaCalculate(TRUE),
       m_bXfaValidationsEnabled(TRUE),
+#endif
       m_bBusy(FALSE) {
   m_pInterForm = new CPDF_InterForm(m_pDocument->GetPDFDocument(), FALSE);
   m_pInterForm->SetFormNotify(this);
@@ -2114,7 +2154,9 @@
   delete m_pInterForm;
   m_pInterForm = nullptr;
   m_Map.clear();
+#ifdef PDF_ENABLE_XFA
   m_XFAMap.RemoveAll();
+#endif
 }
 
 FX_BOOL CPDFSDK_InterForm::HighlightWidgets() {
@@ -2220,6 +2262,7 @@
   m_Map.erase(pControl);
 }
 
+#ifdef PDF_ENABLE_XFA
 void CPDFSDK_InterForm::AddXFAMap(IXFA_Widget* hWidget,
                                   CPDFSDK_XFAWidget* pWidget) {
   m_XFAMap.SetAt(hWidget, pWidget);
@@ -2236,6 +2279,7 @@
   return pWidget;
 }
 
+#endif
 void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled) {
   m_bCalculate = bEnabled;
 }
@@ -2244,6 +2288,7 @@
   return m_bCalculate;
 }
 
+#ifdef PDF_ENABLE_XFA
 void CPDFSDK_InterForm::XfaEnableCalculate(FX_BOOL bEnabled) {
   m_bXfaCalculate = bEnabled;
 }
@@ -2258,6 +2303,7 @@
   m_bXfaValidationsEnabled = bEnabled;
 }
 
+#endif
 #ifdef _WIN32
 CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile) {
   CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
@@ -2660,6 +2706,7 @@
   return pFDF ? pFDF->WriteBuf(textBuf) : FALSE;
 }
 
+#ifdef PDF_ENABLE_XFA
 void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField,
                                          FX_BOOL bSynchronizeElse) {
   ASSERT(pFormField != NULL);
@@ -2679,6 +2726,7 @@
   }
 }
 
+#endif
 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(
     const CFX_WideString& sFileExt) {
   CFX_WideString sFileName;
@@ -2795,8 +2843,10 @@
 
 int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField) {
   CPDF_FormField* pFormField = (CPDF_FormField*)pField;
+#ifdef PDF_ENABLE_XFA
   SynchronizeField(pFormField, FALSE);
 
+#endif
   int nType = pFormField->GetFieldType();
   if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
     OnCalculate(pFormField);
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index ed2ac1a..2e03989 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -14,11 +14,13 @@
 #include "public/fpdf_ext.h"
 #include "third_party/base/nonstd_unique_ptr.h"
 
+#ifdef PDF_ENABLE_XFA
 #include "../include/fpdfxfa/fpdfxfa_app.h"
 #include "../include/fpdfxfa/fpdfxfa_doc.h"
 #include "../include/fpdfxfa/fpdfxfa_page.h"
 #include "../include/fpdfxfa/fpdfxfa_util.h"
 
+#endif
 #if _FX_OS_ == _FX_ANDROID_
 #include "time.h"
 #else
@@ -212,9 +214,11 @@
 }
 
 CPDFDoc_Environment::~CPDFDoc_Environment() {
+#ifdef PDF_ENABLE_XFA
   CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
   if (pProvider->m_pEnvList.GetSize() == 0)
     pProvider->SetJavaScriptInitialized(FALSE);
+#endif
 }
 
 int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg,
@@ -538,14 +542,18 @@
   if (!pAnnot)
     return FALSE;
 
+#ifdef PDF_ENABLE_XFA
   CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot;
+#endif
   CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
   if (pPageView && pPageView->IsValid()) {
     CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr();
     if (!m_pFocusAnnot) {
+#ifdef PDF_ENABLE_XFA
       if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, pLastFocusAnnot))
         return FALSE;
 
+#endif
       if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag))
         return FALSE;
       if (!m_pFocusAnnot) {
@@ -562,10 +570,12 @@
     CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr();
     CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
     m_pFocusAnnot = nullptr;
+#ifdef PDF_ENABLE_XFA
 
     if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot))
       return FALSE;
 
+#endif
     if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) {
       if (pFocusAnnot->GetType() == FX_BSTRC("Widget")) {
         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
@@ -612,13 +622,25 @@
       m_bExitWidget(FALSE),
       m_bOnWidget(FALSE),
       m_bValid(FALSE),
+#ifndef PDF_ENABLE_XFA
+      m_bLocked(FALSE),
+      m_bTakeOverPage(FALSE) {
+#else
       m_bLocked(FALSE) {
+#endif
   CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
   if (pInterForm) {
     CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
+#ifndef PDF_ENABLE_XFA
+    pPDFInterForm->FixPageFields(page);
+#else
     if (page->GetPDFPage())
       pPDFInterForm->FixPageFields(page->GetPDFPage());
+#endif
   }
+#ifndef PDF_ENABLE_XFA
+  m_page->SetPrivateData((void*)m_page, (void*)this, nullptr);
+#endif
 }
 
 CPDFSDK_PageView::~CPDFSDK_PageView() {
@@ -629,14 +651,26 @@
   m_fxAnnotArray.clear();
 
   m_pAnnotList.reset();
+#ifndef PDF_ENABLE_XFA
+
+  m_page->RemovePrivateData((void*)m_page);
+  if (m_bTakeOverPage) {
+    delete m_page;
+  }
+#endif
 }
 
 void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice,
                                        CPDF_Matrix* pUser2Device,
+#ifndef PDF_ENABLE_XFA
+                                       CPDF_RenderOptions* pOptions) {
+#else
                                        CPDF_RenderOptions* pOptions,
                                        const FX_RECT& pClip) {
+#endif
   m_curMatrix = *pUser2Device;
   CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+#ifdef PDF_ENABLE_XFA
   CPDFXFA_Page* pPage = GetPDFXFAPage();
   if (pPage == NULL)
     return;
@@ -666,6 +700,7 @@
 #endif  // PDF_ENABLE_XFA
 
   // for pdf/static xfa.
+#endif
   CPDFSDK_AnnotIterator annotIterator(this, true);
   while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) {
     CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
@@ -717,9 +752,13 @@
   CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
   CPDFSDK_AnnotIterator annotIterator(this, false);
   while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) {
+#ifndef PDF_ENABLE_XFA
+    if (pSDKAnnot->GetType() == "Widget") {
+#else
     bool bHitTest = pSDKAnnot->GetType() == "Widget";
     bHitTest = bHitTest || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME;
     if (bHitTest) {
+#endif
       pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
       CPDF_Point point(pageX, pageY);
       if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
@@ -760,6 +799,7 @@
   return pSDKAnnot;
 }
 
+#ifdef PDF_ENABLE_XFA
 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot) {
   if (!pPDFAnnot)
     return nullptr;
@@ -778,6 +818,7 @@
   return pSDKAnnot;
 }
 
+#endif
 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) {
   return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr;
 }
@@ -788,6 +829,9 @@
 }
 
 FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) {
+#ifndef PDF_ENABLE_XFA
+  return FALSE;
+#else
   if (!pAnnot)
     return FALSE;
   CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
@@ -802,10 +846,14 @@
     m_CaptureWidget = nullptr;
 
   return TRUE;
+#endif
 }
 
 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() {
   if (m_page) {
+#ifndef PDF_ENABLE_XFA
+    return m_page->m_pDocument;
+#else
     return m_page->GetDocument()->GetPDFDoc();
   }
   return NULL;
@@ -814,6 +862,7 @@
 CPDF_Page* CPDFSDK_PageView::GetPDFPage() {
   if (m_page) {
     return m_page->GetPDFPage();
+#endif
   }
   return NULL;
 }
@@ -833,6 +882,7 @@
   }
   return nullptr;
 }
+#ifdef PDF_ENABLE_XFA
 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget) {
   if (!hWidget)
     return nullptr;
@@ -843,6 +893,7 @@
   }
   return nullptr;
 }
+#endif
 
 FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point,
                                         FX_UINT nFlag) {
@@ -862,6 +913,7 @@
   return bRet;
 }
 
+#ifdef PDF_ENABLE_XFA
 FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point& point,
                                         FX_UINT nFlag) {
   CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
@@ -900,6 +952,7 @@
   return TRUE;
 }
 
+#endif
 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag) {
   CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
   ASSERT(pEnv);
@@ -985,9 +1038,24 @@
 
 void CPDFSDK_PageView::LoadFXAnnots() {
   CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+#ifdef PDF_ENABLE_XFA
   CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+#endif
 
+#ifndef PDF_ENABLE_XFA
+  FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
+  // Disable the default AP construction.
+  CPDF_InterForm::EnableUpdateAP(FALSE);
+  m_pAnnotList.reset(new CPDF_AnnotList(m_page));
+  CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
+  const size_t nCount = m_pAnnotList->Count();
+#endif
   SetLock(TRUE);
+#ifndef PDF_ENABLE_XFA
+  for (size_t i = 0; i < nCount; ++i) {
+    CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
+    CPDF_Document* pDoc = GetPDFDocument();
+#else
   m_page->AddRef();
   if (m_pSDKDoc->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) {
     IXFA_PageView* pageView = NULL;
@@ -1012,12 +1080,24 @@
       m_fxAnnotArray.push_back(pAnnot);
       pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
     }
+#endif
 
+#ifndef PDF_ENABLE_XFA
+    CheckUnSupportAnnot(pDoc, pPDFAnnot);
+#else
     pWidgetHander->Release();
   } else {
     CPDF_Page* pPage = m_page->GetPDFPage();
     ASSERT(pPage != NULL);
+#endif
 
+#ifndef PDF_ENABLE_XFA
+    CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+    CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
+    if (!pAnnot)
+      continue;
+    m_fxAnnotArray.push_back(pAnnot);
+#else
     FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
     // Disable the default AP construction.
     CPDF_InterForm::EnableUpdateAP(FALSE);
@@ -1033,11 +1113,18 @@
       if (!pAnnot)
         continue;
       m_fxAnnotArray.push_back(pAnnot);
+#endif
 
+#ifndef PDF_ENABLE_XFA
+    pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
+#else
       pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
     }
+#endif
   }
+#ifdef PDF_ENABLE_XFA
   m_page->Release();
+#endif
   SetLock(FALSE);
 }
 
@@ -1058,7 +1145,11 @@
 
 int CPDFSDK_PageView::GetPageIndex() {
   if (m_page) {
+#ifndef PDF_ENABLE_XFA
+    CPDF_Dictionary* pDic = m_page->m_pFormDict;
+#else
     CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
+#endif
     CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument();
     if (pDoc && pDic) {
       return pDoc->GetPageIndex(pDic->GetObjNum());
diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp
index 76988d5..e59b1a7 100644
--- a/fpdfsdk/src/javascript/JS_Context.cpp
+++ b/fpdfsdk/src/javascript/JS_Context.cpp
@@ -35,7 +35,9 @@
 FX_BOOL CJS_Context::RunScript(const CFX_WideString& script,
                                CFX_WideString* info) {
   v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
+#ifdef PDF_ENABLE_XFA
   v8::Locker locker(m_pRuntime->GetIsolate());
+#endif
   v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
   v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
   v8::Context::Scope context_scope(context);
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index b195b42..2d0d7f6 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -6,8 +6,10 @@
 
 #include "JS_Runtime.h"
 
+#ifdef PDF_ENABLE_XFA
 #include "../../../xfa/src/fxjse/src/value.h"
 #include "../../include/fpdfxfa/fpdfxfa_app.h"
+#endif
 #include "Consts.h"
 #include "Document.h"
 #include "Field.h"
@@ -51,6 +53,15 @@
       m_bBlocking(FALSE),
       m_isolate(NULL),
       m_isolateManaged(false) {
+#ifndef PDF_ENABLE_XFA
+  IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform;
+  if (pPlatform->version <= 2) {
+    unsigned int embedderDataSlot = 0;
+    v8::Isolate* pExternalIsolate = nullptr;
+    if (pPlatform->version == 2) {
+      pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate);
+      embedderDataSlot = pPlatform->m_v8EmbedderSlot;
+#else
   if (CPDFXFA_App::GetInstance()->GetJSERuntime()) {
     // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate.
     m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime();
@@ -64,7 +75,11 @@
         embedderDataSlot = pPlatform->m_v8EmbedderSlot;
       }
       FXJS_Initialize(embedderDataSlot, pExternalIsolate);
+#endif
     }
+#ifndef PDF_ENABLE_XFA
+    FXJS_Initialize(embedderDataSlot, pExternalIsolate);
+#else
     m_isolateManaged = FXJS_GetIsolate(&m_isolate);
   }
 
@@ -77,13 +92,20 @@
     FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects);
     ReleaseContext(pContext);
     return;
+#endif
   }
+#ifndef PDF_ENABLE_XFA
+  m_isolateManaged = FXJS_GetIsolate(&m_isolate);
+#else
 
+#endif
   if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0)
     DefineJSObjects();
 
+#ifdef PDF_ENABLE_XFA
   CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE);
 
+#endif
   CJS_Context* pContext = (CJS_Context*)NewContext();
   FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects);
   ReleaseContext(pContext);
@@ -97,6 +119,9 @@
     delete m_ContextArray.GetAt(i);
 
   m_ContextArray.RemoveAll();
+#ifndef PDF_ENABLE_XFA
+  FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects);
+#endif
 
   m_pApp = NULL;
   m_pDocument = NULL;
@@ -108,7 +133,9 @@
 
 void CJS_Runtime::DefineJSObjects() {
   v8::Isolate::Scope isolate_scope(GetIsolate());
+#ifdef PDF_ENABLE_XFA
   v8::Locker locker(GetIsolate());
+#endif
   v8::HandleScope handle_scope(GetIsolate());
   v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
   v8::Context::Scope context_scope(context);
@@ -181,7 +208,9 @@
 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
   if (m_pDocument != pReaderDoc) {
     v8::Isolate::Scope isolate_scope(m_isolate);
+#ifdef PDF_ENABLE_XFA
     v8::Locker locker(m_isolate);
+#endif
     v8::HandleScope handle_scope(m_isolate);
     v8::Local<v8::Context> context =
         v8::Local<v8::Context>::New(m_isolate, m_context);
@@ -227,6 +256,7 @@
   return v8::Local<v8::Context>::New(m_isolate, m_context);
 }
 
+#ifdef PDF_ENABLE_XFA
 CFX_WideString ChangeObjName(const CFX_WideString& str) {
   CFX_WideString sRet = str;
   sRet.Replace(L"_", L".");
@@ -293,6 +323,7 @@
   return TRUE;
 }
 
+#endif
 void CJS_Runtime::AddObserver(Observer* observer) {
   ASSERT(m_observers.find(observer) == m_observers.end());
   m_observers.insert(observer);
diff --git a/fpdfsdk/src/javascript/JS_Runtime.h b/fpdfsdk/src/javascript/JS_Runtime.h
index 2353517..6de2b70 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.h
+++ b/fpdfsdk/src/javascript/JS_Runtime.h
@@ -58,12 +58,14 @@
   v8::Isolate* GetIsolate() const { return m_isolate; }
   v8::Local<v8::Context> NewJSContext();
 
+#ifdef PDF_ENABLE_XFA
   // IJS_Runtime:
   FX_BOOL GetHValueByName(const CFX_ByteStringC& utf8Name,
                           FXJSE_HVALUE hValue) override;
   FX_BOOL SetHValueByName(const CFX_ByteStringC& utf8Name,
                           FXJSE_HVALUE hValue) override;
 
+#endif
   void AddObserver(Observer* observer);
   void RemoveObserver(Observer* observer);
 
diff --git a/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp b/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp
index 90d19d9..b538066 100644
--- a/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp
@@ -136,6 +136,7 @@
   }
   CPDFSDK_Document* GetReaderDocument() override { return m_pDoc; }
 
+#ifdef PDF_ENABLE_XFA
   virtual FX_BOOL GetHValueByName(const CFX_ByteStringC&,
                                   FXJSE_HVALUE) override {
     return FALSE;
@@ -146,6 +147,7 @@
     return FALSE;
   }
 
+#endif
   int Execute(IJS_Context* cc,
               const wchar_t* script,
               CFX_WideString* info) override {
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index 09b1444..d18e032 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -47,7 +47,9 @@
 #define JS_STR_PLATFORM L"WIN"
 #define JS_STR_LANGUANGE L"ENU"
 #define JS_NUM_VIEWERVERSION 8
+#ifdef PDF_ENABLE_XFA
 #define JS_NUM_VIEWERVERSION_XFA 11
+#endif
 #define JS_NUM_FORMSVERSION 7
 
 BEGIN_JS_STATIC_CONST(CJS_App)
@@ -198,6 +200,7 @@
   if (!vp.IsGetting())
     return FALSE;
 
+#ifdef PDF_ENABLE_XFA
   CJS_Context* pContext = (CJS_Context*)cc;
   CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
   CPDFXFA_Document* pDoc = pCurDoc->GetXFADocument();
@@ -206,6 +209,7 @@
     return TRUE;
   }
 
+#endif
   vp << JS_NUM_VIEWERVERSION;
   return TRUE;
 }
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index 9a3a268..d7d2ef5 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp
@@ -281,7 +281,9 @@
     ++g_isolate_ref_count;
 
   v8::Isolate::Scope isolate_scope(pIsolate);
+#ifdef PDF_ENABLE_XFA
   v8::Locker locker(pIsolate);
+#endif
   v8::HandleScope handle_scope(pIsolate);
   v8::Local<v8::Context> v8Context =
       v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate));
@@ -325,7 +327,9 @@
                          v8::Global<v8::Context>* pV8PersistentContext,
                          std::vector<v8::Global<v8::Object>*>* pStaticObjects) {
   v8::Isolate::Scope isolate_scope(pIsolate);
+#ifdef PDF_ENABLE_XFA
   v8::Locker locker(pIsolate);
+#endif
   v8::HandleScope handle_scope(pIsolate);
   v8::Local<v8::Context> context =
       v8::Local<v8::Context>::New(pIsolate, *pV8PersistentContext);
@@ -335,9 +339,11 @@
   if (!pData)
     return;
 
+#ifdef PDF_ENABLE_XFA
   // XFA, if present, should have already cleaned itself up.
   FXSYS_assert(!pData->m_pFXJSERuntimeData);
 
+#endif
   int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
   for (int i = 0; i < maxID; ++i) {
     CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
@@ -374,11 +380,13 @@
       context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
 }
 
+#ifdef PDF_ENABLE_XFA
 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context,
                                  IJS_Runtime* pIRuntime) {
   v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime);
 }
 
+#endif
 int FXJS_Execute(v8::Isolate* pIsolate,
                  IJS_Context* pJSContext,
                  const wchar_t* script,
diff --git a/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp b/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp
index 8e685c9..e7f50e1 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp
@@ -30,7 +30,9 @@
     EmbedderTest::SetUp();
 
     v8::Isolate::Scope isolate_scope(m_pIsolate);
+#ifdef PDF_ENABLE_XFA
     v8::Locker locker(m_pIsolate);
+#endif
     v8::HandleScope handle_scope(m_pIsolate);
     FXJS_PerIsolateData::SetUp(m_pIsolate);
     FXJS_InitializeRuntime(m_pIsolate, nullptr, &m_pPersistentContext,
@@ -58,7 +60,9 @@
 
 TEST_F(FXJSV8Embeddertest, Getters) {
   v8::Isolate::Scope isolate_scope(isolate());
+#ifdef PDF_ENABLE_XFA
   v8::Locker locker(isolate());
+#endif
   v8::HandleScope handle_scope(isolate());
   v8::Context::Scope context_scope(GetV8Context());
 
diff --git a/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp b/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp
index 943d6ac..9c9c623 100644
--- a/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp
@@ -471,11 +471,13 @@
 
   if (bPopup) {
     if (m_pFillerNotify) {
+#ifdef PDF_ENABLE_XFA
       FX_BOOL bExit = FALSE;
       m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, 0);
       if (bExit)
         return;
 
+#endif
       int32_t nWhere = 0;
       FX_FLOAT fPopupRet = 0.0f;
       FX_FLOAT fPopupMin = 0.0f;
@@ -503,11 +505,13 @@
 
         m_nPopupWhere = nWhere;
         Move(rcWindow, TRUE, TRUE);
+#ifdef PDF_ENABLE_XFA
 
         bExit = FALSE;
         m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, 0);
         if (bExit)
           return;
+#endif
       }
     }
   } else {
@@ -528,6 +532,7 @@
     case FWL_VKEY_Up:
       if (m_pList->GetCurSel() > 0) {
         FX_BOOL bExit = FALSE;
+#ifdef PDF_ENABLE_XFA
 
         if (m_pFillerNotify) {
           m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
@@ -538,6 +543,7 @@
           if (bExit)
             return FALSE;
         }
+#endif
         if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) {
           if (bExit)
             return FALSE;
@@ -548,6 +554,7 @@
     case FWL_VKEY_Down:
       if (m_pList->GetCurSel() < m_pList->GetCount() - 1) {
         FX_BOOL bExit = FALSE;
+#ifdef PDF_ENABLE_XFA
 
         if (m_pFillerNotify) {
           m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
@@ -558,6 +565,7 @@
           if (bExit)
             return FALSE;
         }
+#endif
         if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) {
           if (bExit)
             return FALSE;
@@ -585,6 +593,7 @@
     return m_pEdit->OnChar(nChar, nFlag);
 
   FX_BOOL bExit = FALSE;
+#ifdef PDF_ENABLE_XFA
   if (m_pFillerNotify) {
     m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
     if (bExit)
@@ -594,6 +603,7 @@
     if (bExit)
       return FALSE;
   }
+#endif
   return m_pList->OnCharWithExit(nChar, bExit, nFlag) ? bExit : FALSE;
 }