Skip to content

Cloud Border Style for Annotations

Users are allowed to set the border style of rectangular, circular, and polygonal annotations to a cloud-like pattern. The border style can also be changed between solid lines, dashed lines, or the cloud style. ComPDFKit provides convenient APIs for setting the cloud border style for annotations, along with demo demonstrations.

Here is an example code for adding a cloud-style border to a rectangular annotation:

java
// Insert page numbers.
int pageNumber = 0;
// Retrieve an instance of the PDF page.
CPDFPage page = document.pageAtIndex(pageNumber);

// Create a rectangle annotation object on the page.
CPDFSquareAnnotation squareAnnotation = (CPDFSquareAnnotation) page.addAnnot(CPDFAnnotation.Type.SQUARE);
RectF pageSize = page.getSize();
RectF insertRect = new RectF(0,0,100,100);
// Coordinate transformation.
insertRect = page.convertRectToPage(false,pageSize.width(),pageSize.height(),insertRect);
squareAnnotation.setRect(insertRect);
// Set annotation properties.
squareAnnotation.setBorderColor(Color.YELLOW);
CPDFBorderStyle borderStyle = new CPDFBorderStyle(CPDFBorderStyle.Style.Border_Solid, 10, new float[]{8.0F, 0F});
squareAnnotation.setBorderStyle(borderStyle);
squareAnnotation.setBorderAlpha(255);
squareAnnotation.setFillColor(Color.RED);
squareAnnotation.setFillAlpha(255);

// Set the cloud border style
squareAnnotation.setBordEffectType(CPDFAnnotation.CPDFBorderEffectType.CPDFBorderEffectTypeCloudy);
squareAnnotation.setBordEffectIntensity(CPDFAnnotation.BorderEffectIntensity.INTENSITY_TWO);
// Update the annotations onto the document.
squareAnnotation.updateAp();
kotlin
// Insert page numbers.
val pageNumber = 0
// Retrieve an instance of the PDF page.
val page = document.pageAtIndex(pageNumber)

// Create a rectangle annotation object on the page.
val squareAnnotation = page.addAnnot(CPDFAnnotation.Type.SQUARE) as CPDFSquareAnnotation
val pageSize = page.size
// Coordinate transformation.
squareAnnotation.rect = page.convertRectToPage(false, pageSize.width(), pageSize.height(), RectF(0F, 0F, 100F, 100F))

squareAnnotation.apply {
// Set annotation properties.
  borderColor = Color.YELLOW
  borderStyle = CPDFBorderStyle(CPDFBorderStyle.Style.Border_Solid, 10F, floatArrayOf(8F, 0F))
  borderAlpha = 255
  fillColor = Color.RED
  fillAlpha = 255
  // Set the cloud border style
  bordEffectType = CPDFAnnotation.CPDFBorderEffectType.CPDFBorderEffectTypeCloudy
  bordEffectIntensity = CPDFAnnotation.BorderEffectIntensity.INTENSITY_TWO
}
// Update the annotations onto the document.
squareAnnotation.updateAp()

Cloud Border style Type Enumeration

NameDescription
BorderEffectIntensity.INTENSITY_ZEROThe influence intensity ranges from 0 to 2, and when it is 0, it is a solid line
BorderEffectIntensity.INTENSITY_ONE
BorderEffectIntensity.INTENSITY_TWO
NameDescription
CPDFBorderEffectTypeSolidThe border style style is a solid line
CPDFBorderEffectTypeCloudyThe border style style is cloud style