Skip to content

Commit b21880e

Browse files
committed
v2.2.1
1 parent 7b4f844 commit b21880e

File tree

176 files changed

+1947
-1449
lines changed

Some content is hidden

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

176 files changed

+1947
-1449
lines changed
847 Bytes
Binary file not shown.
26.2 KB
Binary file not shown.

ComPDFKit_Tools/README.md

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ In addition to the `ComPDFKit_Tools` module source code, we also provide a Gradl
1111

1212
```diff
1313
dependencies {
14-
implementation 'com.compdf:compdfkit:2.1.3'
15-
implementation 'com.compdf:compdfkit-ui:2.1.3'
16-
+ implementation 'com.compdf:compdfkit-tools:2.1.3'
14+
implementation 'com.compdf:compdfkit:2.2.1'
15+
implementation 'com.compdf:compdfkit-ui:2.2.1'
16+
+ implementation 'com.compdf:compdfkit-tools:2.2.1'
1717
}
1818
```
1919

2020
## Usage
2121

2222
The ComPDFKit_Tools module provides two main components: [CPDFDocumentActivity](./src/main/java/com/compdfkit/tools/common/pdf/CPDFDocumentActivity.java) and [CPDFDocumentFragment.java](./src/main/java/com/compdfkit/tools/common/pdf/CPDFDocumentFragment.java). These components enable you to easily implement PDF functionalities.
2323

24-
* **CPDFDocumentActivity.java**
24+
### CPDFDocumentActivity
2525

2626
Use CPDFDocumentActivity to display a PDF document:
2727
```java
@@ -34,7 +34,7 @@ CPDFDocumentActivity.startActivity(context, uri, password, configuration);
3434
CPDFDocumentActivity.startActivity(context, filePath, password, configuration);
3535
```
3636

37-
* **CPDFDocumentFragment.java**
37+
### CPDFDocumentFragment
3838

3939
Use CPDFDocumentFragment to load a PDF document into a Fragment:
4040
```java
@@ -53,5 +53,80 @@ CPDFDocumentFragment documentFragment = CPDFDocumentFragment.newInstance(
5353
configuration);
5454
```
5555

56+
### Watermark
5657

58+
If you only need to use the watermark function, you can use `CWatermarkEditDialog` alone. The following is an example of use:
5759

