Skip to content
DemoSampleAPI ReferenceFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub
Android Guides Edit text and image properties

Edit Text and Image Properties ​

ComPDF supports modifying text and image properties. You can set text and image properties within the getEditSelectTextContentView method of the customized context menu in CPDFReaderView.

Edit Text Properties ​

ComPDF supports modifying text properties, such as text font size, name, color, alignment, italics, bold, transparency, etc.

This example shows how to set text to 12pt, red, and bold:

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
  }
}

The following is a sample code for creating and deleting underlines and deleting text:

java
CPDFEditTextSelections textSelections = (CPDFEditTextSelections)selections;
// Create underscores and strikethroughs for text
textSelections.addUnderline();
textSelections.addStrikethrough();

// Delete the underscores and strikethroughs of the text
textSelections.removeUnderline();
textSelections.removeStrikethrough();
kotlin
val textSelections = selections as CPDFEditTextSelections
// Create underscores and strikethroughs for text
textSelections.addUnderline()
textSelections.addStrikethrough()

// Delete the underscores and strikethroughs of the text
textSelections.removeUnderline()
textSelections.removeStrikethrough()

Edit Image Properties ​

ComPDF supports modifying image properties, such as rotating, cropping, mirroring, and setting transparency.

This example shows how to rotate an image and set it to semi-transparent:

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);
  }
}