Merge Documents and Reorganize Pages Using a Drop Zone

This client-side React sample is showing how to use a drop zone to do merge and rearrange of pages among multiple documents.

The sample is demonstrating two WebViewer instances. The user will drag and drop pages from a document to hold in the drop zone, then drag and drop them within the thumbnail of another document.

In the case of MS Office files (DOCX, XLSX, PPTX), documents will be loaded as PDFs, where modifications are saved.

WebViewer provides a slick out-of-the-box responsive UI that enables you to view, annotate and manipulate PDFs and other document types inside any web project.

Click the button below to view the full project in GitHub.

1import React, { useRef, useEffect } from 'react';
2import WebViewer from '@pdftron/webviewer';
3
4const Viewer = ({ docToLoad }) => {
5 const viewer = useRef(null);
6
7 useEffect(() => {
8 WebViewer.Iframe(
9 {
10 path: '/lib/webviewer',
11 initialDoc: docToLoad,
12 ui: 'legacy',
13 loadAsPDF: true,
14 enableFilePicker: true,
15 },
16 viewer.current,
17 ).then((instance) => {
18 if (!window.instance) {
19 window.instance = instance;
20 }
21 instance.UI.enableFeatures([
22 'ThumbnailMultiselect',
23 'MultipleViewerMerging',
24 ]);
25 instance.UI.enableElements(['documentControl']);
26 instance.UI.openElements(['leftPanel']);
27 });
28 // eslint-disable-next-line react-hooks/exhaustive-deps
29 }, []);
30
31 return <div className="webviewer" ref={viewer}></div>;
32};
33
34export default Viewer;
35

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales