Skip to content

Commit 5b16c6a

Browse files
committed
compdfkit(rn) - v2.3.0
1 parent 02e0545 commit 5b16c6a

File tree

77 files changed

+4256
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4256
-255
lines changed

API.md

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,33 @@ Promise Parameters:
401401
const saveResult = await pdfReaderRef.current.save();
402402
```
403403

404+
#### saveAs
405+
406+
Saves the document to the specified directory.
407+
408+
Parameters:
409+
410+
| Name | Type | Description |
411+
| -------------- | ------- | ------------------------------------------------------------ |
412+
| savePath | string | Specifies the path where the document should be saved. |
413+
| removeSecurity | boolean | Whether to remove the document's password. |
414+
| fontSubset | boolean | Whether to embed font subsets into PDF. Defaults to **true**. |
415+
416+
Returns a Promise.
417+
418+
| Name | Type | Description |
419+
| ------ | ---- | ------------------------------------------------------------ |
420+
| result | bool | Returns `true` if the document is saved successfully, otherwise `false`. |
421+
422+
```tsx
423+
const savePath = '/data/user/0/com.compdfkit.flutter.example/cache/temp/PDF_Document.pdf';
424+
// android platfrom support uri, for example:
425+
const savePath = 'content://media/external/file/1000045118';
426+
const removeSecurity = false;
427+
const fontSubset = true;
428+
const result = await pdfReaderRef.current?._pdfDocument.saveAs(savePath, removeSecurity, fontSubset);
429+
```
430+
404431
#### onSaveDocument
405432

406433
function, optional
@@ -992,6 +1019,78 @@ Promise Parameters:
9921019
const pageCount = await pdfReaderRef.current?._pdfDocument.getPageCount();
9931020
```
9941021

1022+
#### importDocument
1023+
1024+
Imports another PDF document and inserts it at a specified position in the current document.
1025+
1026+
Parameters:
1027+
1028+
| Name | Type | Description |
1029+
| -------------- | ------------- | ------------------------------------------------------------ |
1030+
| filePath | string | The path of the PDF document to import. Must be a valid, accessible path on the device. |
1031+
| pages | Array[number] | The collection of pages to import, represented as an array of integers. If `null` or an empty array is passed, the entire document will be imported. |
1032+
| insertPosition | number | The position to insert the external document into the current document. This value must be provided. If not specified, the document will be inserted at the end of the current document. |
1033+
| password | string | The password for the document, if it is encrypted. If the document is not encrypted, an empty string `''` can be passed. |
1034+
1035+
Returns a Promise.
1036+
1037+
| Name | Type | Description |
1038+
| ------ | ---- | ------------------------------------------------------------ |
1039+
| result | bool | Returns a `Promise<boolean>` indicating whether the document import was successful.<br>\- `true` indicates success<br>\- `false` or an error indicates failure |
1040+
1041+
```tsx
1042+
// Define the file path of the document to import
1043+
// For local files (e.g., from app cache):
1044+
const filePath = '/data/user/0/com.compdfkit.flutter.example/cache/temp/PDF_Document.pdf';
1045+
// For Android content URIs (e.g., from media storage):
1046+
const filePath = 'content://media/external/file/1000045118';
1047+
1048+
// Specify the pages to import. An empty array [] imports all pages.
1049+
// In this example, only the first page (index 0) is imported.
1050+
const pages = [0];
1051+
1052+
// Define the position to insert the imported pages.
1053+
// 0 means inserting at the beginning of the document.
1054+
const insertPosition = 0;
1055+
1056+
// Provide the document password if encrypted. Leave empty if not required.
1057+
const password = '';
1058+
1059+
// Import the document into the PDF reader.
1060+
const importResult = await pdfReaderRef.current?._pdfDocument.importDocument(
1061+
filePath,
1062+
pages,
1063+
insertPosition,
1064+
password
1065+
);
1066+
```
1067+
1068+
#### splitDocumentPages
1069+
1070+
Splits the specified pages from the current document and saves them as a new document.
1071+
1072+
This function extracts the given pages from the current PDF document and saves them as a new document at the provided save path.
1073+
1074+
Parameters:
1075+
1076+
| Name | Type | Description |
1077+
| -------- | ------------- | ---------------------------------------------- |
1078+
| savePath | string | The path where the new document will be saved. |
1079+
| pages | Array[number] | Pages to extract from the current document. |
1080+
1081+
Returns a Promise.
1082+
1083+
| Name | Type | Description |
1084+
| ------ | ---- | ------------------------------------------------------------ |
1085+
| result | bool | A Promise that resolves to `true` if the operation is successful, or `false` if it fails. |
1086+
1087+
```tsx
1088+
const savePath = '/data/user/0/com.compdfkit.flutter.example/cache/temp/PDF_Document.pdf';
1089+
// Pages to extract from the current document
1090+
const pages = [0, 1, 2];
1091+
const result = await pdfReaderRef.current?.splitDocumentPages(savePath, pages);
1092+
```
1093+
9951094
### Annotations
9961095

9971096
#### import Annotations
@@ -1048,6 +1147,54 @@ Promise Parameters:
10481147
const removeResult = await pdfReaderRef.current?.removeAllAnnotations();
10491148
```
10501149

1150+
#### getAnnotations
1151+
1152+
Retrieves all annotations on the current page.
1153+
1154+
This method fetches all annotations present on the current page of the PDF document and returns a list of corresponding CPDFAnnotation instances.
1155+
1156+
Promise Parameters:
1157+
1158+
| Name | Type | Description |
1159+
| ----------- | ---------------- | ------------------------------------------------------------ |
1160+
| annotations | CPDFAnnotation[] | A promise that resolves with all annotations on the current page, or an empty array if retrieval fails. |
1161+
1162+
```tsx
1163+
// Page index, where 0 represents the first page
1164+
const pageIndex = 0;
1165+
1166+
// Retrieve the page object from the document
1167+
const page = pdfReaderRef?.current?._pdfDocument.pageAtIndex(pageIndex);
1168+
1169+
// Fetch all annotations on the specified page
1170+
const annotations = await page?.getAnnotations();
1171+
```
1172+
1173+
#### flattenAllPages
1174+
1175+
Flatten all pages of the current document.
1176+
1177+
Parameters:
1178+
1179+
| Name | Type | Description |
1180+
| ---------- | ------- | ------------------------------------------------------------ |
1181+
| savePath | string | The path to save the flattened document. On Android, you can pass a Uri. |
1182+
| fontSubset | boolean | Whether to include the font subset when saving. |
1183+
1184+
Returns a Promise.
1185+
1186+
| Name | Type | Description |
1187+
| ------ | ------- | ------------------------------------------------------------ |
1188+
| result | boolean | Returns 'true' if the flattened document is saved successfully, otherwise 'false'. |
1189+
1190+
```tsx
1191+
const savePath = 'file:///storage/emulated/0/Download/flatten.pdf';
1192+
// or use Uri on the Android Platform.
1193+
const savePath = await ComPDFKit.createUri('flatten_test.pdf', 'compdfkit', 'application/pdf');
1194+
const fontSubset = true;
1195+
const result = await pdfReaderRef.current?._pdfDocument.flattenAllPages(savePath, fontSubset);
1196+
```
1197+
10511198
### Forms
10521199

10531200
#### importWidgets
@@ -1090,6 +1237,95 @@ Promise Parameters:
10901237
const exportXfdfFilePath = await pdfReaderRef.current?.exportWidgets();
10911238
```
10921239

