pdfpagedata

package module
v0.0.0-...-629599d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2020 License: AGPL-3.0 Imports: 10 Imported by: 4 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

pdfpagedata

read/write gradex pagedata frompdf pages

Why

Tracking pages in PDF documents when they are split into separate files can be done a couple of ways

-- postpend something to the filename for page -- put info in metadata -- use some page text, off page -- protocol buf into stream object

Unfortunately, processing thousands of pages, though different hands, needs more safety than fragile filenames can provide. Plus we will have duplicate files with non-duplicate annotations. So what do we do when two people re-upload their different files with the same name, and then either overwrite or make some modification to the filename? How do we recover from an unfortunate name choice here?

We could stash info in the metadata, but that tends to be file-level, so it is not clear how to handle duplicate custom metadata fields when multiple files from different documents are joined, then split, then joined again etc. Bseides, I've seen editors mess with the metadata, and I don't fancy users editing it either.

Off-page page text seems fragile too, but I get some comfort from reading that people an NOT crop when they want to. A test has been included for this very purpose -which is passing.

Wrinkles

text written in the same place gets read back out in some sort of merged way, so pageData is written in a tiny font (like 0.00001) and randomly scattered around a location that is far off the page. Tag destruction is detected (such as for clases), and multiple page datas on a page are supported.

A collision is possible ... we could always consider writing each hidden data twice ...

Future

Protocol buf into a stream object seems like a more robust way (and it avoids crop and collision worries) but it is probably about a half-day or a day to develop so that makes it a roadmap item for now.

Documentation

Index

Constants

View Source
const (
	Raw             = iota
	ReadyToMark     = iota
	Marked          = iota
	ReadyToModerate = iota
	Moderated       = iota
	ReadyToCheck    = iota
	Checked         = iota
)

UnixTime is not all that portable as it is ... so only using it as a tiebreaker when likely that the process was repeated on the same machine For cases where marking is repeated after checking The overlay SHOULD just use a higher sequence number, sequence number is a step in sequence, not another name for a particular process

View Source
const (
	StartTag       = "<gradex-pagedata>"
	EndTag         = "</gradex-pagedata>"
	StartTagOffset = len(StartTag)
	EndTagOffset   = len(EndTag)
)

Variables

This section is empty.

Functions

func ExtractPageData

func ExtractPageData(pageText string) []string

func GetLen

func GetLen(input map[int][]PageData) int

func GetPageDataFromFile

func GetPageDataFromFile(inputPath string) (map[int][]PageData, error)

func MarshalPageData

func MarshalPageData(c *creator.Creator, pd *PageData) error

func OutputPdfText

func OutputPdfText(inputPath string) ([]string, error)

outputPdfText produces array of strings, one string per page mod from https://github.com/unidoc/unipdf-examples/blob/master/text/pdf_extract_text.go

func PruneOldRevisions

func PruneOldRevisions(pdmap *map[int][]PageData) error

func ReadPageData

func ReadPageData(page *pdf.PdfPage) ([]string, error)

func ReadPageString

func ReadPageString(page *pdf.PdfPage) (string, error)

func WritePageData

func WritePageData(c *creator.Creator, text string)

func WritePageString

func WritePageString(c *creator.Creator, text string)

Types

type AuthorDetails

type AuthorDetails struct {
	Anonymous string `json:"Anonymous"`
	Identity  string `json:"Identity"`
}

type ContactDetails

type ContactDetails struct {
	Name    string `json:"name"`
	UUID    string `json:"UUID"`
	Email   string `json:"email"`
	Address string `json:"address"`
}

type CustomDetails

type CustomDetails struct {
	Key   string `json:"name"`
	Value string `json:"value"`
}

type ExamDetails

type ExamDetails struct {
	CourseCode string `json:"courseCode"`
	Diet       string `json:"diet"`
	Date       string `json:"date"`
	UUID       string `json:"UUID"`
}

