Documentation
¶
Index ¶
Constants ¶
const (
// DefaultDPI is the standard rasterization density (200 DPI).
DefaultDPI = 200
)
Variables ¶
var ( // ErrInvalidDocument indicates an unsupported document parameter type or nil document. ErrInvalidDocument = errors.New("unsupported pdfDocOrPath: expected *Document, string (file path), []byte, or io.Reader") // ErrInvalidYear indicates a non-positive year was provided. ErrInvalidYear = errors.New("year must be positive") // ErrPageOutOfBounds indicates a requested page index exceeds document bounds. ErrPageOutOfBounds = errors.New("page index out of bounds") )
Functions ¶
func IndexPlannerDates ¶
IndexPlannerDates scans the pages of a reMarkable planner template PDF and indexes dates matching "Month Day Weekday Notes/Day" into a nested mapping: map[YYYY-MM-DD]map[day|notes]pageIdx.
Accepts *Document, string (file path), []byte, or io.Reader. For each matching date: - A page containing "Notes" in its header represents the "day" view (pointing to its notes companion). - A page containing "Day" in its header represents the "notes" view (pointing back to its day companion).
The header is the first nonempty text line. When that line starts with a month and day followed only by abbreviated weekday/day navigation pairs, the next line also belongs to the header if it starts with a full weekday. Dates must be valid in year; printed years and weekday/date agreement are not checked. Notes takes precedence over Day, including holiday names. Duplicate views return an error naming both page indexes and no index. A page whose text carries no valid header is skipped. A failed PDFium text request for any page, including one that returns no response or one made on a released *Document, returns an error naming the 0-based page index and no index.
func RenderPlannerPage ¶
RenderPlannerPage renders a specific background PDF page at the target DPI. If rmBytes is provided (non-empty), it converts the .rm stroke data to SVG using rmscene.RenderRMToSVG, rasterizes the SVG to exact page pixel dimensions with resvg-go, and composites the stroke layer over the PDF background using image/draw. Returns the final composited image as encoded PNG bytes. With strokes, unreadable, nonpositive or nonfinite PDF page dimensions return an error instead of substituting a default SVG viewport.
Accepts *Document, string (file path), []byte, or io.Reader for pdfDocOrPath.
Types ¶
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document wraps an open PDFium document instance.
func OpenDocumentFromBytes ¶
OpenDocumentFromBytes opens a PDF document from raw byte slice using PDFium WebAssembly. Call the returned cleanup function to release the document. A failure to open the document or to read its page count returns an error and releases everything acquired.
func (*Document) Links ¶
Links extracts internal link targets and external hyperlinks from a page, with each link's rectangle and the page text inside it. A page without links yields an empty list and a nil error. Any failed PDFium request returns an error and no links.
type PageLink ¶
type PageLink struct {
// Index is the 0-based position of the link among the page's links.
Index int
// TargetPage is the 0-based page of this document the link leads to, or
// -1 when it leads to no page of this document.
TargetPage int
// URI is "#page=N" (TargetPage+1) for a link to a page of this document.
// For a URI action it is the URI PDFium reports: the raw bytes of the
// /URI string, not validated as UTF-8. When the document catalog has a
// /URI /Base and the /URI string contains no ':' or starts with one,
// PDFium concatenates the base in front of it. That is plain string
// concatenation, not RFC 3986 reference resolution, so it can produce a
// malformed URL (base "https://a/b.html" and "c.html" yield
// "https://a/b.htmlc.html"), and a URI with ':' after its first byte is
// never prefixed. Without a /Base, a relative URI is returned as written.
// URI is empty for a URI action whose /URI string is empty in a document
// without a /Base, and for any other link, such as a remote go-to,
// launch, or named action, or a link whose destination does not resolve.
URI string
// Rect is the link annotation's /Rect, the area that activates the link.
// PDFium reports a missing /Rect, or one that is not a four-element
// array, as the zero Rect.
Rect Rect
// Text is the page text PDFium reports inside Rect, in the page's text
// order, with every run of white space (unicode.IsSpace, including the
// "\r\n" PDFium inserts between text lines) replaced by one space and
// leading and trailing white space removed. PDFium includes every
// character whose box overlaps Rect with a non-zero area, so a character
// partly inside Rect counts in full while the rest of its word does not.
// Text is empty when Rect covers no text, such as a link drawn over
// handwriting or an image.
Text string
}
PageLink represents a resolved link annotation on a page.
type Rect ¶
Rect is a rectangle in the page's default user space, as written in the PDF: units are points (1/72 inch unless the page sets /UserUnit), y grows upwards, and the page's /MediaBox or /CropBox origin and /Rotate are not applied. On a page whose media box starts at [0 0], (0, 0) is the bottom-left corner. The fields follow the order of a PDF rectangle array, [Left Bottom Right Top], and are normalized so that Left <= Right and Bottom <= Top whichever pair of opposite corners the PDF lists.