Some test text!
Android / Guides / Style properties
AnnotEdit
tool class can edit the style of a selected annotation easily by using annotation style dialog . You can set AnnotEdit
tool to ToolManager
as described here: change tool mode .With Apryse library, you can change annotation styles such as border color, border thickness, fill color, etc. To change annotation style, you must lock PDF document first. For more information about locking document, see: document locking .
To change an annotation border thickness:
Get the BorderStyle
from the annotation by calling annot.getBorderStyle()
.
Set thickness to the BorderSytle
by calling borderStyle.setWidth(double)
.
Refresh the annotation appearance by calling annot.refreshAppearance()
.
Update the PDFViewCtrl
contents by calling pdfViewCtrl.update()
.
void changeAnnotThickness(final PDFViewCtrl pdfViewCtrl, final Annot annot, final double thickness) throws Exception {
// Locks the document first as accessing annotation/doc
// information isn't thread safe.
pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
@Override
public void run() throws Exception {
Annot.BorderStyle borderStyle = annot.getBorderStyle();
borderStyle.setWidth(thickness);
annot.refreshAppearance();
pdfViewCtrl.update();
}
});
}
borderStyle.setWidth(0)
.If there is a FreeText
annotation, to set the border color of the annotation, call freeText.setLineColor(ColorPt, int)
. To set the border color of the other annotation types, call annot.setColor(ColorPt, int)
.
void changeAnnotBorderColor(final PDFViewCtrl pdfViewCtrl, final Annot annot, final @ColorInt int color) throws Exception {
// Locks the document first as accessing annotation/doc
// information isn't thread safe.
pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
@Override
public void run() throws Exception {
ColorPt colorPt = Utils.color2ColorPt(color);
// if color is transparent, then color component number is 0.
int colorCompNum = color == Color.TRANSPARENT ? 0 : 3;
// if the annotation is a FreeText annotation
if (annot.getType() == Annot.e_FreeText) {
FreeText freeText = new FreeText(annot);
freeText.setLineColor(colorPt, colorCompNum);
} else {
annot.setColor(colorPt, colorCompNum);
}
annot.refreshAppearance();
pdfViewCtrl.update();
}
});
}
Text
annotation, call annot.setColor(ColorPt, int)
.To change the opacity of a Markup
annotation, callMarkup.setOpacity(double)
:
void changeAnnotOpacity(final PDFViewCtrl pdfViewCtrl, final Annot annot, final double opacity) throws Exception {
// Locks the document first as accessing annotation/doc
// information isn't thread safe.
pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
@Override
public void run() throws Exception {
// if the annotation is a markup annotation,
// set opacity to the annotation
if (annot.isMarkup()) {
Markup markup = new Markup(annot);
markup.setOpacity(opacity);
}
annot.refreshAppearance();
pdfViewCtrl.update();
}
});
}
To set the fill color of a Markup
annotation, call Markup.setInteriorColor(ColorPt, int)
.
void changeAnnotInteriorColor(final PDFViewCtrl pdfViewCtrl, final Annot annot, @ColorInt final int color) throws Exception {
// Locks the document first as accessing annotation/doc
// information isn't thread safe.
pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
@Override
public void run() throws Exception {
ColorPt colorPt = Utils.color2ColorPt(color);
// if color is transparent, then color component number is 0.
int colorCompNum = color == Color.TRANSPARENT ? 0 : 3;
// if the annotation is a Markup annotation,
// set interior color to the annotation.
if (annot.isMarkup()) {
Markup markup = new Markup(annot);
markup.setInteriorColor(colorPt, colorCompNum);
}
// refresh the annotation appearch
annot.refreshAppearance();
pdfViewCtrl.update();
}
});
}
To change a Text
annotation icon, call Text.setIcon(String)
. After changing the icon, you must refresh the annotation appearance by calling AnnotUtils.refreshStickyNoteAppearance(Annot, PDFViewCtrl)
.
void changeAnnotInteriorColor(final PDFViewCtrl pdfViewCtrl, final Annot annot, final String icon) throws Exception {
// Locks the document first as accessing annotation/doc
// information isn't thread safe.
pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
@Override
public void run() throws Exception {
Text text = new Text(annot);
text.setIcon(icon);
// refresh the annotation appearch
AnnotUtils.refreshStickyNoteAppearance(annot, pdfViewCtrl);
pdfViewCtrl.update();
}
});
}
To change the text color of a FreeText
annotation, call FreeText.setTextColor(ColorPt, int)
.
void changeFreeTextColor(final PDFViewCtrl pdfViewCtrl, final Annot annot, @ColorInt final int color) throws Exception {
// Locks the document first as accessing annotation/doc
// information isn't thread safe.
pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
@Override
public void run() throws Exception {
ColorPt colorPt = Utils.color2ColorPt(color);
// set FreeText annotation text color
FreeText freeText = new FreeText(annot);
freeText.setTextColor(colorPt, 3);
annot.refreshAppearance();
pdfViewCtrl.update();
}
});
}
To change the text size of a FreeText
annotation, call FreeText.setFontSize(double)
.
void changeFreeTextSize(final PDFViewCtrl pdfViewCtrl, final Annot annot, final double textSize) throws Exception {
// Locks the document first as accessing annotation/doc
// information isn't thread safe.
pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
@Override
public void run() throws Exception {
// set FreeText annotation text color
FreeText freeText = new FreeText(annot);
freeText.setFontSize(textSize);
// refresh the annotation appearance
annot.refreshAppearance();
pdfViewCtrl.update();
}
});
}
The follow code snippet shows how to set the font to a FreeText
annotation:
void changeFreeTextFont(final PDFViewCtrl pdfViewCtrl, final Annot annot, final String fontStr) throws Exception {
// Locks the document first as accessing annotation/doc
// information isn't thread safe.
pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
@Override
public void run() throws Exception {
// set FreeText annotation text color
FreeText textAnnot = new FreeText(annot);
String fontDRName = "F0";
// Create a DR entry for embedding the font
Obj annotObj = textAnnot.getSDFObj();
Obj drDict = annotObj.putDict("DR");
Obj fontDict = drDict.putDict("Font");
// Embed the font
Font font = Font.create(pdfViewCtrl.getDoc(), fontStr, textAnnot.getContents());
fontDict.put(fontDRName, font.GetSDFObj());
String fontName = font.getName();
// Set DA string
String DA = textAnnot.getDefaultAppearance();
int slashPosition = DA.indexOf("/", 0);
// if DR string contains '/' which it always should.
if (slashPosition > 0) {
String beforeSlash = DA.substring(0, slashPosition);
String afterSlash = DA.substring(slashPosition);
String afterFont = afterSlash.substring(afterSlash.indexOf(" "));
String updatedDA = beforeSlash + "/" + fontDRName + afterFont;
textAnnot.setDefaultAppearance(updatedDA);
// refresh text annotation appearance
textAnnot.refreshAppearance();
pdfViewCtrl.update();
}
}
});
}
Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales