Anotaciones
Añade, enumera, mueve, elimina y aplana anotaciones de PDF, e importa o exporta XFDF, con NexPDF para Android.
Módulo de licencia
Crear y cambiar anotaciones necesita el módulo annotations (nivel Indie y superiores). Enumerar
las anotaciones con annotationsJson funciona sin clave.
Las coordenadas son puntos PDF con el origen en la esquina inferior izquierda de la página. Los
rectángulos son llx, lly, urx, ury. Todas las llamadas siguientes son métodos estáticos de
NexPdfJni que reciben doc.handle(); las que devuelven Boolean devuelven false si fallan, con
el motivo en NexPdfJni.lastError(). El lector ofrece las mismas
herramientas al usuario.
Añadir marcas y formas
addAnnotation(handle, pageIndex, kind, colorHex, opacity, contents, llx, lly, urx, ury) añade una
anotación de un subtipo de PDF como Highlight, Underline, StrikeOut, Squiggly, Square,
Circle, FreeText o Text (una nota adhesiva). El marcado de texto se ajusta a las líneas que
quedan bajo el rectángulo.
import com.nexdevit.nexpdf.NexPdfDocument
import com.nexdevit.nexpdf.NexPdfJni
NexPdfDocument.openBytes(bytes).use { doc ->
val h = doc.handle()
check(NexPdfJni.addAnnotation(h, 0, "Highlight", "#FFD400", 1.0, "", 72.0, 700.0, 300.0, 716.0)) { NexPdfJni.lastError() }
NexPdfJni.addAnnotation(h, 0, "FreeText", "#E5484D", 1.0, "Checked", 72.0, 640.0, 260.0, 660.0)
NexPdfJni.addAnnotation(h, 0, "Text", "#2563EB", 1.0, "Please confirm this date", 320.0, 700.0, 340.0, 720.0)
val annotated = doc.saveBytes()
}Líneas, flechas y tinta
// A red arrow from (100, 500) to (250, 560), 2 pt wide.
NexPdfJni.addLine(h, 0, "Arrow", "#DC2626", 1.0, 2.0, 100.0, 500.0, 250.0, 560.0)
// Freehand ink: points "x,y;x,y;..." in PDF points.
NexPdfJni.addInk(h, 0, "#1D4ED8", 2.0, 1.0, "100,400;120,410;140,405;160,420")Una firma manuscrita es una anotación de tinta con varios trazos separados por |:
NexPdfJni.addInkSignature(h, 0, "#111827", 1.5, "300,120;320,130;340,118|350,125;380,128")Es solo una firma visual. Para una firma criptográfica, consulta Firmas.
Sellos de imagen y mediciones
// A picture stamp from RGBA pixels (width x height x 4 bytes), here 240 x 120.
NexPdfJni.addImageStamp(h, 0, 400.0, 60.0, 520.0, 120.0, rgba, 240, 120, 1.0)
// A stored distance measurement; per_point converts PDF points to the unit.
val m = """{"kind":"distance","points":[[100,100],[300,100]],"unit":"mm","per_point":0.3528}"""
val result = JSONObject(NexPdfJni.addMeasurement(h, 0, m))
Log.i("NexPDF", result.getString("text"))kind es distance, perimeter o area. NexPdfJni.measurementsJson(h) enumera las
almacenadas.
Enumerar, editar, mover y eliminar
val annots = JSONArray(NexPdfJni.annotationsJson(h, 0))
for (i in 0 until annots.length()) {
val a = annots.getJSONObject(i)
Log.i("NexPDF", "${a.getInt("num")} ${a.getInt("gen")} ${a.getString("kind")} ${a.optString("contents")}")
}
val a = annots.getJSONObject(0)
val num = a.getInt("num"); val gen = a.getInt("gen")
NexPdfJni.setAnnotationContents(h, num, gen, "Updated note")
NexPdfJni.moveAnnotation(h, num, gen, 10.0, -20.0) // dx, dy in points
NexPdfJni.removeAnnotation(h, 0, num, gen)Las anotaciones se identifican por su número de objeto (num) y su generación (gen).
Aplanar
Aplanar graba las anotaciones en el contenido de la página para que ya no se puedan editar:
NexPdfJni.flattenAnnotations(h, -1) // every page; pass a page index for one pageImportar y exportar XFDF
val xfdf = NexPdfJni.exportXfdf(h)
NexPdfDocument.openBytes(cleanBytes).use { other ->
NexPdfJni.importXfdf(other.handle(), xfdf)
val withAnnotations = other.saveBytes()
}Archivos adjuntos
addFileAttachmentAnnot(handle, pageIndex, x, y, name, data, mime, description) añade un icono de
clip cuya esquina superior izquierda está en (x, y):
NexPdfJni.addFileAttachmentAnnot(h, 0, 520.0, 760.0, "invoice.xml", xmlBytes, "application/xml", "Source data")Códigos de barras
Lee códigos QR, Data Matrix, PDF417 y códigos de barras lineales en páginas e imágenes de PDF, y dibuja códigos de barras vectoriales reales, con NexPDF para Android.
Formularios
Enumera, rellena, crea, recalcula y aplana campos de formulario de PDF, e intercambia datos de formulario como JSON, FDF o XFDF, con NexPDF para Android.