Content Watermarks: Insertion and Rendering Performance
This guide summarizes common questions and optimization tips for content watermarks on Android, focusing on insertion and rendering performance and stability. “Content watermark” here means watermarks inserted as page content and rendered with the page—not the Watermark annotation type in the PDF specification.
Common Issues
When adding custom watermarks, you may see:
- Insertion/rendering delay: Repeated page parsing or recreating the same watermark objects hurts performance;
- Incomplete watermark display: During frequent refresh, the SDK throttles updates for efficiency; if one refresh has not finished, the next may not apply in time.
Optimization Tips
1) Insert watermarks with com.foxit.sdk.Task
- Run watermark insertion logic inside a
Task; - Continue your app logic after the SDK internal thread completes to reduce partial-missing cases.
2) Load and insert watermarks in segments
Preload and insert by page range—for example, 10 pages per segment:
- Insert when loading pages 1–10 the first time;
- When the user moves to page 11, preload pages 11–20 and insert.
When the user moves to the next segment, watermarks are usually already inserted, so rendering is more stable and efficient.
Reference Implementation (Excerpt)
java
private static final int PAGING_SIZE = 10;
private final List<Integer> mLoadPageNums = new ArrayList<>();
private class InsertWatermarkTask extends Task {
private final PDFViewCtrl mViewCtrl;
private final int mPageNum;
private final List<Integer> mInsertedPages = new ArrayList<>();
private InsertWatermarkTask(PDFViewCtrl viewCtrl, int pageNum) {
super(new CallBack() {
@Override
public void result(Task task) {
InsertWatermarkTask t = (InsertWatermarkTask) task;
for (int pageIndex : t.mInsertedPages) {
if (t.mViewCtrl.isPageVisible(pageIndex)) {
int w = t.mViewCtrl.getPageViewWidth(pageIndex);
int h = t.mViewCtrl.getPageViewHeight(pageIndex);
t.mViewCtrl.refresh(pageIndex, new Rect(0, 0, w, h));
}
}
}
});
this.mViewCtrl = viewCtrl;
this.mPageNum = pageNum;
}
@Override
protected void execute() {
// Iterate by page segment, parse pages, insert watermarks, record page indices in mInsertedPages
}
}NOTE
- Initialize watermark objects once and reuse them when empty to avoid duplicate creation.
- Trigger segmented insertion with page visibility events such as
PDFViewCtrl.IPageEventListener.onPageVisible.