1240+
#### getWidgets
1241+
1242+
Retrieves all form widgets on the current page.
1243+
1244+
This method fetches all form widgets present on the current page of the PDF document and returns a list of corresponding CPDFWidget instances.
1245+
1246+
Returns a Promise.
1247+
1248+
**Promise Parameters:**
1249+
1250+
| Name | Type | Description |
1251+
| ------- | ------------ | ------------------------------------------------------- |
1252+
| widgets | CPDFWidget[] | **true**: import successful,``**false**: import failed. |
1253+
1254+
```tsx
1255+
const pageIndex = 0;
1256+
const page = pdfReaderRef?.current?._pdfDocument.pageAtIndex(pageIndex);
1257+
const widgets = await page?.getWidgets();
1258+
```
1259+
1260+
**Related Widgets**
1261+
1262+
| Class | Description |
1263+
| --------------------- | ------------------------------- |
1264+
| CPDFWidget | Base class for all form widgets |
1265+
| CPDFTextWidget | Text input field widget |
1266+
| CPDFSignatureWidget | Signature widget |
1267+
| CPDFRadiobuttonWidget | Radio button widget |
1268+
| CPDFPushbuttonWidget | Button widget |
1269+
| CPDFListboxWidget | List box widget |
1270+
| CPDFCheckboxWidget | Checkbox widget |
1271+
| CPDFComboboxWidget | Combo box widget |
1272+
1273+
#### Fill Form Fields
1274+
1275+
ComPDFKit supports programmatically filling form fields in a PDF document.
1276+
1277+
The steps to fill in form fields using code are as follows:
1278+
1279+
1. Get the page object of the form to be filled in from CPDFDocument.
1280+
1281+
2. Retrieve all forms from the page object.
1282+
1283+
3. Traverse all forms to find the one to be filled in.
1284+
1285+
4. Modify the form field contents as needed.
1286+
1287+
This example shows how to fill in form fields:
1288+
1289+
```tsx
1290+
const pageIndex = 0;
1291+
// Retrieve the page object of the first page
1292+
const cpdfPage: CPDFPage = pdfReaderRef?.current?._pdfDocument.pageAtIndex(pageIndex);
1293+
1294+
// Retrieve all form widgets on the current page
1295+
const widgets = await page?.getWidgets();
1296+
1297+
// Fill in the text field content
1298+
// Assume that there is a text field form on the current page and retrieve the CPDFTextWidget object
1299+
const textWidget = widgets[0] as CPDFTextWidget;
1300+
// Set the text field content to "Hello World"
1301+
await textWidget.setText('Hello World');
1302+
// Refresh the appearance of the form to apply changes, this step is necessary
1303+
await textWidget.updateAp();
1304+
1305+
// Modify the radio button's checked state
1306+
const radioButtonWidget = widgets[0] as CPDFRadiobuttonWidget;
1307+
// Set the radio button to checked
1308+
await radioButtonWidget.setChecked(true);
1309+
// Refresh the appearance of the radio button
1310+
await radioButtonWidget.updateAp();
1311+
1312+
// Modify the checkbox's checked state
1313+
const checkboxWidget = widgets[0] as CPDFCheckboxWidget;
1314+
// Set the checkbox to checked
1315+
await checkboxWidget.setChecked(true);
1316+
// Refresh the appearance of the checkbox
1317+
await checkboxWidget.updateAp();
1318+
1319+
// Add an electronic signature to the signature form
1320+
const signatureWidget = widgets[0] as CPDFSignatureWidget;
1321+
// Android-supported URI format:
1322+
await signatureWidget.addImageSignature('content://media/external/images/media/123');
1323+
// Or file path:
1324+
await signatureWidget.addImageSignature('/path/to/image');
1325+
// Refresh the appearance of the signature form
1326+
await signatureWidget.updateAp();
1327+
```
1328+
10931329
### Security
10941330

10951331
#### isEncrypted
@@ -1217,3 +1453,4 @@ Returns a Promise.
12171453
```tsx
12181454
const encryptAlgo = await pdfReaderRef.current?._pdfDocument.getEncryptAlgo();
12191455
```
1456+