60+
```java
61+
// The example uses the sample document located in the assets directory
62+
String path = CFileUtils.getAssetsTempFile(this, "test.pdf", "test.pdf");
63+
CWatermarkEditDialog editDialog = CWatermarkEditDialog.newInstance();
64+
// You can pass the file path or URI of the PDF document directly
65+
editDialog.setDocument(path, null);
66+
// Or pass an existing CPDFDocument object
67+
// editDialog.setDocument(document);
68+
editDialog.setPageIndex(0);
69+
// Set the saving path of the document with watermark added. If not set, when you click [Save],
70+
// a file directory selection pop-up window will pop up for saving.
71+
File saveFile = new File(getFilesDir(), "temp/test.pdf");
72+
editDialog.setSavePath(saveFile.getAbsolutePath());
73+
editDialog.setDefaultText("ComPDFKit");
74+
// editDialog.setDefaultImagePath("xxx.png");
75+
editDialog.setCompleteListener(pdfFile -> {
76+
if (!TextUtils.isEmpty(pdfFile)){
77+
openPDF(pdfFile);
78+
}
79+
editDialog.dismiss();
80+
});
81+
editDialog.show(getSupportFragmentManager(), "addWatermarkDialog");
82+
83+
private void openPDF(String path){
84+
CPDFDocumentActivity.startActivity(this, path, "",
85+
CPDFConfigurationUtils.normalConfig(this, "tools_default_configuration.json"));
86+
}
87+
```
88+
89+
<img src="screenshots/img_2.jpg" style="zoom: 30%;" />
90+
91+
### Encryption
92+
93+
If you need to set an opening password or permission password for a document, you can do so through `CDocumentEncryptionDialog`. The following is an example:
94+
95+
```java
96+
private void encryption(){
97+
String path = CFileUtils.getAssetsTempFile(this, "test_SetPassword.pdf", "test_SetPassword.pdf");
98+
99+
CPDFDocument document = new CPDFDocument(this);
100+
document.open(path);
101+
102+
CPDFDocument.PDFDocumentPermissions permission = document.getPermissions();
103+
//only has user permission
104+
if (permission == CPDFDocument.PDFDocumentPermissions.PDFDocumentPermissionsUser) {
105+
// You can enter the owner permissions password and reload the pdf to gain owner permissions
106+
CInputOwnerPwdDialog inputOwnerPwdDialog = CInputOwnerPwdDialog.newInstance();
107+
inputOwnerPwdDialog.setDocument(document);
108+
inputOwnerPwdDialog.setConfirmClickListener(ownerPassword -> {
109+
inputOwnerPwdDialog.dismiss();
110+
document.reload(ownerPassword);
111+
showEncryptionDialog(document);
112+
});
113+
inputOwnerPwdDialog.show(getSupportFragmentManager(), "inputOwnerPwdDialog");
114+
return;
115+
}
116+
showEncryptionDialog(document);
117+
}
118+
119+
private void showEncryptionDialog(CPDFDocument document){
120+
CDocumentEncryptionDialog encryptionDialog = CDocumentEncryptionDialog.newInstance();
121+
encryptionDialog.setDocument(document);
122+
encryptionDialog.setEncryptionResultListener((isRemoveSecurity, result, filePath, password) -> openPDF(filePath));
123+
encryptionDialog.show(getSupportFragmentManager(), "showEncryptionDialog");
124+
}
125+
126+
private void openPDF(String path){
127+
CPDFDocumentActivity.startActivity(this, path, "",
128+
CPDFConfigurationUtils.normalConfig(this, "tools_default_configuration.json"));
129+
}
130+
```
131+
132+
<img src="screenshots/img_3.jpg" style="zoom: 30%;" />

ComPDFKit_Tools/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ dependencies {
5454
api project(path:':ComPDFKit_Repo:compdfkit')
5555
api project(path:':ComPDFKit_Repo:compdfkit-ui')
5656
// or use
57-
// api ('com.compdf:compdfkit:2.2.0')
58-
// api ('com.compdf:compdfkit-ui:2.2.0')
57+
// api ('com.compdf:compdfkit:2.2.1')
58+
// api ('com.compdf:compdfkit-ui:2.2.1')
5959
api 'com.github.bumptech.glide:glide:4.15.1'
6060
annotationProcessor 'com.github.bumptech.glide:compiler:4.15.1'
6161
api 'androidx.documentfile:documentfile:1.0.1'

ComPDFKit_Tools/screenshots/img_2.jpg

488 KB
Loading

ComPDFKit_Tools/screenshots/img_3.jpg

147 KB
Loading

ComPDFKit_Tools/src/main/java/com/compdfkit/tools/annotation/pdfannotationbar/CAnnotationToolbar.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import androidx.annotation.NonNull;
2424
import androidx.annotation.Nullable;
2525
import androidx.appcompat.widget.AppCompatImageView;
26-
import androidx.fragment.app.FragmentManager;
26+
import androidx.fragment.app.FragmentActivity;
2727
import androidx.recyclerview.widget.LinearLayoutManager;
2828
import androidx.recyclerview.widget.RecyclerView;
2929

@@ -67,8 +67,6 @@ public class CAnnotationToolbar extends FrameLayout {
6767

6868
private CPDFViewCtrl pdfView;
6969

70-
private FragmentManager fragmentManager;
71-
7270
private COnAnnotationChangeListener annotationChangeListener;
7371

7472
private LinearLayout llAnnotTools;
@@ -120,10 +118,6 @@ public void initWithPDFView(CPDFViewCtrl pdfView) {
120118
// redoUndoManager();
121119
}
122120

123-
public void setFragmentManager(FragmentManager fragmentManager) {
124-
this.fragmentManager = fragmentManager;
125-
}
126-
127121
private void showAnnotStyleDialog() {
128122
CViewUtils.hideKeyboard(this);
129123
CStyleManager styleManager = new CStyleManager(pdfView);
@@ -157,7 +151,10 @@ public void onChangeOpacity(int opacity) {
157151
}
158152
}
159153
});
160-
dialogFragment.show(fragmentManager, "annotStyleDialogFragment");
154+
FragmentActivity fragmentActivity = CViewUtils.getFragmentActivity(getContext());
155+
if (fragmentActivity != null) {
156+
dialogFragment.show(fragmentActivity.getSupportFragmentManager(), "annotStyleDialogFragment");
157+
}
161158
}
162159

163160
private void switchAnnotationType(CAnnotToolBean bean) {

ComPDFKit_Tools/src/main/java/com/compdfkit/tools/annotation/pdfannotationlist/CPDFAnnotationListFragment.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616
import android.os.Environment;
1717
import android.text.TextUtils;
1818
import android.view.Gravity;
19-
import android.view.LayoutInflater;
2019
import android.view.View;
21-
import android.view.ViewGroup;
2220
import android.widget.ProgressBar;
2321

2422
import androidx.activity.result.ActivityResultLauncher;
2523
import androidx.activity.result.contract.ActivityResultContracts;
2624
import androidx.annotation.NonNull;
2725
import androidx.annotation.Nullable;
2826
import androidx.constraintlayout.widget.ConstraintLayout;
29-
import androidx.fragment.app.Fragment;
3027
import androidx.recyclerview.widget.LinearLayoutManager;
3128
import androidx.recyclerview.widget.RecyclerView;
3229

@@ -38,6 +35,7 @@
3835
import com.compdfkit.tools.annotation.pdfannotationlist.data.CPDFAnnotDatas;
3936
import com.compdfkit.tools.annotation.pdfannotationlist.dialog.CPDFEditReplyDialogFragment;
4037
import com.compdfkit.tools.annotation.pdfannotationlist.dialog.CPDFReplyDetailsDialogFragment;
38+
import com.compdfkit.tools.common.basic.fragment.CBasicThemeFragment;
4139
import com.compdfkit.tools.common.interfaces.COnSetPDFDisplayPageIndexListener;
4240
import com.compdfkit.tools.common.utils.CFileUtils;
4341
import com.compdfkit.tools.common.utils.CLog;
@@ -54,7 +52,7 @@
5452
import java.util.List;
5553

5654

57-
public class CPDFAnnotationListFragment extends Fragment {
55+
public class CPDFAnnotationListFragment extends CBasicThemeFragment {
5856

5957
private RecyclerView rvAnnotation;
6058

@@ -111,14 +109,17 @@ public void initWithPDFView(CPDFViewCtrl pdfView) {
111109
this.pdfView = pdfView;
112110
}
113111

114-
@Nullable
112+
113+
@Override
114+
protected int layoutId() {
115+
return R.layout.tools_bota_annotation_list_fragment;
116+
}
117+
115118
@Override
116-
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
117-
View rootView = inflater.inflate(R.layout.tools_bota_annotation_list_fragment, container, false);
119+
protected void onCreateView(View rootView) {
118120
rvAnnotation = rootView.findViewById(R.id.rv_annotation);
119121
clEmptyView = rootView.findViewById(R.id.cl_annot_empty_view);
120122
progressBar = rootView.findViewById(R.id.progress_bar);
121-
return rootView;
122123
}
123124

124125
@Override

ComPDFKit_Tools/src/main/java/com/compdfkit/tools/annotation/pdfannotationlist/adapter/CPDFAnnotReplyListAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
2+
* Copyright © 2014-2025 PDF Technologies, Inc. All Rights Reserved.
33
*
44
* THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
55
* AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.

ComPDFKit_Tools/src/main/java/com/compdfkit/tools/annotation/pdfannotationlist/data/CPDFAnnotDatas.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
2+
* Copyright © 2014-2025 PDF Technologies, Inc. All Rights Reserved.
33
* <p>
44
* THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
55
* AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.

0 commit comments

Comments
 (0)