Developer Guide Web
Developer Guide Web
ComPDFKit for Web is a robust online PDF viewer library for developers who need to develop
applications on the Web, which offers powerful JavaScript APIs for quickly viewing and editing any
PDF online. It is feature-rich and battle-tested, making PDF files process and manipulation easier
and faster for your online project.
Standard page display modes, including Scrolling, Double page, and Cover mode.
Navigation with thumbnails, outlines, and layers.
Text search & selection.
Zoom in and out.
Switch between different themes, including light mode and dark mode.
Create, edit, and remove kinds of annotations, including Notes, Free Text, Lines, Arrow,
Squares, Circles, Ink, and Stamps.
Support for annotation appearances.
Import and export annotations to/from XFDF.
Create, edit and, remove form fields, including Text Fields, Check Boxes, Radio Button, List
Box, Combo Box, Push Button, and Signatures.
Fill out PDF Forms.
Drawn signatures.
Image signatures.
Typed signatures.
Encrypt and decrypt PDFs, Password can be set to protected the PDF.
Overlay Comparison to superpose two files and show the differences by different colors.
Programmatically add and remove text in PDFs and make it possible to edit PDFs like Word.
Allow selecting text to copy, resize, change colors, text alignment, and the position of text
boxes.
1.2 License
ComPDFKit for Web is a commercial SDK, which requires a license to grant developer permission
to release their apps. Each license is only valid for one root domain. Other flexible licensing
options are also supported, please contact our marketing team to know more. However, any
documents, sample code, or source code distribution from the released package of ComPDFKit to
any third party is prohibited.
2 Get Started
It is easy to embed ComPDFKit in your web app with a few lines of JavaScript code. Take just a few
minutes and get started.
The following sections introduce the structure of the installation package, how to run a demo, and
how to make a web app with ComPDFKit for Web.
2.1 Requirements
To integrate ComPDFKit for Web in your browser, you must have a development environment and
a browser.
Before you start the following steps, create a new web project first.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ComPDFKit Web Viewer</title>
</head>
<!-- Import WebViewer as a script tag -->
<script src='@compdfkit/webviewer.global.js'></script>
<body>
<div id="app" style="width: 100%; height: 100vh;"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ComPDFKit Web Viewer</title>
</head>
<!-- Import WebViewer as a script tag -->
<script src='@compdfkit/webviewer.global.js'></script>
<body>
<div id="app" style="width: 100%; height: 100vh;"></div>
<script>
let docViewer = null;
ComPDFKitViewer.init({
pdfUrl: '/webviewer/example/developer_guide_web.pdf',
license: 'Input your license here'
}, document.getElementById('app')).then((core) => {
docViewer = core.docViewer;
Open http://localhost:8080 on your browser. Then you will be able to see the PDF file you want to
display.
1. Add the ""@compdfkit" folder in the lib directory to the root directory or assets directory of
your project. This will serve as the entry point for the ComPDFKit for Web and will be
imported into your project.
2. Add the "webviewer" folder that contains the required static resource files to run the
ComPDFKit Web demo, to your project’s static resource folder.
1. Import the “webviewer.js” file in the "@compdfkit" folder into your project.
2. Initialize the ComPDFKit for Web in your project by calling ComPDFKitViewer.init() .
3. Pass the PDF address you want to display and your license key into the init function.
4. Once your project is running, you will be able to see the PDF file you want to display.
npm install
useEffect(() => {
ComPDFKitViewer.init({
pdfUrl: 'Your PDF Url',
license: 'Input your license here'
}, viewer.current).then((core) => {
docViewer = core.docViewer;
docViewer.addEvent('documentloaded', () => {
console.log('ComPDFKit Web Demo');
})
})
});
return (
<div id="webviewer" ref={viewer}></div>
)
}
2.6 UI Customization
2.6.1 Customize the Navigation Bar
One key part of customizing the UI is the customization of the navigation bar. There are several
ways you may want to customize the navigation bar. To name a few:
ComPDFKit for Web's WebViewer UI provides flexible APIs for easy customization of the
navigation bar.
To understand the structure of the navigation bar and the different types of tools, you can read
The Composition of the Navigation Bar and Navigation Bar Tools. You can also jump directly
to the UI Customization Samples to see examples of customizing the navigation bar.
Navigation Tools:
The icon buttons on the left and right sides of the image below (Navigation Bar) are the
Navigation Tools.
Feature Area:
The part inside the feature box in the middle of the navigation bar is called the Feature Area
(as shown in the image below). Each feature has a different Sub-Menus. Buttons in both the
Feature Area and the Sub-Menus can be modified individually.
Sub-Menus:
Under different Feature Areas, there are corresponding Sub-Menus showing a group of
tools for that feature. ComPDFKit for Web provides various APIs to customize the tools within
this Sub-Menus. Below, the Sub-Menus for annotations and forms are shown:
ComPDFKitViewer.init(...)
.then(instance => {
const { UI } = instance;
UI.setActiceToolMode('toolMenu-Annotation');
})
2.6.4 Hide/Show Navigation Bar Elements
Find the Data Element Attribute of the Navigation Bar
To hide or show navigation bar elements, you first need to find the element’s data-element
attribute in the DOM inspector.
For Example:
We can see that its data-element value is themeMode . Now we can use this value to hide or show
it.
The image below is the data-element attributes of the Toolbar of the Feature Area.
// Hide the left panel button and the right panel button.
UI.disableElements(['leftPanelButton', 'rightPanelButton']);
// Show the left panel button and the right panel button.
UI.enableElements(['leftPanelButton', 'rightPanelButton']);
Parameters for the setHeaderItems callback function: header object, can invoke get ,
getItems , shift , unshift , push , pop , delete , and update to perform corresponding
operations on navigation tools and the toolbar.
UI.setHeaderItems(function(header) {
// Get all feature area.
const items = header.getHeader('tools').getItems();
console.log(items);
});
2. Action Button
An action button can trigger an action. This kind of button has no active state. Its properties
include:
const newActionButton = {
name: 'customButton',
type: 'actionButton',
img: 'path/to/image',
onClick: () => {
alert('Hello world!');
},
dataElement: 'alertButton'
};
3. State Button
The state button is a customizable button. You can decide how many states it has, what state is
active, and when to update the state. Its properties include:
states (object) - The shape of the object looks like: { nameOfState1: state1, nameOfState2:
state2, ... }
unmount (function, optional) - Function to be called before the button is unmounted from
DOM.
dataElement (string, optional) - String to set data-element value of the button element.
text (string, optional) - Effective when dropItem is true. Set the text displayed for the
dropdown option.
Examples:
A stateful button that shows the count. When you click it, it will increment the counter by 1.
const countButton = {
name: 'customButton',
type: 'statefulButton',
initialState: 'Count',
states: {
Count: {
number: 1,
getContent: activeState => {
return activeState.number;
},
onClick: activeState => {
activeState.number += 1;
}
}
},
dataElement: 'countButton'
};
A state button showing the current page number. When you click it, the document will go to the
next page. If you are on the last page, the document will turn to the first page.
const nextPageButton = {
name: 'customButton',
type: 'statefulButton',
initialState: 'Page',
states: {
Page: {
getContent: Core.getCurrentPage,
onClick: activeState => {
const currentPage = Core.getCurrentPage();
const totalPages = Core.getPagesCount();
const atLastPage = currentPage === totalPages;
if (atLastPage) {
Core.previousPage();
} else {
Core.nextPage();
}
activeState.getContent = Core.getCurrentPage();
}
}
},
mount: () => {
// Execute after mounting.
console.log('Mounted.');
},
unmount: () => {
// Execute before destruction.
console.log('Destroyed.');
},
dataElement: 'nextPageButton'
};
const newToggleButton = {
name: 'customButton',
type: 'toggleButton',
img: `path/to/image`,
element: 'pageModePanel',
dataElement: 'pageModePanelButton'
};
5. Tool Button
The tool button is the button in the sub-menus under the feature module. For example, in the
Form feature mode, you can create a button for a text field function by customizing a tool button
and specifying its element value as textfield . You can place the tool buttons you need to
customize anywhere. When the tool is activated, the button is in an active state.
const newToolButton = {
name: 'customButton',
type: 'toolButton',
toolName: 'textfield'
};
6. Spacer
The spacer is just a div with a CSS attribute of flex: 1 , used to occupy any remaining space in
the tool. It is used to push buttons to each side of the default title.
const newSpacer = {
type: 'spacer'
};
7. Divider
Divider renders a vertical bar with some margin to separate item groups.
Its properties include:
const newDivider = {
type: 'divider'
};
UI.setHeaderItems(function(header) {
const mySaveButton = {
name: 'customButton',
type: 'actionButton',
dataElement: 'mySaveButton',
img: `<svg width="14" height="14" viewBox="0 0 14 14" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M13 1L1 13" stroke="#BABABA" stroke-width="2" stroke-
linecap="round" stroke-linejoin="round"/>
<path d="M1 1L13 13" stroke="#BABABA" stroke-width="2" stroke-
linecap="round" stroke-linejoin="round"/>
</svg>`,
onClick: function() {
Core.download();
}
}
header.push(mySaveButton);
});
Hide the text field tool in the form function area and put it on the right side of the navigation bar:
UI.setHeaderItems(header => {
header.headers.toolItems.form.splice(0, 1);
const myTextFieldButtom = {
name: 'customButton',
type: 'toolButton',
toolName: 'textfield'
}
header.getHeader('rightHeaders').unshift(myTextFieldButtom);
});
UI.setHeaderItems(header => {
// Reverse the order of the function area.
header.headers.tools.reverse();
// Sort by the names of the function areas in alphabetical order.
header.headers.tools.sort((a, b) => a.element.localeCompare(b.element));
});
3 Guides
If you’re interested in the ComPDFKit features, please go through our guides to quickly add PDF
viewing, annotating, editing, form filling, and signing to your application. The following sections
list some examples to show you how to add document functionalities to your Web apps using our
JavaScript APIs.
3.1 Viewer
3.1.1 Overview
ComPDFKit for Web includes a high-quality PDF viewer that’s fast, precise, and feature-rich. It
offers developers a way to quickly embed a highly configurable PDF viewer in any Web
application.
Display Modes: Freely switch between single-page or double-page view, page flipping or
scrolling modes, adapting to different reading scenarios.
Multiple Themes: Choose themes suitable for work, night reading, prolonged screen time,
or creating custom themes.
PDF Navigation: Navigate directly to specific locations, or use bookmarks and outlines.
Extensibility: Easily add features such as annotations, forms, signatures, etc., to PDF viewer.
Fast UI Integration: Achieve rapid integration and customization through extensible UI
components.
Display Modes
Choose between single-page, double-page, book, flip, or scroll modes, or set cropping and
split-view modes.
Page Navigation
Locate the position of keywords in the document, and copy or mark the text of interest.
Zooming
Adjust the degree of zoom in or zoom out of a page in a PDF document to fit the user's visual
preferences or device screen size.
Set Language
Single Mode
Show one page at a time for users to continuously scroll up and down to navigate through
the pages.
Double Page
Display two pages side-by-side and continuously scroll up and down to navigate through the
pages.
Cover Mode
docViewer.webViewerSwitchSpreadMode(mode)
It's a mode to view PDFs in full-screen, which fills the entire screen with the PDF content. The
following method is given to start the full-screen presentation mode.
docViewer.requestFullScreenMode()
Page Navigation
After loading a PDF document, you can programmatically interact with it, which allows you to
view and transition between the pages like scrolling and jumping to specific pages.
// Previous page.
docViewer.previousPage()
// Next page.
docViewer.nextPage()
// Jump to a page.
docViewer.pageNumberChanged('3')
Scroll
To scroll to specific distances in the horizontal and vertical directions, you can use this
function.
Scroll Mode
ComPDFKit for Web has two scrolling modes: Vertical and Horizontal. You can set the
corresponding mode by using the following method.
docViewer.webViewerSwitchScrollMode(mode)
Thumbnails
docViewer.search(value)
3.1.5 Zooming
ComPDFKit for Web provides super zoom out and in to unlock more zoom levels, and pinch-to-
zoom or double tap on the specific area to perform a smart page content analysis, or you can
programmatically interact with it by using the following method.
Use the following methods to zoom in/out by a certain zoom value or scale.
// Zoom in.
docViewer.zoomIn()
// Zoom out.
docViewer.zoomOut()
// Scale changed.
docViewer.webViewerScaleChanged(scale)
scale yes number Zoom Scale, Zoom In: 10, Zoom Out: 0.5
3.2 Annotations
3.2.1 Overview
Annotations allow users to highlight paragraphs, add comments, markup, sign, or stamp PDF
documents without modifying the original author's content. The annotated content, along with
the original text, can then be shared together.
Create Annotations
Note
Link
Free text
Shapes: Square, circle, line, and arrow
Markup: Highlight, underline, strikeout, and squiggly
Ink
Stamp: Nearly 20 standard stamps and dynamic stamps
Note: When adding an annotation, the coordinate origin is at the left top corner of the page.
Note
Add a sticky note (text annotation) to a PDF Document page by using the following method.
docViewer.addAnnotations({
type: 'text',
pageIndex: 1,
color: '#FF0000',
fontSize: 16,
fontName: 'Helvetica',
opacity: 1,
contents: 'test',
rect: {
left: 100,
top: 30,
right: 124,
bottom: 54
},
})
Link
To add a hyperlink or intra-document link annotation to a PDF Document page by using the
following method.
// Add a hyperlink.
docViewer.addAnnotations({
type: "link",
pageIndex: 0,
rect: {
left: 92,
top: 200,
right: 167,
bottom: 230
},
url: "https://example.com"
})
Free Text
Add a free text annotation to a PDF Document page by using the following method.
docViewer.addAnnotations({
type: 'freetext',
pageIndex: 0,
color: '#000000',
fontSize: 16,
fontName: 'Helvetica',
opacity: 1,
textAlignment: 'left',
contents: 'test',
rect: {
left: 100,
top: 200,
right: 160,
bottom: 240
}
})
Shapes
Add a shape annotation like a rectangle, circle, line, or arrow to a PDF document page by
using the following method.
// Square.
docViewer.addAnnotations({
type: 'square',
pageIndex: 0,
borderWidth: 2,
borderColor: '#FF0000',
rect: {
left: 0,
top: 50,
right: 100,
bottom: 100
}
})
// Circle.
docViewer.addAnnotations({
type: 'circle',
pageIndex: 0,
borderWidth: 2,
borderColor: '#FF0000',
rect: {
left: 0,
top: 50,
right: 100,
bottom: 100
}
})
// Line.
docViewer.addAnnotations({
type: 'line',
pageIndex: 0,
borderWidth: 2,
borderColor: '#FF0000',
rect: {
left: 0,
top: 50,
right: 100,
bottom: 100
},
linePoints: [0,50,100,100]
})
Markup
Add a highlight annotation to a PDF Document page by using the following method, and add
other markup annotations in a similar way.
Note: The value of quadPoints are (left,top), (right,top), (left,bottom), and (right,bottom). The
coordinate origin is at the bottom left corner of the page.
docViewer.addAnnotations({
type: 'highlight', // Types include highlight, underline, strikeout,
squiggly.
pageIndex: 0,
opacity: 0.8,
quadPoints: [
{ PointX: 116, PointY: 300 },
{ PointX: 360, PointY: 300 },
{ PointX: 116, PointY: 360 },
{ PointX: 360, PointY: 360 },
],
rect: {
left: 116,
top: 300,
right: 360,
bottom: 360
},
color: "#FF0000",
contents: "test",
})
Ink
Ink is the annotation to draw freely on PDFs with kinds of colors. Follow the method below to
obtain our ink annotation.
docViewer.addAnnotations({
type: 'ink',
pageIndex: 0,
borderWidth: 2,
opacity: 0.8,
borderColor: '#FF0000',
inkPointes: [[
{ PointX: 9.20, PointY: 34 },
{ PointX: 9.20, PointY: 34 },
{ PointX: 9.20, PointY: 33 },
{ PointX: 9.20, PointY: 31 },
{ PointX: 10.20, PointY: 31 },
{ PointX: 11.20, PointY: 30 },
{ PointX: 12.20, PointY: 28 },
{ PointX: 13.2, PointY: 27 },
{ PointX: 13.2, PointY: 26 },
{ PointX: 15.2, PointY: 24 },
{ PointX: 17.2, PointY: 23 },
{ PointX: 22.2, PointY: 19 }
]],
rect: {
left: 9.2,
top: 19,
right: 22.2,
bottom: 34
},
})
Stamp
Add standard and text stamps to a PDF document page by using the following method.
Provide more than 20 standard stamps and dynamic time stamps.
// Standard stamp.
docViewer.addAnnotations({
type: "stamp",
pageIndex: 0,
rect: {
left: 205,
top: 379,
right: 435,
bottom: 431
},
stampType: "standard",
contents: "NotApproved"
})
// Text stamp.
docViewer.addAnnotations({
type: "stamp",
pageIndex: 0,
rect: {
left: 220,
top: 367,
right: 320,
bottom: 412
},
stampType: "text",
contents: "REVISED",
time: "28/07/2023 07:28:28",
stampColor: 1,
stampShape: 0
})
docViewer.addAnnotations({
type: "stamp",
stampType: "image",
pageIndex: 0,
imageBase64,
rect: {
left: 220,
top: 367,
right: 320,
bottom: 412
}
})
}
reader.readAsDataURL(imageBlob);
3.3 Forms
3.3.1 Overview
The Form (or AcroForm) feature allows users to create interactive form fields in a PDF document,
enabling other users to provide information by filling out these fields. Essentially, PDF form fields
are a type of PDF annotation known as Widget annotations. They are utilized to implement
interactive form elements such as buttons, checkboxes, combo boxes, and more.
As PDF is an electronic format, it provides advantages that traditional paper forms do not have.
For instance, users can edit information that has already been entered. Additionally, document
creators can distribute PDF forms over the internet, restrict the content and format entered by
users, as well as programmatically extract and categorize the information filled in by users.
Full Types Supported: Supports all form field types, properties, and appearance settings.
Create, Edit, Delete Form Fields: Perform creation, editing, and deletion operations
programmatically or directly through the UI.
Fill Form Fields: Seamlessly fill form fields using the CPDFViewer or automatically fill them
programmatically.
Form Events: Trigger specified workflows, enabling automation.
Form Flattening: Permanently adds forms to the document as images, ensuring document
appearance stability and preventing further modifications.
Fast UI Integration: Achieve rapid integration and customization through extendable UI
components.
Text Fields: It is a box or space for text fill-in data typically entered from a keyboard. The text
may be set to a single line or multiple lines.
Check Boxes: Check boxes could represent one or more checkboxes that can be checked or
unchecked.
Radio Button: Select one option from the predefined options.
List Box: Select one or more options from the predefined options, similar to the Combo Box.
Combo Box: Select one option from a drop-down list of available text options.
Push Button: Create custom buttons on the PDF document that will perform an action when
pressed.
Signatures: Allow users to add electronic signatures to PDF documents.
More supported form fields are coming soon. Please contact us if you have other form field
requirements.
Text Fields
Text fields could be created, customized, named, filled, downloaded, hidden, and deleted.
Except for the field, ComPDFKit for Web provides options to change the text color,
background color, font, single/multiple lines, and alignment of the text in the text field. Here
is the sample code below to set edit a text field.
docViewer.addAnnotations({
type: "textfield",
rect: {
left: 102,
top: 136,
right: 161,
bottom: 156
},
fieldName: "Text Field1",
isHidden: 0,
contents: 'test',
backgroundColor: "#93B9FD",
color: "#000000",
fontName: "Helvetica",
fontSize: 14,
textAlignment: "left",
isMultiLine: false,
pageIndex: 0
})
Check Boxes
Check boxes could be created, customized, named, filled, downloaded, hidden, and deleted.
Except for the field, ComPDFKit for Web provides options to set the shape of the marker that
appears inside the check box including check, circle, cross, diamond, square, or star. Here is
the sample code below to set edit a check box.
docViewer.addAnnotations({
type: "checkbox",
rect: {
left: 110,
top: 190,
right: 130,
bottom: 210
},
fieldName: "Check Box1",
isHidden: 0,
borderColor: "#43474D",
backgroundColor: "#93B9FD",
borderWidth: 1,
borderStyle: "solid",
checkStyle: 0,
isChecked: 0,
pageIndex: 0
})
Radio Button
Radio buttons could be created, customized, named, filled, downloaded, hidden, and
deleted. Except for the field, ComPDFKit for Web provides options to set the shape of the
marker that appears inside the radio button including check, circle, cross, diamond, square,
or star. Here is the sample code below to edit a radio button.
docViewer.addAnnotations({
type: "radiobutton",
rect: {
left: 150,
top: 190,
right: 170,
bottom: 210
},
fieldName: "Group1",
isHidden: 0,
borderColor: "#43474D",
borderStyle: "solid",
borderWidth: 1,
backgroundColor: "#93B9FD",
checkStyle: 1,
isChecked: 0,
pageIndex: 0
})
List Box
A list box could be created, customized, named, selected, downloaded, hidden, and deleted.
Except for the field, ComPDFKit for Web provides options to change the text color,
background color, and font in the list box. Here is the sample code below to edit a list box.
docViewer.addAnnotations({
type: "listbox",
rect: {
left: 356,
top: 176,
right: 414,
bottom: 203
},
borderColor: "#43474D",
borderStyle: "solid",
borderWidth: 1,
fieldName: "List Box1",
fontName: "Helvetica",
fontSize: 14,
isHidden: 0,
items: [
{
Value: "Item1",
String: "Item1"
},
{
Value: "Item2",
String: "Item2"
}
],
selected: 0,
color: "#000000",
backgroundColor: "#93B9FD",
pageIndex: 0
})
Combo Box
Combo boxes could be created, customized, named, selected, downloaded, hidden, and
deleted. Except for the field, ComPDFKit for Web provides options to change the text color,
background color, and font in the combo box. Here is the sample code below to edit a
combo box.
docViewer.addAnnotations({
type: "combobox",
rect: {
left: 356,
top: 176,
right: 414,
bottom: 203
},
borderColor: "#43474D",
borderStyle: "solid",
borderWidth: 1,
fieldName: "Combo Box1",
fontName: "Helvetica",
fontSize: 14,
isHidden: 0,
items: [
{
Value: "Item1",
String: "Item1"
},
{
Value: "Item2",
String: "Item2"
}
],
selected: 0,
color: "#000000",
backgroundColor: "#93B9FD",
pageIndex: 0
})
Push Button
Push buttons could be created, customized, named, downloaded, hidden, and deleted.
Except for the field, ComPDFKit for Web provides options to change the text color,
background color, and font in the push button or set an action to go to the page or open a
web link. Here is the sample code below to edit a push button.
// Go To Pages.
docViewer.addAnnotations({
type: "pushbutton",
rect: {
left: 356,
top: 176,
right: 414,
bottom: 203
},
backgroundColor: "#93B9FD",
borderColor: "#43474D",
borderStyle: "solid",
borderWidth: 1,
fieldName: "Button1",
fontName: "Helvetica",
fontSize: 14,
actionType: 1,
isHidden: 0,
color: "#000000",
title: "OK",
pageIndex: 0,
destPage: 2
})
// Open a Web Link.
docViewer.addAnnotations({
type: "pushbutton",
rect: {
left: 356,
top: 176,
right: 414,
bottom: 203
},
backgroundColor: "#93B9FD",
borderColor: "#43474D",
borderStyle: "solid",
borderWidth: 1,
fieldName: "Button1",
fontName: "Helvetica",
fontSize: 14,
isHidden: 0,
color: "#000000",
title: "OK",
pageIndex: 0,
actionType: 6,
url: "http://example.com"
})
3.4 Signatures
3.4.1 Overview
It's a legal way to get consent or approval on electronic documents or forms. With Signatures, you
can sign any PDF digital document conveniently and reliably without printing. Various types of
signatures are supported.
Drawn
Drawn signatures let you create your signature with a trackpad or mouse. You can draw your
signature as if you were using a pen or a pencil, and adjust the color and stroke width as you like.
Drawn signatures are ideal for creating natural and personal signatures that match your
handwriting style.
Image
Image signatures let you upload a photo of your handwritten signature and use it to sign PDF
documents. Image signatures are perfect for using your existing signature without having to
redraw it every time.
Typed
Typed signatures let you type your name and choose a font style that suits you. You can select
from a variety of fonts that mimic handwriting, and change the color and stroke width as well.
Typed signatures are convenient and fast for creating simple and elegant signatures that look
professional.
3.5 Security
3.5.1 Overview
The security module provides features including password protection, permission settings, Bates
coding, background, and page header and footer functionalities. Document security is guaranteed
by managing document passwords and permissions, and by adding logos and copyright
information.
PDF Permissions
A PDF user password is used to secure access to PDF documents and requires the correct
password to view the content. It is commonly used to protect confidential reports and financial
documents. The PDF reader also displays document rights such as copying and printing
permissions when a user password is set.
A PDF permission password, also called an owner or master password, protects the permissions
of a PDF document. It restricts actions such as making changes or comments and allows control
over copying, printing, and modification. Permission passwords ensure integrity and allow
management of advanced editing and security settings. They protect the user's copyright and
differ from user passwords.
PDF files' password can be set/removed to encrypt/decrypt the PDF document. Encrypt and
decrypt the password through the following function.
Overlay Comparison: Highlight document differences using colored lines, suitable for
comparing variances in complex drawings.
Content Comparison: Retrieve differential content and locations, suitable for document
comparison with substantial text and image differences.
Overlay Comparison
Generate a comparative result document based on two documents for comparison, marking
document differences with colored lines.
Content Comparison
Compare the content of two documents (including text and images) and present the
differences in a list format.
const data = {
leftFile: documentAFile, // Old file.
rightFile: documentBFile, // New file.
type: 2, // The type of document comparison.
inTransparency: '50', // The transparency of the old file.
newTransparency: '50', // The transparency of of the new file.
coverType: '0', // Blend Modes.
inColor: '#FBBDBF', // The color of the old file.
newColor: '#93B9FD' // The color of of the new file.
}
const data = {
leftFile: documentAFile, // Old file.
rightFile: documentBFile, // New file.
type: 1, // The type of document comparison.
textCompare: true,
imgCompare: true,
replaceColor: '#93B9FD',
insertColor: '#C0FFEC',
deleteColor: '#FBBDBF'
}
Text Editing: Freely insert or delete text, or adjust text properties and positions.
Image Editing: Freely insert or delete images, or adjust image properties and positions.
Search and Replace: Search for a keyword and replace it with other content.
Undo and Redo: Undo or redo any changes.
Custom Menus: Customize content editing context menus.
Fast UI Integration: Achieve quick integration and customization through expandable UI
components.
docViewer.startPDFContentEditMode()
// Insert Text.
docViewer.contentEditAnnotationsManager.addTextEditor({
pageNumber: 1,
rect: {
left: 240,
top: 32,
right: 300,
bottom: 48
},
fontData: {
fontName: 'Helvetica',
fontSize: 14,
r: 0,
g: 0,
b: 0,
opacity: 1,
isBold: 0,
italic: 0,
},
alignType: 2
})
docViewer.endPDFContentEditMode()
Insertion or Deletion of Pages: Insert or delete pages within the document to meet specific
layout requirements.
Structural Adjustments: Adjust the sequence or rotate the orientation of pages to meet
specific display or printing needs.
Multi-Document Collaboration: Extract pages from one document and insert them into
another, facilitating collaboration and content integration.
Insert Pages
Insert blank pages or pages from another document into the target document.
Delete Pages
Rotate Pages
Replace Pages
Replace specified pages in the target document with pages from another document.
Extract Pages
Copy Pages
// Rotate the first page 90 degrees clockwise, with each unit of rotation
representing a 90-degree clockwise turn.
const pagesIndexToRotate = [0]
const rotation = 1;
docViewer.rotatePages(pagesIndexToRotate, rotation)
3.8.5 Replace Pages
The steps to replace pages are as follows:
// Insert the first page of another document into the original document's first-
page position to complete the replacement.
const file = {...} // File Object.
const pageIndexToInsert = 0
const pagesIndexToInsert = 'all' // Insert the range of PDF pages.
// Extract the first, third, and fourth pages of the original document and save
it in a new document.
const pagesIndexToExtract = [1, '3-4'] // Extract the range of the page.
const data = await docViewer.extractPages(pagesIndexToExtract)
const pageNumber = 1;
const pagePoint = {
x: 0,
y: 0
};
const pageNumber = 1;
const windowPoint = {
x: 47,
y: 64
};
docViewer.addEvent('click', handleClick)
4 Support
4.1 Reporting Problems
Thank you for your interest in ComPDFKit for Web, the only easy-to-use but powerful
development solution to integrate high quality PDF rendering and editing capabilities to your web
app. If you encounter any technical questions or bug issues when using ComPDFKit for Web,
please submit the problem report to the ComPDFKit team. More information as follows would
help us to solve your problem:
Contact ComPDFKit:
Thanks,