CHANGELOG.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
## Newest Release
22

3+
### 2.3.0 - 21 Mar. 2025
4+
5+
1. Added the features support for ComPDFKit PDF SDK for iOS iOS V2.3.0.
6+
2. Added the features support for ComPDFKit PDF SDK for Android Android V2.3.0.
7+
3. Added import/export form data API, supporting XFDF format files.
8+
4. Added the ability to create text input fields and insert images by clicking on a page area in content editing mode.
9+
5. Added navigation system print API.
10+
6. Added import PDF document API.
11+
7. Added split PDF document API.
12+
8. Added fill form content API.
13+
9. Added `saveAs` API.
14+
10. Added API to retrieve all annotations and form data on a page.
15+
11. Added document flattening API.
16+
12. Fixed a crash issue when editing or deleting text in certain documents.
17+
13. Fixed the border display issue after completing a free text annotation.
18+
14. Fixed an issue where the LaBan Key input method could not delete the last character while editing text.
19+
15. Fixed text garbling issues in content editing mode.
20+
16. Fixed an issue where form field content was not displayed in some documents.
21+
17. Fixed the issue that the zoomed-in page area did not follow the zooming when jumping to draw a rectangular area.
22+
18. Fixed the issue of Chinese garbled characters in the form name.
23+
19. Fixed the issue where the prompt did not appear for scanned PDF documents on iOS.
24+
25+
## Previous Release
26+
327
### 2.3.0-beta.1 - 28 Feb. 2025
428

529
* Added import/export interface for form data in XFDF format files.
@@ -8,13 +32,8 @@
832
* Fixed issue where editing or deleting text in some documents caused crashes.
933
* Fixed issue with the border appearing after completing FreeText annotation.
1034
* Fixed issue where the LaBan Key input method deletes the last character when editing text.
11-
1235
* Fixed the issue of text garbling in content editing mode.
1336

14-
15-
16-
## Previous Release
17-
1837
### 2.2.2 - 19 Feb. 2025
1938

2039
* Added the features support for ComPDFKit PDF SDK for iOS iOS V2.2.2.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ open ios/Podfile
115115
```diff
116116
target 'MyApp' do
117117
# ...
118-
+ pod "ComPDFKit", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.3.0-beta.podspec'
119-
+ pod "ComPDFKit_Tools", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.3.0-beta.podspec'
118+
+ pod "ComPDFKit", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.3.0.podspec'
119+
+ pod "ComPDFKit_Tools", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.3.0.podspec'
120120
# ...
121121
end
122122
```
@@ -126,8 +126,8 @@ end
126126
```diff
127127
target 'MyApp' do
128128
# ...
129-
+ pod 'ComPDFKit', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.3.0-beta'
130-
+ pod 'ComPDFKit_Tools', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.3.0-beta'
129+
+ pod 'ComPDFKit', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.3.0'
130+
+ pod 'ComPDFKit_Tools', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.3.0'
131131
# ...
132132
end
133133
```

android/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ dependencies {
8787
compileOnly fileTree(include: ['*.jar','*.aar'], dir: 'libs')
8888
implementation "com.facebook.react:react-native:+"
8989

90-
api "com.compdf:compdfkit-tools:2.3.0-SNAPSHOT"
90+
api "com.compdf:compdfkit-tools:2.3.0"
9191
api 'com.github.bumptech.glide:glide:4.15.1'
9292
annotationProcessor 'com.github.bumptech.glide:compiler:4.15.1'
9393
api 'androidx.documentfile:documentfile:1.0.1'
9494
api 'androidx.appcompat:appcompat:1.6.1'
9595
api 'com.google.android.material:material:1.8.0'
9696
api 'androidx.constraintlayout:constraintlayout:2.1.4'
9797
}
98+
configurations.all { resolutionStrategy.cacheChangingModulesFor 0, 'seconds' }
99+
98100

0 commit comments

Comments
 (0)