Files
pdfmerge/internal/pdf/model/annotations.go
2025-12-15 17:44:00 +01:00

1900 lines
47 KiB
Go

package model
import (
"fmt"
"gitea.tecamino.com/paadi/pdfmerge/internal/pdf/common"
"gitea.tecamino.com/paadi/pdfmerge/internal/pdf/core"
)
// PDFAnnotation contains common attributes of an annotation. The context object contains the subannotation,
// which can be a markup annotation or other types.
type PdfAnnotation struct {
context PdfModel // Sub-annotation.
Rect core.PdfObject
Contents core.PdfObject
P core.PdfObject // Reference to page object.
NM core.PdfObject
M core.PdfObject
F core.PdfObject
AP core.PdfObject
AS core.PdfObject
Border core.PdfObject
C core.PdfObject
StructParent core.PdfObject
OC core.PdfObject
primitive *core.PdfIndirectObject
}
// Context in this case is a reference to the subannotation.
func (a *PdfAnnotation) GetContext() PdfModel {
return a.context
}
// Set the sub annotation (context).
func (a *PdfAnnotation) SetContext(ctx PdfModel) {
a.context = ctx
}
func (a *PdfAnnotation) String() string {
s := ""
obj, ok := a.ToPdfObject().(*core.PdfIndirectObject)
if ok {
s = fmt.Sprintf("%T: %s", a.context, obj.PdfObject.String())
}
return s
}
// Additional elements for mark-up annotations.
type PdfAnnotationMarkup struct {
T core.PdfObject
Popup *PdfAnnotationPopup
CA core.PdfObject
RC core.PdfObject
CreationDate core.PdfObject
IRT core.PdfObject
Subj core.PdfObject
RT core.PdfObject
IT core.PdfObject
ExData core.PdfObject
}
// Subtype: Text
type PdfAnnotationText struct {
*PdfAnnotation
*PdfAnnotationMarkup
Open core.PdfObject
Name core.PdfObject
State core.PdfObject
StateModel core.PdfObject
}
// Subtype: Link
type PdfAnnotationLink struct {
*PdfAnnotation
A core.PdfObject
Dest core.PdfObject
H core.PdfObject
PA core.PdfObject
QuadPoints core.PdfObject
BS core.PdfObject
}
// Subtype: FreeText
type PdfAnnotationFreeText struct {
*PdfAnnotation
*PdfAnnotationMarkup
DA core.PdfObject
Q core.PdfObject
RC core.PdfObject
DS core.PdfObject
CL core.PdfObject
IT core.PdfObject
BE core.PdfObject
RD core.PdfObject
BS core.PdfObject
LE core.PdfObject
}
// Subtype: Line
type PdfAnnotationLine struct {
*PdfAnnotation
*PdfAnnotationMarkup
L core.PdfObject
BS core.PdfObject
LE core.PdfObject
IC core.PdfObject
LL core.PdfObject
LLE core.PdfObject
Cap core.PdfObject
IT core.PdfObject
LLO core.PdfObject
CP core.PdfObject
Measure core.PdfObject
CO core.PdfObject
}
// Subtype: Square
type PdfAnnotationSquare struct {
*PdfAnnotation
*PdfAnnotationMarkup
BS core.PdfObject
IC core.PdfObject
BE core.PdfObject
RD core.PdfObject
}
// Subtype: Circle
type PdfAnnotationCircle struct {
*PdfAnnotation
*PdfAnnotationMarkup
BS core.PdfObject
IC core.PdfObject
BE core.PdfObject
RD core.PdfObject
}
// Subtype: Polygon
type PdfAnnotationPolygon struct {
*PdfAnnotation
*PdfAnnotationMarkup
Vertices core.PdfObject
LE core.PdfObject
BS core.PdfObject
IC core.PdfObject
BE core.PdfObject
IT core.PdfObject
Measure core.PdfObject
}
// Subtype: PolyLine
type PdfAnnotationPolyLine struct {
*PdfAnnotation
*PdfAnnotationMarkup
Vertices core.PdfObject
LE core.PdfObject
BS core.PdfObject
IC core.PdfObject
BE core.PdfObject
IT core.PdfObject
Measure core.PdfObject
}
// Subtype: Highlight
type PdfAnnotationHighlight struct {
*PdfAnnotation
*PdfAnnotationMarkup
QuadPoints core.PdfObject
}
// Subtype: Underline
type PdfAnnotationUnderline struct {
*PdfAnnotation
*PdfAnnotationMarkup
QuadPoints core.PdfObject
}
// Subtype: Squiggly
type PdfAnnotationSquiggly struct {
*PdfAnnotation
*PdfAnnotationMarkup
QuadPoints core.PdfObject
}
// Subtype: StrikeOut
type PdfAnnotationStrikeOut struct {
*PdfAnnotation
*PdfAnnotationMarkup
QuadPoints core.PdfObject
}
// Subtype: Caret
type PdfAnnotationCaret struct {
*PdfAnnotation
*PdfAnnotationMarkup
RD core.PdfObject
Sy core.PdfObject
}
// Subtype: Stamp
type PdfAnnotationStamp struct {
*PdfAnnotation
*PdfAnnotationMarkup
Name core.PdfObject
}
// Subtype: Ink
type PdfAnnotationInk struct {
*PdfAnnotation
*PdfAnnotationMarkup
InkList core.PdfObject
BS core.PdfObject
}
// Subtype: Popup
type PdfAnnotationPopup struct {
*PdfAnnotation
Parent core.PdfObject
Open core.PdfObject
}
// Subtype: FileAttachment
type PdfAnnotationFileAttachment struct {
*PdfAnnotation
*PdfAnnotationMarkup
FS core.PdfObject
Name core.PdfObject
}
// Subtype: Sound
type PdfAnnotationSound struct {
*PdfAnnotation
*PdfAnnotationMarkup
Sound core.PdfObject
Name core.PdfObject
}
// Subtype: Rich Media
type PdfAnnotationRichMedia struct {
*PdfAnnotation
RichMediaSettings core.PdfObject
RichMediaContent core.PdfObject
}
// Subtype: Movie
type PdfAnnotationMovie struct {
*PdfAnnotation
T core.PdfObject
Movie core.PdfObject
A core.PdfObject
}
// Subtype: Screen
type PdfAnnotationScreen struct {
*PdfAnnotation
T core.PdfObject
MK core.PdfObject
A core.PdfObject
AA core.PdfObject
}
// Subtype: Widget
type PdfAnnotationWidget struct {
*PdfAnnotation
H core.PdfObject
MK core.PdfObject
A core.PdfObject
AA core.PdfObject
BS core.PdfObject
Parent core.PdfObject
}
// Subtype: Watermark
type PdfAnnotationWatermark struct {
*PdfAnnotation
FixedPrint core.PdfObject
}
// Subtype: PrinterMark
type PdfAnnotationPrinterMark struct {
*PdfAnnotation
MN core.PdfObject
}
// Subtype: TrapNet
type PdfAnnotationTrapNet struct {
*PdfAnnotation
}
// Subtype: 3D
type PdfAnnotation3D struct {
*PdfAnnotation
T3DD core.PdfObject
T3DV core.PdfObject
T3DA core.PdfObject
T3DI core.PdfObject
T3DB core.PdfObject
}
// Subtype: Projection
type PdfAnnotationProjection struct {
*PdfAnnotation
*PdfAnnotationMarkup
}
// Subtype: Redact
type PdfAnnotationRedact struct {
*PdfAnnotation
*PdfAnnotationMarkup
QuadPoints core.PdfObject
IC core.PdfObject
RO core.PdfObject
OverlayText core.PdfObject
Repeat core.PdfObject
DA core.PdfObject
Q core.PdfObject
}
// Construct a new PDF annotation model and initializes the underlying PDF primitive.
func NewPdfAnnotation() *PdfAnnotation {
annot := &PdfAnnotation{}
container := &core.PdfIndirectObject{}
container.PdfObject = core.MakeDict()
annot.primitive = container
return annot
}
// Create a new text annotation.
func NewPdfAnnotationText() *PdfAnnotationText {
annotation := NewPdfAnnotation()
textAnnotation := &PdfAnnotationText{}
textAnnotation.PdfAnnotation = annotation
textAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(textAnnotation)
return textAnnotation
}
// Create a new link annotation.
func NewPdfAnnotationLink() *PdfAnnotationLink {
annotation := NewPdfAnnotation()
linkAnnotation := &PdfAnnotationLink{}
linkAnnotation.PdfAnnotation = annotation
annotation.SetContext(linkAnnotation)
return linkAnnotation
}
// Create a new free text annotation.
func NewPdfAnnotationFreeText() *PdfAnnotationFreeText {
annotation := NewPdfAnnotation()
freetextAnnotation := &PdfAnnotationFreeText{}
freetextAnnotation.PdfAnnotation = annotation
freetextAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(freetextAnnotation)
return freetextAnnotation
}
// Create a new line annotation.
func NewPdfAnnotationLine() *PdfAnnotationLine {
annotation := NewPdfAnnotation()
lineAnnotation := &PdfAnnotationLine{}
lineAnnotation.PdfAnnotation = annotation
lineAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(lineAnnotation)
return lineAnnotation
}
// Create a new square annotation.
func NewPdfAnnotationSquare() *PdfAnnotationSquare {
annotation := NewPdfAnnotation()
rectAnnotation := &PdfAnnotationSquare{}
rectAnnotation.PdfAnnotation = annotation
rectAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(rectAnnotation)
return rectAnnotation
}
// Create a new circle annotation.
func NewPdfAnnotationCircle() *PdfAnnotationCircle {
annotation := NewPdfAnnotation()
circAnnotation := &PdfAnnotationCircle{}
circAnnotation.PdfAnnotation = annotation
circAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(circAnnotation)
return circAnnotation
}
// Create a new polygon annotation.
func NewPdfAnnotationPolygon() *PdfAnnotationPolygon {
annotation := NewPdfAnnotation()
polygonAnnotation := &PdfAnnotationPolygon{}
polygonAnnotation.PdfAnnotation = annotation
polygonAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(polygonAnnotation)
return polygonAnnotation
}
// Create a new polyline annotation.
func NewPdfAnnotationPolyLine() *PdfAnnotationPolyLine {
annotation := NewPdfAnnotation()
polylineAnnotation := &PdfAnnotationPolyLine{}
polylineAnnotation.PdfAnnotation = annotation
polylineAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(polylineAnnotation)
return polylineAnnotation
}
// Create a new text highlight annotation.
func NewPdfAnnotationHighlight() *PdfAnnotationHighlight {
annotation := NewPdfAnnotation()
highlightAnnotation := &PdfAnnotationHighlight{}
highlightAnnotation.PdfAnnotation = annotation
highlightAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(highlightAnnotation)
return highlightAnnotation
}
// Create a new text underline annotation.
func NewPdfAnnotationUnderline() *PdfAnnotationUnderline {
annotation := NewPdfAnnotation()
underlineAnnotation := &PdfAnnotationUnderline{}
underlineAnnotation.PdfAnnotation = annotation
underlineAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(underlineAnnotation)
return underlineAnnotation
}
// Create a new text squiggly annotation.
func NewPdfAnnotationSquiggly() *PdfAnnotationSquiggly {
annotation := NewPdfAnnotation()
squigglyAnnotation := &PdfAnnotationSquiggly{}
squigglyAnnotation.PdfAnnotation = annotation
squigglyAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(squigglyAnnotation)
return squigglyAnnotation
}
// Create a new text strikeout annotation.
func NewPdfAnnotationStrikeOut() *PdfAnnotationStrikeOut {
annotation := NewPdfAnnotation()
strikeoutAnnotation := &PdfAnnotationStrikeOut{}
strikeoutAnnotation.PdfAnnotation = annotation
strikeoutAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(strikeoutAnnotation)
return strikeoutAnnotation
}
// Create a new caret annotation.
func NewPdfAnnotationCaret() *PdfAnnotationCaret {
annotation := NewPdfAnnotation()
caretAnnotation := &PdfAnnotationCaret{}
caretAnnotation.PdfAnnotation = annotation
caretAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(caretAnnotation)
return caretAnnotation
}
// Create a new stamp annotation.
func NewPdfAnnotationStamp() *PdfAnnotationStamp {
annotation := NewPdfAnnotation()
stampAnnotation := &PdfAnnotationStamp{}
stampAnnotation.PdfAnnotation = annotation
stampAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(stampAnnotation)
return stampAnnotation
}
// Create a new ink annotation.
func NewPdfAnnotationInk() *PdfAnnotationInk {
annotation := NewPdfAnnotation()
inkAnnotation := &PdfAnnotationInk{}
inkAnnotation.PdfAnnotation = annotation
inkAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(inkAnnotation)
return inkAnnotation
}
// Create a new popup annotation.
func NewPdfAnnotationPopup() *PdfAnnotationPopup {
annotation := NewPdfAnnotation()
popupAnnotation := &PdfAnnotationPopup{}
popupAnnotation.PdfAnnotation = annotation
annotation.SetContext(popupAnnotation)
return popupAnnotation
}
// Create a new file attachment annotation.
func NewPdfAnnotationFileAttachment() *PdfAnnotationFileAttachment {
annotation := NewPdfAnnotation()
fileAnnotation := &PdfAnnotationFileAttachment{}
fileAnnotation.PdfAnnotation = annotation
fileAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(fileAnnotation)
return fileAnnotation
}
// Create a new sound annotation.
func NewPdfAnnotationSound() *PdfAnnotationSound {
annotation := NewPdfAnnotation()
soundAnnotation := &PdfAnnotationSound{}
soundAnnotation.PdfAnnotation = annotation
soundAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(soundAnnotation)
return soundAnnotation
}
// Create a new rich media annotation.
func NewPdfAnnotationRichMedia() *PdfAnnotationRichMedia {
annotation := NewPdfAnnotation()
richmediaAnnotation := &PdfAnnotationRichMedia{}
richmediaAnnotation.PdfAnnotation = annotation
annotation.SetContext(richmediaAnnotation)
return richmediaAnnotation
}
// Create a new movie annotation.
func NewPdfAnnotationMovie() *PdfAnnotationMovie {
annotation := NewPdfAnnotation()
movieAnnotation := &PdfAnnotationMovie{}
movieAnnotation.PdfAnnotation = annotation
annotation.SetContext(movieAnnotation)
return movieAnnotation
}
// Create a new screen annotation.
func NewPdfAnnotationScreen() *PdfAnnotationScreen {
annotation := NewPdfAnnotation()
screenAnnotation := &PdfAnnotationScreen{}
screenAnnotation.PdfAnnotation = annotation
annotation.SetContext(screenAnnotation)
return screenAnnotation
}
// Create a new watermark annotation.
func NewPdfAnnotationWatermark() *PdfAnnotationWatermark {
annotation := NewPdfAnnotation()
watermarkAnnotation := &PdfAnnotationWatermark{}
watermarkAnnotation.PdfAnnotation = annotation
annotation.SetContext(watermarkAnnotation)
return watermarkAnnotation
}
// Create a new printermark annotation.
func NewPdfAnnotationPrinterMark() *PdfAnnotationPrinterMark {
annotation := NewPdfAnnotation()
printermarkAnnotation := &PdfAnnotationPrinterMark{}
printermarkAnnotation.PdfAnnotation = annotation
annotation.SetContext(printermarkAnnotation)
return printermarkAnnotation
}
// Create a new trapnet annotation.
func NewPdfAnnotationTrapNet() *PdfAnnotationTrapNet {
annotation := NewPdfAnnotation()
trapnetAnnotation := &PdfAnnotationTrapNet{}
trapnetAnnotation.PdfAnnotation = annotation
annotation.SetContext(trapnetAnnotation)
return trapnetAnnotation
}
// Create a new 3d annotation.
func NewPdfAnnotation3D() *PdfAnnotation3D {
annotation := NewPdfAnnotation()
x3dAnnotation := &PdfAnnotation3D{}
x3dAnnotation.PdfAnnotation = annotation
annotation.SetContext(x3dAnnotation)
return x3dAnnotation
}
// Create a new projection annotation.
func NewPdfAnnotationProjection() *PdfAnnotationProjection {
annotation := NewPdfAnnotation()
projectionAnnotation := &PdfAnnotationProjection{}
projectionAnnotation.PdfAnnotation = annotation
projectionAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(projectionAnnotation)
return projectionAnnotation
}
// Create a new redact annotation.
func NewPdfAnnotationRedact() *PdfAnnotationRedact {
annotation := NewPdfAnnotation()
redactAnnotation := &PdfAnnotationRedact{}
redactAnnotation.PdfAnnotation = annotation
redactAnnotation.PdfAnnotationMarkup = &PdfAnnotationMarkup{}
annotation.SetContext(redactAnnotation)
return redactAnnotation
}
// Create a new annotation widget and initializes the underlying primitive.
func NewPdfAnnotationWidget() *PdfAnnotationWidget {
annotation := NewPdfAnnotation()
annotationWidget := &PdfAnnotationWidget{}
annotationWidget.PdfAnnotation = annotation
annotation.SetContext(annotationWidget)
return annotationWidget
}
// Used for PDF parsing. Loads a PDF annotation model from a PDF primitive dictionary object.
// Loads the common PDF annotation dictionary, and anything needed for the annotation subtype.
func (r *PdfReader) newPdfAnnotationFromIndirectObject(container *core.PdfIndirectObject) (*PdfAnnotation, error) {
d, isDict := container.PdfObject.(*core.PdfObjectDictionary)
if !isDict {
return nil, fmt.Errorf("annotation indirect object not containing a dictionary")
}
// Check if cached, return cached model if exists.
if model := r.modelManager.GetModelFromPrimitive(d); model != nil {
annot, ok := model.(*PdfAnnotation)
if !ok {
return nil, fmt.Errorf("cached model not a PDF annotation")
}
return annot, nil
}
annot := &PdfAnnotation{}
annot.primitive = container
r.modelManager.Register(d, annot)
if obj := d.Get("Type"); obj != nil {
str, ok := obj.(*core.PdfObjectName)
if !ok {
common.Log.Trace("Incompatibility! Invalid type of Type (%T) - should be Name", obj)
} else {
if *str != "Annot" {
// Log a debug message.
// Not returning an error on this
common.Log.Trace("Unsuspected Type != Annot (%s)", *str)
}
}
}
if obj := d.Get("Rect"); obj != nil {
annot.Rect = obj
}
if obj := d.Get("Contents"); obj != nil {
annot.Contents = obj
}
if obj := d.Get("P"); obj != nil {
annot.P = obj
}
if obj := d.Get("NM"); obj != nil {
annot.NM = obj
}
if obj := d.Get("M"); obj != nil {
annot.M = obj
}
if obj := d.Get("F"); obj != nil {
annot.F = obj
}
if obj := d.Get("AP"); obj != nil {
annot.AP = obj
}
if obj := d.Get("AS"); obj != nil {
annot.AS = obj
}
if obj := d.Get("Border"); obj != nil {
annot.Border = obj
}
if obj := d.Get("C"); obj != nil {
annot.C = obj
}
if obj := d.Get("StructParent"); obj != nil {
annot.StructParent = obj
}
if obj := d.Get("OC"); obj != nil {
annot.OC = obj
}
subtypeObj := d.Get("Subtype")
if subtypeObj == nil {
common.Log.Debug("warning: Compatibility issue - annotation Subtype missing - assuming no subtype")
annot.context = nil
return annot, nil
}
subtype, ok := subtypeObj.(*core.PdfObjectName)
if !ok {
common.Log.Debug("error: Invalid Subtype object type != name (%T)", subtypeObj)
return nil, fmt.Errorf("invalid Subtype object type != name (%T)", subtypeObj)
}
switch *subtype {
case "Text":
ctx, err := r.newPdfAnnotationTextFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Link":
ctx, err := r.newPdfAnnotationLinkFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "FreeText":
ctx, err := r.newPdfAnnotationFreeTextFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Line":
ctx, err := r.newPdfAnnotationLineFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
common.Log.Trace("LINE ANNOTATION: annot (%T): %+v\n", annot, annot)
common.Log.Trace("LINE ANNOTATION: ctx (%T): %+v\n", ctx, ctx)
common.Log.Trace("LINE ANNOTATION Markup: ctx (%T): %+v\n", ctx.PdfAnnotationMarkup, ctx.PdfAnnotationMarkup)
return annot, nil
case "Square":
ctx, err := r.newPdfAnnotationSquareFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Circle":
ctx, err := r.newPdfAnnotationCircleFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Polygon":
ctx, err := r.newPdfAnnotationPolygonFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "PolyLine":
ctx, err := r.newPdfAnnotationPolyLineFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Highlight":
ctx, err := r.newPdfAnnotationHighlightFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Underline":
ctx, err := r.newPdfAnnotationUnderlineFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Squiggly":
ctx, err := r.newPdfAnnotationSquigglyFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "StrikeOut":
ctx, err := r.newPdfAnnotationStrikeOut(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Caret":
ctx, err := r.newPdfAnnotationCaretFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Stamp":
ctx, err := r.newPdfAnnotationStampFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Ink":
ctx, err := r.newPdfAnnotationInkFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Popup":
ctx, err := r.newPdfAnnotationPopupFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "FileAttachment":
ctx, err := r.newPdfAnnotationFileAttachmentFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Sound":
ctx, err := r.newPdfAnnotationSoundFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "RichMedia":
ctx, err := r.newPdfAnnotationRichMediaFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Movie":
ctx, err := r.newPdfAnnotationMovieFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Screen":
ctx, err := r.newPdfAnnotationScreenFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Widget":
ctx, err := r.newPdfAnnotationWidgetFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "PrinterMark":
ctx, err := r.newPdfAnnotationPrinterMarkFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "TrapNet":
ctx, err := r.newPdfAnnotationTrapNetFromDict()
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Watermark":
ctx, err := r.newPdfAnnotationWatermarkFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "3D":
ctx, err := r.newPdfAnnotation3DFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Projection":
ctx, err := r.newPdfAnnotationProjectionFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
case "Redact":
ctx, err := r.newPdfAnnotationRedactFromDict(d)
if err != nil {
return nil, err
}
ctx.PdfAnnotation = annot
annot.context = ctx
return annot, nil
}
err := fmt.Errorf("unknown annotation (%s)", *subtype)
return nil, err
}
// Load data for markup annotation subtypes.
func (r *PdfReader) newPdfAnnotationMarkupFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationMarkup, error) {
annot := &PdfAnnotationMarkup{}
if obj := d.Get("T"); obj != nil {
annot.T = obj
}
if obj := d.Get("Popup"); obj != nil {
indObj, isIndirect := obj.(*core.PdfIndirectObject)
if !isIndirect {
if _, isNull := obj.(*core.PdfObjectNull); !isNull {
return nil, fmt.Errorf("popup should point to an indirect object")
}
} else {
popupAnnotObj, err := r.newPdfAnnotationFromIndirectObject(indObj)
if err != nil {
return nil, err
}
popupAnnot, isPopupAnnot := popupAnnotObj.context.(*PdfAnnotationPopup)
if !isPopupAnnot {
return nil, fmt.Errorf("popup not referring to a popup annotation")
}
annot.Popup = popupAnnot
}
}
if obj := d.Get("CA"); obj != nil {
annot.CA = obj
}
if obj := d.Get("RC"); obj != nil {
annot.RC = obj
}
if obj := d.Get("CreationDate"); obj != nil {
annot.CreationDate = obj
}
if obj := d.Get("IRT"); obj != nil {
annot.IRT = obj
}
if obj := d.Get("Subj"); obj != nil {
annot.Subj = obj
}
if obj := d.Get("RT"); obj != nil {
annot.RT = obj
}
if obj := d.Get("IT"); obj != nil {
annot.IT = obj
}
if obj := d.Get("ExData"); obj != nil {
annot.ExData = obj
}
return annot, nil
}
func (r *PdfReader) newPdfAnnotationTextFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationText, error) {
annot := PdfAnnotationText{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.Open = d.Get("Open")
annot.Name = d.Get("Name")
annot.State = d.Get("State")
annot.StateModel = d.Get("StateModel")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationLinkFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationLink, error) {
annot := PdfAnnotationLink{}
annot.A = d.Get("A")
annot.Dest = d.Get("Dest")
annot.H = d.Get("H")
annot.PA = d.Get("PA")
annot.QuadPoints = d.Get("QuadPoints")
annot.BS = d.Get("BS")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationFreeTextFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationFreeText, error) {
annot := PdfAnnotationFreeText{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.DA = d.Get("DA")
annot.Q = d.Get("Q")
annot.RC = d.Get("RC")
annot.DS = d.Get("DS")
annot.CL = d.Get("CL")
annot.IT = d.Get("IT")
annot.BE = d.Get("BE")
annot.RD = d.Get("RD")
annot.BS = d.Get("BS")
annot.LE = d.Get("LE")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationLineFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationLine, error) {
annot := PdfAnnotationLine{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.L = d.Get("L")
annot.BS = d.Get("BS")
annot.LE = d.Get("LE")
annot.IC = d.Get("IC")
annot.LL = d.Get("LL")
annot.LLE = d.Get("LLE")
annot.Cap = d.Get("Cap")
annot.IT = d.Get("IT")
annot.LLO = d.Get("LLO")
annot.CP = d.Get("CP")
annot.Measure = d.Get("Measure")
annot.CO = d.Get("CO")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationSquareFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationSquare, error) {
annot := PdfAnnotationSquare{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.BS = d.Get("BS")
annot.IC = d.Get("IC")
annot.BE = d.Get("BE")
annot.RD = d.Get("RD")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationCircleFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationCircle, error) {
annot := PdfAnnotationCircle{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.BS = d.Get("BS")
annot.IC = d.Get("IC")
annot.BE = d.Get("BE")
annot.RD = d.Get("RD")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationPolygonFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationPolygon, error) {
annot := PdfAnnotationPolygon{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.Vertices = d.Get("Vertices")
annot.LE = d.Get("LE")
annot.BS = d.Get("BS")
annot.IC = d.Get("IC")
annot.BE = d.Get("BE")
annot.IT = d.Get("IT")
annot.Measure = d.Get("Measure")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationPolyLineFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationPolyLine, error) {
annot := PdfAnnotationPolyLine{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.Vertices = d.Get("Vertices")
annot.LE = d.Get("LE")
annot.BS = d.Get("BS")
annot.IC = d.Get("IC")
annot.BE = d.Get("BE")
annot.IT = d.Get("IT")
annot.Measure = d.Get("Measure")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationHighlightFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationHighlight, error) {
annot := PdfAnnotationHighlight{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.QuadPoints = d.Get("QuadPoints")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationUnderlineFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationUnderline, error) {
annot := PdfAnnotationUnderline{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.QuadPoints = d.Get("QuadPoints")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationSquigglyFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationSquiggly, error) {
annot := PdfAnnotationSquiggly{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.QuadPoints = d.Get("QuadPoints")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationStrikeOut(d *core.PdfObjectDictionary) (*PdfAnnotationStrikeOut, error) {
annot := PdfAnnotationStrikeOut{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.QuadPoints = d.Get("QuadPoints")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationCaretFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationCaret, error) {
annot := PdfAnnotationCaret{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.RD = d.Get("RD")
annot.Sy = d.Get("Sy")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationStampFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationStamp, error) {
annot := PdfAnnotationStamp{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.Name = d.Get("Name")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationInkFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationInk, error) {
annot := PdfAnnotationInk{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.InkList = d.Get("InkList")
annot.BS = d.Get("BS")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationPopupFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationPopup, error) {
annot := PdfAnnotationPopup{}
annot.Parent = d.Get("Parent")
annot.Open = d.Get("Open")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationFileAttachmentFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationFileAttachment, error) {
annot := PdfAnnotationFileAttachment{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.FS = d.Get("FS")
annot.Name = d.Get("Name")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationSoundFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationSound, error) {
annot := PdfAnnotationSound{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.Name = d.Get("Name")
annot.Sound = d.Get("Sound")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationRichMediaFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationRichMedia, error) {
annot := &PdfAnnotationRichMedia{}
annot.RichMediaSettings = d.Get("RichMediaSettings")
annot.RichMediaContent = d.Get("RichMediaContent")
return annot, nil
}
func (r *PdfReader) newPdfAnnotationMovieFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationMovie, error) {
annot := PdfAnnotationMovie{}
annot.T = d.Get("T")
annot.Movie = d.Get("Movie")
annot.A = d.Get("A")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationScreenFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationScreen, error) {
annot := PdfAnnotationScreen{}
annot.T = d.Get("T")
annot.MK = d.Get("MK")
annot.A = d.Get("A")
annot.AA = d.Get("AA")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationWidgetFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationWidget, error) {
annot := PdfAnnotationWidget{}
annot.H = d.Get("H")
annot.MK = d.Get("MK")
// MK can be an indirect object...
// Expected to be a dictionary.
annot.A = d.Get("A")
annot.AA = d.Get("AA")
annot.BS = d.Get("BS")
annot.Parent = d.Get("Parent")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationPrinterMarkFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationPrinterMark, error) {
annot := PdfAnnotationPrinterMark{}
annot.MN = d.Get("MN")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationTrapNetFromDict() (*PdfAnnotationTrapNet, error) {
annot := PdfAnnotationTrapNet{}
// empty?e
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationWatermarkFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationWatermark, error) {
annot := PdfAnnotationWatermark{}
annot.FixedPrint = d.Get("FixedPrint")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotation3DFromDict(d *core.PdfObjectDictionary) (*PdfAnnotation3D, error) {
annot := PdfAnnotation3D{}
annot.T3DD = d.Get("3DD")
annot.T3DV = d.Get("3DV")
annot.T3DA = d.Get("3DA")
annot.T3DI = d.Get("3DI")
annot.T3DB = d.Get("3DB")
return &annot, nil
}
func (r *PdfReader) newPdfAnnotationProjectionFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationProjection, error) {
annot := &PdfAnnotationProjection{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
return annot, nil
}
func (r *PdfReader) newPdfAnnotationRedactFromDict(d *core.PdfObjectDictionary) (*PdfAnnotationRedact, error) {
annot := PdfAnnotationRedact{}
markup, err := r.newPdfAnnotationMarkupFromDict(d)
if err != nil {
return nil, err
}
annot.PdfAnnotationMarkup = markup
annot.QuadPoints = d.Get("QuadPoints")
annot.IC = d.Get("IC")
annot.RO = d.Get("RO")
annot.OverlayText = d.Get("OverlayText")
annot.Repeat = d.Get("Repeat")
annot.DA = d.Get("DA")
annot.Q = d.Get("Q")
return &annot, nil
}
func (a *PdfAnnotation) GetContainingPdfObject() core.PdfObject {
return a.primitive
}
// Note: Call the sub-annotation's Tocore.PdfObject to set both the generic and non-generic information.
// TODO/FIXME: Consider doing it here instead.
func (a *PdfAnnotation) ToPdfObject() core.PdfObject {
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
d.Set("Type", core.MakeName("Annot"))
d.SetIfNotNil("Rect", a.Rect)
d.SetIfNotNil("Contents", a.Contents)
d.SetIfNotNil("P", a.P)
d.SetIfNotNil("NM", a.NM)
d.SetIfNotNil("M", a.M)
d.SetIfNotNil("F", a.F)
d.SetIfNotNil("AP", a.AP)
d.SetIfNotNil("AS", a.AS)
d.SetIfNotNil("Border", a.Border)
d.SetIfNotNil("C", a.C)
d.SetIfNotNil("StructParent", a.StructParent)
d.SetIfNotNil("OC", a.OC)
return container
}
// Markup portion of the annotation.
func (a *PdfAnnotationMarkup) appendToPdfDictionary(d *core.PdfObjectDictionary) {
d.SetIfNotNil("T", a.T)
if a.Popup != nil {
d.Set("Popup", a.Popup.ToPdfObject())
}
d.SetIfNotNil("CA", a.CA)
d.SetIfNotNil("RC", a.RC)
d.SetIfNotNil("CreationDate", a.CreationDate)
d.SetIfNotNil("IRT", a.IRT)
d.SetIfNotNil("Subj", a.Subj)
d.SetIfNotNil("RT", a.RT)
d.SetIfNotNil("IT", a.IT)
d.SetIfNotNil("ExData", a.ExData)
}
func (a *PdfAnnotationText) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
if a.PdfAnnotationMarkup != nil {
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
}
d.SetIfNotNil("Subtype", core.MakeName("Text"))
d.SetIfNotNil("Open", a.Open)
d.SetIfNotNil("Name", a.Name)
d.SetIfNotNil("State", a.State)
d.SetIfNotNil("StateModel", a.StateModel)
return container
}
func (a *PdfAnnotationLink) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
d.SetIfNotNil("Subtype", core.MakeName("Link"))
d.SetIfNotNil("A", a.A)
d.SetIfNotNil("Dest", a.Dest)
d.SetIfNotNil("H", a.H)
d.SetIfNotNil("PA", a.PA)
d.SetIfNotNil("QuadPoints", a.QuadPoints)
d.SetIfNotNil("BS", a.BS)
return container
}
func (a *PdfAnnotationFreeText) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("FreeText"))
d.SetIfNotNil("DA", a.DA)
d.SetIfNotNil("Q", a.Q)
d.SetIfNotNil("RC", a.RC)
d.SetIfNotNil("DS", a.DS)
d.SetIfNotNil("CL", a.CL)
d.SetIfNotNil("IT", a.IT)
d.SetIfNotNil("BE", a.BE)
d.SetIfNotNil("RD", a.RD)
d.SetIfNotNil("BS", a.BS)
d.SetIfNotNil("LE", a.LE)
return container
}
func (a *PdfAnnotationLine) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("Line"))
d.SetIfNotNil("L", a.L)
d.SetIfNotNil("BS", a.BS)
d.SetIfNotNil("LE", a.LE)
d.SetIfNotNil("IC", a.IC)
d.SetIfNotNil("LL", a.LL)
d.SetIfNotNil("LLE", a.LLE)
d.SetIfNotNil("Cap", a.Cap)
d.SetIfNotNil("IT", a.IT)
d.SetIfNotNil("LLO", a.LLO)
d.SetIfNotNil("CP", a.CP)
d.SetIfNotNil("Measure", a.Measure)
d.SetIfNotNil("CO", a.CO)
return container
}
func (a *PdfAnnotationSquare) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
if a.PdfAnnotationMarkup != nil {
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
}
d.SetIfNotNil("Subtype", core.MakeName("Square"))
d.SetIfNotNil("BS", a.BS)
d.SetIfNotNil("IC", a.IC)
d.SetIfNotNil("BE", a.BE)
d.SetIfNotNil("RD", a.RD)
return container
}
func (a *PdfAnnotationCircle) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("Circle"))
d.SetIfNotNil("BS", a.BS)
d.SetIfNotNil("IC", a.IC)
d.SetIfNotNil("BE", a.BE)
d.SetIfNotNil("RD", a.RD)
return container
}
func (a *PdfAnnotationPolygon) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("Polygon"))
d.SetIfNotNil("Vertices", a.Vertices)
d.SetIfNotNil("LE", a.LE)
d.SetIfNotNil("BS", a.BS)
d.SetIfNotNil("IC", a.IC)
d.SetIfNotNil("BE", a.BE)
d.SetIfNotNil("IT", a.IT)
d.SetIfNotNil("Measure", a.Measure)
return container
}
func (a *PdfAnnotationPolyLine) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("PolyLine"))
d.SetIfNotNil("Vertices", a.Vertices)
d.SetIfNotNil("LE", a.LE)
d.SetIfNotNil("BS", a.BS)
d.SetIfNotNil("IC", a.IC)
d.SetIfNotNil("BE", a.BE)
d.SetIfNotNil("IT", a.IT)
d.SetIfNotNil("Measure", a.Measure)
return container
}
func (a *PdfAnnotationHighlight) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("Highlight"))
d.SetIfNotNil("QuadPoints", a.QuadPoints)
return container
}
func (a *PdfAnnotationUnderline) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("Underline"))
d.SetIfNotNil("QuadPoints", a.QuadPoints)
return container
}
func (a *PdfAnnotationSquiggly) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("Squiggly"))
d.SetIfNotNil("QuadPoints", a.QuadPoints)
return container
}
func (a *PdfAnnotationStrikeOut) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("StrikeOut"))
d.SetIfNotNil("QuadPoints", a.QuadPoints)
return container
}
func (a *PdfAnnotationCaret) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("Caret"))
d.SetIfNotNil("RD", a.RD)
d.SetIfNotNil("Sy", a.Sy)
return container
}
func (a *PdfAnnotationStamp) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("Stamp"))
d.SetIfNotNil("Name", a.Name)
return container
}
func (a *PdfAnnotationInk) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("Ink"))
d.SetIfNotNil("InkList", a.InkList)
d.SetIfNotNil("BS", a.BS)
return container
}
func (a *PdfAnnotationPopup) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
d.SetIfNotNil("Subtype", core.MakeName("Popup"))
d.SetIfNotNil("Parent", a.Parent)
d.SetIfNotNil("Open", a.Open)
return container
}
func (a *PdfAnnotationFileAttachment) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("FileAttachment"))
d.SetIfNotNil("FS", a.FS)
d.SetIfNotNil("Name", a.Name)
return container
}
func (a *PdfAnnotationRichMedia) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
d.SetIfNotNil("Subtype", core.MakeName("RichMedia"))
d.SetIfNotNil("RichMediaSettings", a.RichMediaSettings)
d.SetIfNotNil("RichMediaContent", a.RichMediaContent)
return container
}
func (a *PdfAnnotationSound) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("Sound"))
d.SetIfNotNil("Sound", a.Sound)
d.SetIfNotNil("Name", a.Name)
return container
}
func (a *PdfAnnotationMovie) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
d.SetIfNotNil("Subtype", core.MakeName("Movie"))
d.SetIfNotNil("T", a.T)
d.SetIfNotNil("Movie", a.Movie)
d.SetIfNotNil("A", a.A)
return container
}
func (a *PdfAnnotationScreen) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
d.SetIfNotNil("Subtype", core.MakeName("Screen"))
d.SetIfNotNil("T", a.T)
d.SetIfNotNil("MK", a.MK)
d.SetIfNotNil("A", a.A)
d.SetIfNotNil("AA", a.AA)
return container
}
func (a *PdfAnnotationWidget) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
d.SetIfNotNil("Subtype", core.MakeName("Widget"))
d.SetIfNotNil("H", a.H)
d.SetIfNotNil("MK", a.MK)
d.SetIfNotNil("A", a.A)
d.SetIfNotNil("AA", a.AA)
d.SetIfNotNil("BS", a.BS)
d.SetIfNotNil("Parent", a.Parent)
return container
}
func (a *PdfAnnotationPrinterMark) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
d.SetIfNotNil("Subtype", core.MakeName("PrinterMark"))
d.SetIfNotNil("MN", a.MN)
return container
}
func (a *PdfAnnotationTrapNet) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
d.SetIfNotNil("Subtype", core.MakeName("TrapNet"))
return container
}
func (a *PdfAnnotationWatermark) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
d.SetIfNotNil("Subtype", core.MakeName("Watermark"))
d.SetIfNotNil("FixedPrint", a.FixedPrint)
return container
}
func (a *PdfAnnotation3D) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
d.SetIfNotNil("Subtype", core.MakeName("3D"))
d.SetIfNotNil("3DD", a.T3DD)
d.SetIfNotNil("3DV", a.T3DV)
d.SetIfNotNil("3DA", a.T3DA)
d.SetIfNotNil("3DI", a.T3DI)
d.SetIfNotNil("3DB", a.T3DB)
return container
}
func (a *PdfAnnotationProjection) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
return container
}
func (a *PdfAnnotationRedact) ToPdfObject() core.PdfObject {
a.PdfAnnotation.ToPdfObject()
container := a.primitive
d := container.PdfObject.(*core.PdfObjectDictionary)
a.PdfAnnotationMarkup.appendToPdfDictionary(d)
d.SetIfNotNil("Subtype", core.MakeName("Redact"))
d.SetIfNotNil("QuadPoints", a.QuadPoints)
d.SetIfNotNil("IC", a.IC)
d.SetIfNotNil("RO", a.RO)
d.SetIfNotNil("OverlayText", a.OverlayText)
d.SetIfNotNil("Repeat", a.Repeat)
d.SetIfNotNil("DA", a.DA)
d.SetIfNotNil("Q", a.Q)
return container
}
// Border definitions.
type BorderStyle int
const (
BorderStyleSolid BorderStyle = iota
BorderStyleDashed BorderStyle = iota
BorderStyleBeveled BorderStyle = iota
BorderStyleInset BorderStyle = iota
BorderStyleUnderline BorderStyle = iota
)
func (bs *BorderStyle) GetPdfName() string {
switch *bs {
case BorderStyleSolid:
return "S"
case BorderStyleDashed:
return "D"
case BorderStyleBeveled:
return "B"
case BorderStyleInset:
return "I"
case BorderStyleUnderline:
return "U"
}
return "" // Should not happen.
}
// Border style
type PdfBorderStyle struct {
W *float64 // Border width
S *BorderStyle // Border style
D *[]int // Dash array.
container core.PdfObject
}
func NewBorderStyle() *PdfBorderStyle {
bs := &PdfBorderStyle{}
return bs
}
func (bs *PdfBorderStyle) SetBorderWidth(width float64) {
bs.W = &width
}
func (bs *PdfBorderStyle) GetBorderWidth() float64 {
if bs.W == nil {
return 1 // Default.
}
return *bs.W
}
func (a *PdfBorderStyle) ToPdfObject() core.PdfObject {
d := core.MakeDict()
if a.container != nil {
if indObj, is := a.container.(*core.PdfIndirectObject); is {
indObj.PdfObject = d
}
}
d.Set("Subtype", core.MakeName("Border"))
if a.W != nil {
d.Set("W", core.MakeFloat(*a.W))
}
if a.S != nil {
d.Set("S", core.MakeName(a.S.GetPdfName()))
}
if a.D != nil {
d.Set("D", core.MakeArrayFromIntegers(*a.D))
}
if a.container != nil {
return a.container
} else {
return d
}
}
// Border effect
type BorderEffect int
const (
BorderEffectNoEffect BorderEffect = iota
BorderEffectCloudy BorderEffect = iota
)
type PdfBorderEffect struct {
S *BorderEffect // Border effect type
I *float64 // Intensity of the effect
}