![JAR search and dependency download from the Maven repository](/logo.png)
com.itextpdf.forms.util.BorderStyleUtil Maven / Gradle / Ivy
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
package com.itextpdf.forms.util;
import com.itextpdf.forms.fields.PdfFormAnnotation;
import com.itextpdf.kernel.pdf.PdfDictionary;
import com.itextpdf.kernel.pdf.PdfName;
import com.itextpdf.kernel.pdf.annot.PdfAnnotation;
import com.itextpdf.layout.IPropertyContainer;
import com.itextpdf.layout.borders.Border;
import com.itextpdf.layout.properties.Property;
/**
* This file is a helper class for the internal usage only.
* Be aware that its API and functionality may be changed in the future.
*/
public final class BorderStyleUtil {
/**
* Applies the border property to the annotation.
*
* @param container property container to apply border properties from.
* @param annotation the annotation to set border characteristics to.
*/
public static void applyBorderProperty(IPropertyContainer container, PdfFormAnnotation annotation) {
Border border = container.getProperty(Property.BORDER);
if (border == null) {
// For now, we set left border to an annotation, but appropriate borders for an element will be drawn.
border = container.getProperty(Property.BORDER_LEFT);
}
if (border != null) {
annotation.setBorderStyle(transformBorderTypeToBorderStyleDictionary(border.getType()));
annotation.setBorderColor(border.getColor());
annotation.setBorderWidth(border.getWidth());
}
}
private static PdfDictionary transformBorderTypeToBorderStyleDictionary(int borderType) {
final PdfDictionary bs = new PdfDictionary();
PdfName style;
switch (borderType) {
case 1001:
style = PdfAnnotation.STYLE_UNDERLINE;
break;
case 1002:
style = PdfAnnotation.STYLE_BEVELED;
break;
case 1003:
style = PdfAnnotation.STYLE_INSET;
break;
case Border.DASHED_FIXED:
case Border.DASHED:
case Border.DOTTED:
// Default dash array will be used.
style = PdfAnnotation.STYLE_DASHED;
break;
default:
style = PdfAnnotation.STYLE_SOLID;
break;
}
bs.put(PdfName.S, style);
return bs;
}
private BorderStyleUtil() {
// Private constructor.
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy