# pdf-viewer-semantic-text-comparison

> PDF viewer sample comparing two uploaded documents with synchronized navigation and highlighted text differences.

**Framework:** vue  **Component:** PdfViewer  **Variant:** semantic-text-comparison

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/vue/pdf-viewer-semantic-text-comparison.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-vue-pdfviewer
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/pdf-viewer-semantic-text-comparison/PdfViewer.vue

```vue
<template>
  <div class="control-section semantic-comparison">
    <div class="uploaders">
      <label>Original PDF <input ref="originalInput" type="file" accept=".pdf" @change="selectFile($event, true)" /></label>
      <span>{{ originalName }}</span>
      <label>Modified PDF <input ref="modifiedInput" type="file" accept=".pdf" @change="selectFile($event, false)" /></label>
      <span>{{ modifiedName }}</span>
      <button class="e-btn e-primary" type="button" :disabled="!originalFile || !modifiedFile" @click="compare">Compare</button>
      <button v-if="originalFile" class="e-btn" type="button" @click="clearFile(true)">Remove original</button>
      <button v-if="modifiedFile" class="e-btn" type="button" @click="clearFile(false)">Remove modified</button>
    </div>
    <div id="comparer-container" ref="comparerContainer"></div>
  </div>
</template>

<script lang="ts">
import { PdfComparer } from '@syncfusion/ej2-pdfviewer';
import { markRaw } from 'vue';

export default {
  data() {
    return {
      originalFile: null as File | null, modifiedFile: null as File | null,
      originalPath: 'https://cdn.syncfusion.com/content/pdf/original-document.pdf',
      modifiedPath: 'https://cdn.syncfusion.com/content/pdf/modified-document.pdf',
      originalName: 'Choose a PDF file', modifiedName: 'Choose a PDF file',
      comparer: null as PdfComparer | null
    };
  },
  methods: {
    selectFile(event: Event, original: boolean) {
      const file = (event.target as HTMLInputElement).files?.[0];
      if (!file) return;
      if (!file.name.toLowerCase().endsWith('.pdf')) { alert('Please select a valid PDF file.'); return; }
      if (original) {
        this.releasePath(true); this.originalFile = file; this.originalPath = URL.createObjectURL(file); this.originalName = file.name;
      } else {
        this.releasePath(false); this.modifiedFile = file; this.modifiedPath = URL.createObjectURL(file); this.modifiedName = file.name;
      }
    },
    releasePath(original: boolean) {
      const path = original ? this.originalPath : this.modifiedPath;
      if (!path.startsWith('https://')) URL.revokeObjectURL(path);
    },
    clearFile(original: boolean) {
      if (original) { this.releasePath(true); this.originalFile = null; this.originalPath = 'https://cdn.syncfusion.com/content/pdf/original-document.pdf'; this.originalName = 'Choose a PDF file'; (this.$refs.originalInput as HTMLInputElement).value = ''; }
      else { this.releasePath(false); this.modifiedFile = null; this.modifiedPath = 'https://cdn.syncfusion.com/content/pdf/modified-document.pdf'; this.modifiedName = 'Choose a PDF file'; (this.$refs.modifiedInput as HTMLInputElement).value = ''; }
    },
    compare() {
      if (!this.originalFile || !this.modifiedFile) return;
      this.comparer?.destroy();
      this.comparer = markRaw(new PdfComparer({
        originalDocumentPath: this.originalPath, modifiedDocumentPath: this.modifiedPath,
        resourceUrl: 'https://cdn.syncfusion.com/ej2/35.1.37/dist/ej2-pdfviewer-lib',
        comparisonOptions: { beforeColor: '#FF0000', afterColor: '#00FF00', beforeColorOpacity: 0.4, afterColorOpacity: 0.4, enableHighlights: true } as any,
        enableDifferencePanel: true, enableSyncScrolling: true
      }));
      this.comparer.appendTo(this.$refs.comparerContainer as HTMLElement);
      this.comparer.compare();
    }
  },
  beforeUnmount() {
    this.releasePath(true); this.releasePath(false); this.comparer?.destroy();
  }
};
</script>

<style scoped>
.uploaders { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 8px 0 16px; }
.uploaders label { font-weight: 600; }
.uploaders span { color: #666; font-size: 12px; margin-right: 8px; }
#comparer-container { height: 640px; width: 100%; }
</style>

```
