# OFD 编辑器快速开始

打开一份真实 OFD，修改正文，保存后重新打开。

可以先在官网打开《功能导览》，里面的段落、表格和页眉都来自实际 OFD 文件。[打开完整 OFD 编辑器](https://quirekit.com/demo/ofd-editor/)

## 完成第一次修改

1. 在《功能导览》第一页单击正文中的一句话，输入一段文字。状态栏会显示「正文编辑」。
2. 打开「文件 → 导出 → OFD (.ofd)」，把修改后的文件保存到本地。
3. 从「文件 → 导入 → OFD 文档」重新打开刚才的文件，检查同一处文字。需要从空白公文开始时，打开「文件 → 文档模板库 → 公文示例」，选择「用模板新建」。

## 查看一个 OFD 文件

点击「读取示例 OFD」可以查看导览的类型和实际页数，也可以选一份本地文件。这个示例使用 MIT 许可的 `@quirekit/ofd/preservation` 读取原生包，所选文件留在浏览器里。完整工作台由商业组件 `@quirekit/ofd-editor` 提供。

### demos/inspect-file.vue

```vue
<script setup lang="ts">
import { computed, onBeforeUnmount, ref } from "vue";
import { openOFDSource } from "@quirekit/ofd/preservation";
import { QuireButton, QuireFileUpload, QuireIcon } from "@quirekit/ui/vue";

const props = defineProps<{ /** Page language from the documentation shell. */ locale?: string }>();
const english = computed(() => props.locale === "en");
const result = ref<{ name: string; kind: string; pages: number }>();
const failed = ref(false);
const busy = ref(false);
let selection = 0;
onBeforeUnmount(() => { selection++; });

/**
 * Reads only the latest file selected, entirely in this browser.
 * @param file - A local file, or the packaged guide when omitted.
 * @returns Resolves when file facts or a readable error are displayed.
 */
async function inspect(file?: File): Promise<void> {
  const current = ++selection;
  result.value = undefined;
  failed.value = false;
  busy.value = true;
  try {
    let bytes: ArrayBuffer;
    if (file) bytes = await file.arrayBuffer();
    else {
      const response = await fetch("/downloads/guide.ofd");
      if (!response.ok) throw new Error("Sample unavailable");
      bytes = await response.arrayBuffer();
    }
    if (current !== selection) return;
    const source = openOFDSource(new Uint8Array(bytes));
    result.value = { name: file?.name ?? "guide.ofd", kind: source.documentType ?? "OFD", pages: source.pages.length };
  } catch {
    if (current === selection) failed.value = true;
  } finally {
    if (current === selection) busy.value = false;
  }
}
</script>

<template>
  <div class="file-inspector">
    <div class="file-actions">
      <QuireButton size="sm" @click="inspect()">{{ english ? "Inspect the sample" : "读取示例 OFD" }}</QuireButton>
      <QuireFileUpload :model-value="[]" accept=".ofd" :label="english ? 'Open a local OFD' : '打开本地 OFD'"
        @file-accept="({ files }) => files[0] && inspect(files[0])">
        <template #default="{ openFilePicker }">
          <QuireButton size="sm" variant="outline" @click="openFilePicker">
            <template #leading><QuireIcon name="folderOpen" /></template>
            {{ english ? "Choose a local OFD" : "选择本地 OFD" }}
          </QuireButton>
        </template>
      </QuireFileUpload>
    </div>
    <p aria-live="polite" role="status">
      <template v-if="busy">{{ english ? "Reading file…" : "正在读取文件…" }}</template>
      <template v-else-if="failed">{{ english ? "Could not read this file. Select a valid OFD or try the sample again." : "文件读取失败，请选择有效的 OFD 或重新读取示例。" }}</template>
      <template v-else-if="result">{{ result.name }} · {{ result.kind }} · {{ result.pages }} {{ english ? "pages" : "页" }}</template>
      <template v-else>{{ english ? "Selected files are read in your browser." : "选择的文件仅在当前浏览器中读取。" }}</template>
    </p>
  </div>
</template>

<style scoped>
.file-inspector { display: grid; gap: 12px; padding: 16px; }
.file-actions { display: flex; gap: 8px; align-items: start; flex-wrap: wrap; }
.file-inspector p { margin: 0; overflow-wrap: anywhere; color: var(--qk-color-text-secondary); }
</style>

```

## 选择下一步

| 我想做的事 | 对应指南 |
| --- | --- |
| 判断哪些地方能改，编辑页眉或填写表单 | [编辑与保存](/guide/editing) |
| 把公文版式保存给下一位同事使用 | [创建与更新模板](/guide/templates) |
| 检查纸张、排好多个文件的打印顺序 | [打印与批量打印](/guide/printing) |
| 交付 Word、PDF 或保留签名的归档包 | [转换、验签与归档](/guide/exchange) |
| 把编辑器嵌入已有网站，接收文档会话 | [嵌入工作台](/integration/embed) |
| 从 Excel、业务系统或 HIS 写入同一份模板 | [统一填写数据](/integration/data) |
| 处理院级模板、CDA 和已签发病历 | [医疗扩展 OFD-H](/integration/medical) |