type MarkDetails

type MarkDetails struct {
	Given     float64 `json:"given"`
	Available float64 `json:"available"`
	Comment   float64 `json:"comment"`
}

type MarkingAction

type MarkingAction struct {
	Actor    string         `json:"actor"`
	Contact  ContactDetails `json:"contact"`
	Mark     MarkDetails    `json:"mark"`
	Done     bool           `json:"done"`
	UnixTime int64          `json:"unixTime"`
	Custom   CustomDetails  `json:"custom"`
}

type PageData

type PageData struct {
	Exam        ExamDetails         `json:"exam"`
	Author      AuthorDetails       `json:"author"`
	Page        PageDetails         `json:"page"`
	Contact     ContactDetails      `json:"contact"`
	Submission  SubmissionDetails   `json:"submission"`
	Questions   []QuestionDetails   `json:"questions"`
	Processing  []ProcessingDetails `json:"processing"`
	Custom      []CustomDetails     `json:"custom"`
	Revision    int                 `json:"revision"`
	PreparedFor string              `json:"preparedfor"`
	ToDo        string              `json:"todo"`
}

func SelectPageDataByRevision

func SelectPageDataByRevision(pds []PageData) (PageData, error)

func StripAuthorIdentity

func StripAuthorIdentity(pd PageData) PageData

this function is for use in a co-operative environment - you can slip one past the gaolie in the custom fields in Questions/Processing/Custom

func UnmarshalPageData

func UnmarshalPageData(page *pdf.PdfPage) ([]PageData, error)

type PageDetails

type PageDetails struct {
	UUID     string `json:"UUID"`
	Number   int    `json:"number"`
	Of       int    `json:"of"`
	Filename string `json:"filename"`
}

type ParameterDetails

type ParameterDetails struct {
	Name     string `json:"name"`
	Value    string `json:"value"`
	Sequence int    `json:"sequence"`
}

type PdfSummary

type PdfSummary struct {
	CourseCode  string
	PreparedFor string
	ToDo        string
}

func TriagePdf

func TriagePdf(inputPath string) (PdfSummary, error)

type ProcessingDetails

type ProcessingDetails struct {
	UUID       string             `json:"UUID"`
	Previous   string             `json:"previous"`
	UnixTime   int64              `json:"unixTime"`
	Name       string             `json:"name"`
	Parameters []ParameterDetails `json:"parameters"`
	By         ContactDetails     `json:"by"`
	Sequence   int                `json:"sequence"`
}

func SelectProcessByLast

func SelectProcessByLast(pd PageData) (ProcessingDetails, error)

type QuestionDetails

type QuestionDetails struct {
	UUID           string            `json:"UUID"`
	Name           string            `json:"name"` //what to call it in a dropbox etc
	Section        string            `json:"section"`
	Number         int               `json:"number"` //No Harry Potter Platform 9&3/4 questions
	Parts          []QuestionDetails `json:"parts"`
	MarksAvailable float64           `json:"marksAvailable"`
	MarksAwarded   float64           `json:"marksAwarded"`
	Marking        []MarkingAction   `json:"markers"`
	Moderating     []MarkingAction   `json:"moderators"`
	Checking       []MarkingAction   `json:"checkers"`
	Sequence       int               `json:"sequence"`
	UnixTime       int64             `json:"unixTime"`
	Previous       string            `json:"previous"`
}

use section for (a), (b) and number for (i)

func SelectQuestionByLast

func SelectQuestionByLast(pd PageData) (QuestionDetails, error)

type SubmissionDetails

type SubmissionDetails struct {
	FilePrefix       string `json:"filePrefix"`
	OriginalFilename string `json:"originalFilename"`
	OriginalFormat   string `json:"originalFormat"`
	NewFilename      string `json:"newFilename"`
	NewFormat        string `json:"newFormat"`
}

don't use this in anonymous pages

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址