office-viewer_viewer
by GanYoung
README.md
<p align="center">
<img src="assets/logo.svg" alt="Office & PDF Viewer Logo" width="88" height="88" />
</p>
<h1 align="center">Office & PDF Viewer for Antigravity</h1>
<p align="center">
为 <strong>Google Antigravity</strong> 右侧边栏与文件标签页新增 <strong>PDF、Word、Excel、CSV、PowerPoint</strong> 原生文档预览能力的 MCP App 插件。
</p>
<p align="center">
<a href="https://github.com/GanYoung/antigravity-office-viewer/releases"><img src="https://img.shields.io/github/v/release/GanYoung/antigravity-office-viewer?color=3B82F6" alt="Release"></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg" alt="MIT License"></a>
<img src="https://img.shields.io/badge/Node.js-%3E%3D18-brightgreen" alt="Node.js >= 18">
<img src="https://img.shields.io/badge/Antigravity-MCP%20App%20Plugin-1D4ED8" alt="Antigravity MCP App Plugin">
</p>
---
## 功能特点
- **文件标签页直接打开 (`file` entrypoint)**:在工作区、聊天链接或文件列表中点击 `.pdf`、`.docx`、`.doc`、`.xlsx`、`.xls`、`.xlsm`、`.csv`、`.tsv`、`.pptx`、`.ppt`,直接在右侧边栏打开自定义预览器。
- **侧边栏独立入口 (`+` 菜单 / 左侧边栏)**:点击右侧边栏 `+` → **Office & PDF 预览**,即可拖入文件、浏览本机文件夹、查看最近打开历史,或流式读取超过 10 MiB 的大文件。
- **AI 对话联动(内置 Skill + Rule)**:直接对 Agent 说「在右侧边栏打开这份 PDF / Word / Excel / PPT」,或让 Agent 生成文档后自动在右侧栏预览;支持将当前页面内容一键「附加到对话」。
- **多格式双引擎渲染**:
- **PDF (`.pdf`)**:内置 PDF.js + 离线 CJK CMap 与标准字体(零外部网络请求),支持缩放、旋转、目录跳转、全文搜索与文字划选复制。
- **Word (`.docx` / `.doc`)**:支持纯前端即时排版(`.docx`),以及 Windows 下调用本机 Microsoft Word COM 的高保真原版排版(带磁盘缓存,兼容 `.doc`)。
- **Excel / 表格 (`.xlsx` / `.xls` / `.xlsm` / `.csv` / `.tsv`)**:支持多工作表切换、冻结行列号、合并单元格、公式栏查看/复制、筛选搜索、大表分页,以及一键切换 Excel 打印预览。
- **PowerPoint (`.pptx` / `.ppt`)**:支持即时幻灯片浏览 + 演讲者备注 + 键盘翻页,以及 Windows 下本机 Microsoft PowerPoint 原版高保真渲染。
- **开箱即用,零 `npm install`**:本仓库与 Release 已内置打包后的 `dist/server.mjs`、`dist/viewer.html` 及 PDF.js 离线字体资源,安装后只需本机有 **Node.js ≥ 18** 即可直接运行。
---
## 支持格式与平台说明
| 格式 | 跨平台纯 JS 即时预览 (Windows / macOS / Linux) | 本机 Office 原版高保真模式 (Windows + MS Office) |
| :--- | :---: | :---: |
| `.pdf` | ✅ 完整支持(含中文 CJK CMap) | — |
| `.docx` | ✅ `docx-preview` 即时渲染 | ✅ Word COM 转高清 PDF(带缓存) |
| `.doc` | — | ✅ Word COM 自动转高清 PDF |
| `.xlsx` / `.xls` / `.xlsm` / `.csv` / `.tsv` | ✅ SheetJS 交互表格 / 公式 / 筛选 | ✅ Excel COM 打印视图 PDF |
| `.pptx` | ✅ 幻灯片解析 + 演讲者备注 | ✅ PowerPoint COM 原版高保真 PDF |
| `.ppt` | — | ✅ PowerPoint COM 自动转高清 PDF |
---
## 快速安装
> **前置条件**:本机已安装 [Node.js](https://nodejs.org/)(v18 或更高版本)。
### 方式一:通过 Antigravity CLI 一键安装(推荐)
```bash
agy plugin install https://github.com/GanYoung/antigravity-office-viewer
```
### 方式二:手动克隆到全局插件目录(适用于 Antigravity App / IDE)
**Windows (PowerShell):**
```powershell
git clone https://github.com/GanYoung/antigravity-office-viewer.git "$env:USERPROFILE\.gemini\config\plugins\office-viewer"
```
**macOS / Linux:**
```bash
git clone https://github.com/GanYoung/antigravity-office-viewer.git ~/.gemini/config/plugins/office-viewer
```
### 方式三:下载 Release 压缩包
1. 前往 [Releases 页面](https://github.com/GanYoung/antigravity-office-viewer/releases/latest) 下载 `antigravity-office-viewer-v1.0.0.zip`。
2. 解压到全局插件目录 `~/.gemini/config/plugins/office-viewer/`(确保目录内直接包含 `plugin.json`、`mcp_config.json`、`dist/` 等文件)。
3. Antigravity 会自动发现并加载插件,无需手动编辑配置。
---
## 使用方式
1. **点击文件直接预览**:在 Antigravity 中点击任意 `.pdf` / `.docx` / `.xlsx` / `.pptx` / `.csv` 文件即可在右侧标签页打开。
2. **从侧边栏打开文档中心**:点击右侧边栏 `+` 菜单 → 选择 **Office & PDF 预览**,即可拖拽文件、输入路径或浏览本地目录。
3. **在对话中直接吩咐 Agent**:
- `在右侧边栏打开并预览我当前项目里的 PDF / Word / Excel / PPT 文件`
- `用原版排版模式在右侧栏预览这份 PPTX 演示文稿`
- `帮我打开桌面上的 report.pdf 第 5 页`
### 暴露的 MCP 工具
插件注册的 MCP 服务器命名空间为 `office-viewer_viewer`:
- `preview_document({ path?, mode?, page?, sheet? })`:在右侧边栏打开指定本地文档,或无参打开文档中心;支持 `mode: "auto" | "office" | "fast"`、指定初始页码 `page` 或 Excel 工作表 `sheet`。
- `open_office_file`:Antigravity 原生文件标签页处理器(`file` entrypoint)。
---
## 项目结构
```text
office-viewer/
├── plugin.json # Antigravity 插件清单
├── mcp_config.json # MCP Server 启动配置
├── assets/logo.svg # 插件图标
├── skills/office-viewer/ # Agent 按需加载的技能说明 (SKILL.md)
├── rules/AGENTS.md # 自动触发右侧栏预览的插件规则
├── src/
│ ├── server.mjs # MCP Server 源码(Node.js)
│ ├── viewer.js / .css # 单文件 MCP App 前端预览器源码
│ ├── pptx_parser.js # PPTX 客户端解析器
│ ├── template.html # 内联 HTML 模板
│ └── office_convert.ps1 # Windows Microsoft Office COM 转 PDF 脚本
├── dist/ # 开箱即用构建产物(零 node_modules 可运行)
│ ├── server.mjs # esbuild 打包后的独立 MCP Server
│ ├── viewer.html # 单文件内联 MCP App 页面
│ └── pdf-assets/ # 离线 PDF.js CMap 与标准字体
└── build.mjs # esbuild 构建脚本
```
---
## 从源码开发与构建
如果你修改了 `src/` 下的源码,重新构建只需执行:
```bash
npm install
npm run build
```
构建脚本 `build.mjs` 会自动:
1. 将 `src/viewer.js`、`src/viewer.css` 和 `src/template.html` 打包为单文件 `dist/viewer.html`(并校验体积 `< 10 MiB`)。
2. 将 `src/server.mjs` 及其全部依赖打包为独立可执行的 `dist/server.mjs`。
3. 同步复制 `pdfjs-dist` 的 `cmaps` 和 `standard_fonts` 到 `dist/pdf-assets/`。
---
## 开源致谢(Third-Party Licenses)
本项目打包与使用了以下优秀的开源组件:
- [@modelcontextprotocol/sdk](https://github.com/modelcontextprotocol/typescript-sdk) & [@modelcontextprotocol/ext-apps](https://github.com/modelcontextprotocol/ext-apps) — MIT License
- [PDF.js (`pdfjs-dist`)](https://github.com/mozilla/pdf.js) — Apache-2.0 License
- [docx-preview](https://github.com/VolodymyrBaydalka/docxjs) — Apache-2.0 License
- [SheetJS (`xlsx`)](https://sheetjs.com/) — Apache-2.0 License
- [JSZip](https://github.com/Stuk/jszip) — MIT / GPLv3 Dual License
- [Zod](https://github.com/colinhacks/zod) — MIT License
## License
[MIT](LICENSE) © 2026 [GanYoung](https://github.com/GanYoung)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues