本页内容
编辑文本和图像属性
ComPDFKit 支持修改文本与图像属性。您可以在CPDFReaderView
自定义的上下文菜单getEditSelectTextContentView
方法中来设置文本和图像属性。
编辑文本属性
ComPDFKit 支持修改文本属性,如字体大小、名称、颜色、对齐方式、斜体、粗体、透明度等。以及创建和删除文本的下划线、删除线。
以下是如何将文本设置为12pt、红色和粗体的示例代码:
java
public class DemoContextMenuHelper extends CPDFContextMenuShowHelper {
public DemoContextMenuHelper(CPDFReaderView cpdfReaderView) {
super(cpdfReaderView);
}
@Override
public View getEditSelectTextContentView(CPDFPageView pageView, LayoutInflater layoutInflater, CPDFEditSelections selections) {
View contentView = ....
invokeOnClickListener(contentView, view ->{
if (view.getId() == R.id.edit_attr){
CPDFEditTextSelections textSelections = (CPDFEditTextSelections) selections;
textSelections.setFontSize(12);
textSelections.setColor(Color.RED);
textSelections.setBold(true);
textSelections.setItalic(true);
textSelections.setAlign(CPDFEditTextArea.PDFEditAlignType.PDFEditAlignLeft);
textSelections.setTransparancy(255);
textSelections.setFontName(CPDFEditTextArea.FontTimesRoman);
}
}, R.id.edit_attr);
return contentView;
}
}
kotlin
public class DemoContextMenuHelper(readerView: CPDFReaderView?) : CPDFContextMenuShowHelper(readerView) {
override fun getEditTextAreaContentView(
pageView: CPDFPageView?,
layoutInflater : LayoutInflater?,
selections: CPDFEditSelections?
): View {
View contentView = ...
invokeOnClickListener(pageView, {view ->
if (view.id == R.id.edit) {
val textSelections = selections as CPDFEditTextSelections
textSelections.fontSize = 12F
textSelections.color = Color.RED
textSelections.isBold = true
textSelections.isItalic = true
textSelections.align = CPDFEditTextArea.PDFEditAlignType.PDFEditAlignLeft
textSelections.transparancy = 255F
textSelections.fontName = CPDFEditTextArea.FontTimesRoman
}
}, R.id.edit)
return contentView
}
}
以下是创建和删除文本的下划线、删除线的示例代码:
java
CPDFEditTextSelections textSelections = (CPDFEditTextSelections)selections;
// 创建文本的下划线和删除线
textSelections.addUnderline();
textSelections.addStrikethrough();
// 删除文本的下划线和删除线
textSelections.removeUnderline();
textSelections.removeStrikethrough();
kotlin
val textSelections = selections as CPDFEditTextSelections
// 创建文本的下划线和删除线
textSelections.addUnderline()
textSelections.addStrikethrough()
// 删除文本的下划线和删除线
textSelections.removeUnderline()
textSelections.removeStrikethrough()
编辑图像属性
ComPDFKit 支持修改图像属性,如旋转、裁剪、镜像和设置透明度。
以下是如何如何旋转图像并将其设置为半透明的示例代码:
java
public class DemoContextMenuHelper extends CPDFContextMenuShowHelper {
public DemoContextMenuHelper(CPDFReaderView cpdfReaderView) {
super(cpdfReaderView);
}
@Override
public View getEditImageAreaContentView(final CPDFPageView pageView, LayoutInflater layoutInflater, RectF area) {
View contentView = ...
this.pageView = pageView;
invokeOnClickListener(pageView, view ->{
if (view.getId() == R.id.edit){
pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.ROTATE, 90.0F);
pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.TRANCPARENCY, 127.5F);
}
}, R.id.edit);
return contentView;
}
}
kotlin
public class DemoContextMenuHelper(readerView: CPDFReaderView?) : CPDFContextMenuShowHelper(readerView) {
@Override
public View getEditImageAreaContentView(final CPDFPageView pageView, LayoutInflater layoutInflater, RectF area) {
this.pageView = pageView;
invokeOnClickListener(pageView, view ->{
if (view.getId() == R.id.edit){
pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.ROTATE, 90.0F);
pageView.operateEditImageArea(CPDFPageView.EditImageFuncType.TRANCPARENCY, 127.5F);
}
}, R.id.edit);
return super.getEditImageAreaContentView(pageView, layoutInflater, area);
}
}