How to Customize Settings on Document Loading in Angular PDF Viewer?
This article explains how to customize the form field settings, such as text field settings, upon document loading in the Syncfusion® PDF Viewer component within an Angular PDF Viewer application.
After following this guide, users will be able to set various properties, like the tooltip, font size, and value for form fields in the PDF Viewer programmatically upon document load.
Solution:
To customize form field settings when the PDF document is loaded, use the documentLoad event in the PDF Viewer. Inside this event, access the viewer instance and set the textFieldSettings property, which allows you to define properties like name, tooltip, value, fontSize, and color for text fields. This ensures the specified settings are applied automatically when the document is loaded, allowing for customized form field appearances and behavior.
Prerequisites:
Before diving into the implementation, ensure that the following steps are completed:
-
Syncfusion PDF Viewer Setup: Make sure the Syncfusion PDF Viewer is installed and set up in your Angular project. Follow the Getting Started with Syncfusion PDF Viewer for Angular guide if you haven’t already.
-
Basic Knowledge of Angular: Familiarity with Angular components and the basic setup of Angular projects will help you follow along with the implementation.
Code Snippets
Install and Configure Syncfusion PDF Viewer
First, install the necessary Syncfusion PDF Viewer modules and services in your Angular project and import them as needed.
import { Component, OnInit } from '@angular/core';
import {
LinkAnnotationService,
BookmarkViewService,
MagnificationService,
ThumbnailViewService,
ToolbarService,
NavigationService,
AnnotationService,
TextSearchService,
TextSelectionService,
FormFieldsService,
FormDesignerService,
PrintService
} from '@syncfusion/ej2-angular-pdfviewer';
Create the PDF Viewer Component
In your component’s HTML file, set up the PDF Viewer element to display the PDF document:
@Component({
selector: 'app-root',
template: `
<div class="content-wrapper">
<ejs-pdfviewer
id="pdfViewer"
[resourceUrl]="resourceUrl"
[documentPath]="document"
(documentLoad)="documentLoad()"
style="height: 640px; display: block;">
</ejs-pdfviewer>
</div>
`,
providers: [
LinkAnnotationService,
BookmarkViewService,
MagnificationService,
ThumbnailViewService,
ToolbarService,
NavigationService,
AnnotationService,
TextSearchService,
TextSelectionService,
FormFieldsService,
FormDesignerService,
PrintService
]
})
Customize Form Field Settings on Document Load
In the documentLoad() method, use the following code to customize form field settings for the document after it loads. This includes setting properties like tooltip, font size, value, and text color for text fields.
export class AppComponent implements OnInit {
public document: string = 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf';
public resourceUrl: string = 'https://cdn.syncfusion.com/ej2/28.1.33/dist/ej2-pdfviewer-lib';
ngOnInit(): void { }
// Function to configure PDF viewer settings when the document loads
public documentLoad() {
var viewer = (<any>document.getElementById("pdfViewer")).ej2_instances[0];
// Set text field settings for the PDF viewer
viewer.textFieldSettings = {
name: 'TextboxField',
tooltip: 'Syncfusion',
value: 'Syncfusion',
fontSize: 15,
color: 'red',
};
}
}
Key Features Used in the Code:
- textFieldSettings: The textFieldSettings property is used to define the attributes of the text fields in the PDF, such as tooltip, value, font size, and color.
- documentLoad Event: The documentLoad event is triggered when the PDF document is loaded. It provides an opportunity to configure various PDF viewer settings programmatically.
Sample Link:
You can find the full sample in our GitHub repository.
Conclusion:
I hope you enjoyed learning how to customize settings on document loading in Angular PDF Viewer.
You can refer to Angular PDF Viewer feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Angular PDF Viewer Example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!