Skip to content
Demo示例FAQ

PDF 生成模板编辑器

开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。

查看 GitHub
Guides

阅读视图配置

ReaderViewConfig 控制 PDF 阅读视图的显示行为,包括页面布局、主题、缩放、间距等。

配置字段总览

字段类型默认值说明
displayModeString"singlePage"页面显示模式
continueModebooleantrue是否连续滚动
verticalModebooleantrue是否垂直滚动
cropModebooleanfalse是否裁剪页面白边
themesString"light"阅读主题
enableSliderBarbooleantrue是否显示滑块进度条
enablePageIndicatorbooleantrue是否显示页码指示器
pageSpacingint10页面间距(dp)
pageScalefloat1.0页面初始缩放比例
pageSameWidthbooleantrue所有页面是否等宽显示
enableMinScalebooleantrue是否开启最小缩放限制
marginsint[][0, 0, 0, 0]页面边距 [左, 上, 右, 下]
linkHighlightbooleantrue是否高亮显示链接
formFieldHighlightbooleantrue是否高亮显示表单域
annotationsVisiblebooleantrue是否显示注释
enableDoubleTapZoombooleanfalse是否启用双击缩放
enableCreateEditTextInputbooleantrue内容编辑模式下创建文本时是否弹出输入框
enableCreateImagePickerDialogbooleantrue内容编辑模式下创建图片时是否弹出选择器

页面显示模式

displayMode 控制页面的布局方式:

说明
singlePage单页模式(默认)
doublePage双页模式
coverPage封面模式(首页单独显示,后续双页)
json
{
  "readerViewConfig": {
    "displayMode": "singlePage",
    "continueMode": true,
    "verticalMode": true
  }
}

滚动方向

  • continueMode: true + verticalMode: true → 垂直连续滚动(默认)
  • continueMode: true + verticalMode: false → 水平连续滚动
  • continueMode: false → 翻页模式(每次只显示一页/双页)
json
{
  "readerViewConfig": {
    "continueMode": false,
    "verticalMode": false
  }
}

阅读主题

themes 提供 4 种内置主题:

说明
light浅色主题(默认)
dark深色主题
sepia护眼模式(暖色调)
reseda绿色护眼模式
json
{
  "readerViewConfig": {
    "themes": "light"
  }
}

页面间距与边距

json
{
  "readerViewConfig": {
    "pageSpacing": 10,
    "margins": [0, 0, 0, 0]
  }
}
  • pageSpacing:页面之间的间距,单位 dp。
  • margins:页面边距数组 [left, top, right, bottom],单位 dp。

缩放控制

json
{
  "readerViewConfig": {
    "pageScale": 1.0,
    "pageSameWidth": true,
    "enableMinScale": true,
    "enableDoubleTapZoom": false
  }
}
字段说明
pageScale初始缩放比例,1.0 表示 100%
pageSameWidth所有页面是否按相同宽度显示
enableMinScale是否启用最小缩放限制
enableDoubleTapZoom是否支持双击放大/缩小

高亮与可见性

json
{
  "readerViewConfig": {
    "linkHighlight": true,
    "formFieldHighlight": true,
    "annotationsVisible": true,
    "cropMode": false
  }
}
字段说明
linkHighlight高亮显示文档中的超链接区域
formFieldHighlight高亮显示表单域区域
annotationsVisible是否渲染并显示注释
cropMode裁剪页面白边,仅显示内容区域

UI 样式配置

readerViewConfig.uiStyle 提供细粒度的 UI 样式控制:

json
{
  "readerViewConfig": {
    "uiStyle": {
      "selectTextColor": "#33000000",
      "displayPageRect": {
        "fillColor": "#4D1460F3",
        "borderColor": "#6499FF",
        "borderWidth": 5,
        "borderDashPattern": [0.0, 0.0]
      },
      "screenshot": {
        "outsideColor": "#00000000",
        "fillColor": "#00000000",
        "borderColor": "#6499FF",
        "borderWidth": 5,
        "borderDashPattern": [20.0, 8.0]
      },
      "formPreview": {
        "style": "fill",
        "strokeWidth": 2,
        "color": "#4D1460F3"
      },
      "defaultBorderStyle": {
        "borderColor": "#FF888888",
        "borderWidth": 2,
        "borderDashPattern": [10, 10]
      },
      "focusBorderStyle": {
        "nodeColor": "#6499FF",
        "borderColor": "#6499FF",
        "borderWidth": 2,
        "borderDashPattern": [10.0, 10.0]
      }
    }
  }
}
样式项说明
selectTextColor文本选中高亮颜色
displayPageRect页面显示区域的边框/填充样式
screenshot截图模式的边框/填充样式
formPreview表单预览样式
defaultBorderStyle对象默认边框样式
focusBorderStyle对象选中时的边框样式
cropImageStyle图片裁剪时的边框样式

完整示例

json
{
  "readerViewConfig": {
    "linkHighlight": true,
    "formFieldHighlight": true,
    "displayMode": "singlePage",
    "continueMode": true,
    "verticalMode": true,
    "cropMode": false,
    "themes": "light",
    "enableSliderBar": true,
    "enablePageIndicator": true,
    "pageSpacing": 10,
    "margins": [0, 0, 0, 0],
    "pageScale": 1.0,
    "pageSameWidth": true,
    "enableMinScale": true,
    "annotationsVisible": true,
    "enableDoubleTapZoom": false
  }
}