Documentation
¶
Overview ¶
Package ops is the verb layer of go-pdfkit: what people actually do to a PDF they already have. Merge two files, pull out pages three to seven, turn a page the right way up, drop the metadata, split a report into chapters.
A document here is an ordered list of pages, each borrowed from a source file, plus the document-level pieces. Every operation rearranges that list or annotates its entries, and nothing is applied until Doc.Bytes is called. An operation therefore costs nothing until it has to, pages from several files mix freely, and the list stays a plain value.
Index ¶
- func BlankPages(pdf []byte, opt BlankOptions) ([]int, error)
- func FromXFA(src *reader.Document) (*Doc, *XFAReport, error)
- func ParseRange(spec string, pageCount int) ([]int, error)
- type Attachment
- type BlankOptions
- type Bookmark
- type Doc
- func (d *Doc) AddLayer(name, parent string) error
- func (d *Doc) Append(other *Doc)
- func (d *Doc) Attach(name string, data []byte, description string) error
- func (d *Doc) Attachments() []Attachment
- func (d *Doc) Bates(spec, prefix string, start, digits int) error
- func (d *Doc) Blank(width, height float64)
- func (d *Doc) Booklet() error
- func (d *Doc) Bytes() ([]byte, error)
- func (d *Doc) ClearInfo()
- func (d *Doc) Compress()
- func (d *Doc) Crop(spec string, box [4]float64) error
- func (d *Doc) Decrypt()
- func (d *Doc) Delete(spec string) error
- func (d *Doc) Detach(name string) bool
- func (d *Doc) Divide(across, down int) error
- func (d *Doc) DropBlank(opt BlankOptions) ([]int, error)
- func (d *Doc) DropLayer(name string) error
- func (d *Doc) DropOutlines()
- func (d *Doc) DuplexCollate(split int, reverseBacks bool) error
- func (d *Doc) Encrypt(e reader.Encryption)
- func (d *Doc) Flatten()
- func (d *Doc) Info() reader.Dict
- func (d *Doc) InsertBlank(i int) error
- func (d *Doc) Interleave(others ...*Doc) error
- func (d *Doc) Layers() []Layer
- func (d *Doc) Move(from, to int) error
- func (d *Doc) NUp(n int) error
- func (d *Doc) OnePage() error
- func (d *Doc) Overlay(other *Doc) error
- func (d *Doc) PageCount() int
- func (d *Doc) PageLabels() []string
- func (d *Doc) PageNumbers(spec, format string) error
- func (d *Doc) Picture(data []byte, dpi float64) error
- func (d *Doc) Poster(across, down int) error
- func (d *Doc) Protection() (reader.Protection, bool)
- func (d *Doc) RecolourText(spec string, r, g, b float64) error
- func (d *Doc) RemoveAnnotations()
- func (d *Doc) Repaired() bool
- func (d *Doc) Resize(spec string, box [4]float64) error
- func (d *Doc) Reverse()
- func (d *Doc) Rotate(spec string, degrees int) error
- func (d *Doc) Rotation(i int) (int, error)
- func (d *Doc) Sanitize()
- func (d *Doc) Select(spec string) error
- func (d *Doc) SetInfo(key reader.Name, value string)
- func (d *Doc) SetLayerVisible(name string, visible bool) error
- func (d *Doc) SetOutline(marks []Bookmark)
- func (d *Doc) SetPageLabels(rules []LabelRule) error
- func (d *Doc) SetRotation(spec string, degrees int) error
- func (d *Doc) SetVersion(v string)
- func (d *Doc) Split(n int) ([]*Doc, error)
- func (d *Doc) SplitAt(at ...int) ([]*Doc, error)
- func (d *Doc) Stamp(spec string, s Stamp) error
- func (d *Doc) Underlay(other *Doc) error
- func (d *Doc) UnreachedText() int
- func (d *Doc) Version() string
- func (d *Doc) Watermark(spec, text string) error
- type Filling
- type Font
- type LabelRule
- type LabelStyle
- type Layer
- type Page
- type Position
- type Stamp
- type XFAReport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlankPages ¶ added in v0.15.0
func BlankPages(pdf []byte, opt BlankOptions) ([]int, error)
BlankPages reports which pages of a file hold almost nothing, counting from one and in order.
Each page is DRAWN and its pixels counted, because that is the only test that agrees with a reader. A page whose content stream is full of operators painting white, or drawing outside the media box, looks blank and is blank; a page carrying an image of nothing is blank too, and no amount of reading the content stream says so.
⛔ What it will not do is call a page of solid colour blank. The test is distance from WHITE, not uniformity: a deliberately black separator sheet carries information, and a measure of variance would delete it.
func FromXFA ¶ added in v0.12.0
FromXFA lays out the XFA form a document carries and returns a document of its pages, drawn.
The source document's own pages are not kept: for a dynamic form they are the placeholder, and for a static one they are the form itself and this is the wrong verb — see forms.Form.Dynamic, which says which kind a document is. This does not refuse a static one, because a caller may legitimately want to see what the XML says as against what the pages show, but a caller that has not asked which kind it has will replace a perfectly good form with a plainer drawing of it.
func ParseRange ¶
ParseRange turns the page selection people write — "1-3,7,10-", "even", "last", "all" — into page numbers counting from one, in the order given and with duplicates kept, because "1,1,2" really does mean three pages.
A range with no start begins at the first page and one with no end runs to the last. A descending range like "5-2" counts down, which is how a reversed extract is written.
Types ¶
type Attachment ¶ added in v0.10.0
type Attachment struct {
// Name is what the document calls it.
Name string
// Description is what it says the file is, when it says anything.
Description string
// Data is the file.
Data []byte
}
An Attachment is a file travelling inside the document.
type BlankOptions ¶ added in v0.15.0
type BlankOptions struct {
// DPI is how finely the page is drawn before its pixels are counted. Zero
// means a hundred and fifty.
//
// ⛔ It is not fifty, which is what this first used and what a thumbnail
// would want. MEASURED on A4: at 50 DPI an eight-point full stop covers
// exactly ONE pixel, which is the same mark a speck of dust makes, so no
// threshold at that resolution can tell punctuation from dirt. At 150 it
// covers four and a comma covers eight. See TestMeasureTheInkLadder.
DPI float64
// Tolerance is how far a channel may be from white and still count as
// paper, out of 255. Zero means twelve.
//
// ⛔ Not zero-means-zero: nothing in a rendered page is exactly white.
// Anti-aliasing, a JPEG background and a scan of real paper all land a few
// levels below it, and a tolerance of zero calls every page inked.
Tolerance uint8
// MaxInk is the fraction of a page's pixels that may be ink and have the
// page still count as blank. The zero value keeps any page with a mark on
// it, which is what the zero value SHOULD mean here.
//
// For scans, where dust and the edge of the platen leave specks, the
// figures to set it from are these, measured on A4 at the default 150 DPI:
//
// one pixel 4.6e-07
// a full stop (8pt) 1.8e-06 (four pixels)
// a comma (8pt) 3.7e-06 (eight pixels)
// one word (12pt) 2.0e-04
//
// So 1e-06 tolerates a speck or two and still keeps a page holding a full
// stop. The margin is a factor of four, and it is not offered as a default
// because whether that margin holds depends on the scanner, which this
// package cannot see.
MaxInk float64
// MaxPixels is passed to the renderer, so a media box a file made up
// cannot be asked to fill memory.
MaxPixels int
// KeepAnnotations counts the notes, highlights and form fields a page
// carries as ink. They are NOT counted by default: a page whose only mark
// is a sticky note is blank paper somebody wrote on, and the note is not
// part of what was printed.
KeepAnnotations bool
}
BlankOptions say how little a page may hold and still count as blank.
⛔ The zero value is the STRICTEST setting, not a middle one: a page with a single inked pixel is kept. That is deliberate and it is the only safe default, because this is the input to deleting pages — a page wrongly called blank destroys content, while a blank page wrongly kept merely leaves a blank page.
type Bookmark ¶ added in v0.4.0
A Bookmark is an entry of an outline written from scratch: what it says, the page of this document it points at counting from one, and whatever sits under it.
It is what a document assembled rather than merged carries — a shared edit, a report built out of pieces — where there is no source outline to carry over because the outline is the caller's own.
type Doc ¶
type Doc struct {
// contains filtered or unexported fields
}
A Doc is a document being assembled: pages in the order they will be written, and the trailer's information dictionary.
func FromDocument ¶
FromDocument wraps an already-parsed document. Every page the document reports can be read — the page tree walk has already established that — so there is nothing here that can fail.
func OpenWithPassword ¶
OpenWithPassword reads a PDF file that may be encrypted.
func (*Doc) AddLayer ¶ added in v0.15.0
AddLayer adds an empty layer, under parent when parent names one.
⛔ The layer has NO CONTENT on it, and that is what adding one means: a template gains a layer for whoever draws on it next. Nothing in the document becomes hidden or shown by adding one.
func (*Doc) Append ¶
Append adds the pages of another document to the end of this one. The other document is not changed, and the two may come from different files.
func (*Doc) Attach ¶ added in v0.10.0
Attach puts a file inside the document, under a name.
The name is what a reader shows and what another tool looks it up by. Two files under one name is a document that has lost one of them, so a name already used is refused rather than quietly replacing what is there.
func (*Doc) Attachments ¶ added in v0.10.0
func (d *Doc) Attachments() []Attachment
Attachments are the files the document carries, in the order it names them.
A PDF can hold whole files inside it — the spreadsheet a report was drawn from, the XML a form was filled from, the source of a figure. They are not drawn and nothing on the page says they are there, which is why a tool that rewrites a document can drop them without anyone noticing until the file is wanted.
func (*Doc) Bates ¶
Bates numbers the pages a range names with a running serial, the way a legal exhibit is marked: a fixed prefix and a zero-padded counter.
func (*Doc) Booklet ¶
Booklet reorders the pages for saddle-stitch printing — folded in half and stapled through the spine — and lays them two to a sheet. Blank pages are added so the count is a multiple of four, which is what folding needs.
func (*Doc) Bytes ¶
Bytes writes the document out as a PDF file. Every borrowed page is copied out of the file it came from with the attributes it inherited written onto it, so pages from different documents keep their own geometry and resources.
func (*Doc) ClearInfo ¶
func (d *Doc) ClearInfo()
ClearInfo drops the whole information dictionary, which is what "remove the metadata" means.
func (*Doc) Compress ¶ added in v0.2.0
func (d *Doc) Compress()
Compress asks for the file to be written with its objects packed into compressed streams and a cross-reference stream, which is what every writer since PDF 1.5 does and what makes a file a good deal smaller. It costs nothing but a version of 1.5, which every reader in use has understood for twenty years.
func (*Doc) Crop ¶
Crop sets the visible area of the pages the range names, in points, as [left bottom right top]. It sets the crop box; the media box, which is the paper the page is on, is left alone.
func (*Doc) Decrypt ¶ added in v0.2.0
func (d *Doc) Decrypt()
Decrypt writes the file without protection. A document opened with the right password is already decrypted, so this only undoes an earlier call to Doc.Encrypt; a file read with OpenWithPassword and written out is unprotected either way.
func (*Doc) Detach ¶ added in v0.10.0
Detach removes the file of that name, and says whether there was one.
func (*Doc) Divide ¶ added in v0.15.0
Divide cuts each page into an across×down grid of smaller pages, each the size of the piece it holds.
It is for a page that holds things which should have been separate: a two-page spread scanned as one wide sheet, two tickets printed side by side, a sheet of labels. Dividing a wide spread down the middle with Divide(2, 1) gives two pages of half the width, each of them the page it was before somebody put two on a sheet.
⛔ This is NOT Doc.Poster, although the grid is the same. Poster keeps every sheet the size of the page it came from, which means it ENLARGES: the pieces printed and taped together make one page the size of a wall. Divide keeps the content at its own size and makes the pages smaller, so the pieces laid side by side are the page again at 1:1. Confusing the two gives a result that looks right in a thumbnail and is wrong by a factor of across and down — which is why the distinction is in both doc comments rather than left to whoever reads the grid arguments.
The pieces come out in reading order: left to right, top to bottom, the top-left one first.
The cuts meet exactly. Nothing is repeated from one piece to the next and no bleed is left, because Divide is told how many pieces to make and not what a trimmer needs; every part of the page lands on one piece and one only, so the pieces are exactly the page again.
func (*Doc) DropBlank ¶ added in v0.15.0
func (d *Doc) DropBlank(opt BlankOptions) ([]int, error)
DropBlank removes the pages that hold almost nothing and reports which went, numbered as they were BEFORE the removal — because a caller who wants to say what happened needs the numbers the reader saw.
⛔ It refuses to empty the document. A file of no pages is still a file: it opens, it has a size, and a caller who handed over a stack of scans that turned out to be blank would be told nothing was wrong while being given something no reader can show. Every page blank is a result worth an error.
func (*Doc) DropLayer ¶ added in v0.15.0
DropLayer removes a layer.
⛔ WHAT WAS DRAWN ON IT DOES NOT GO WITH IT. The content stays in the page and stops being optional, so a HIDDEN layer that is dropped becomes permanently visible — which is the opposite of what somebody deleting a layer called "internal pricing" expects. Removing the content as well would mean rewriting every content stream that mentions the layer, which this does not do; the refusal below is the honest half of that.
func (*Doc) DropOutlines ¶
func (d *Doc) DropOutlines()
DropOutlines leaves the bookmarks behind. They are kept by default: a merge that loses every bookmark is a poor merge.
func (*Doc) DuplexCollate ¶ added in v0.15.0
DuplexCollate puts a duplex stack back in reading order.
An automatic feeder that cannot turn a sheet over leaves ONE file holding two blocks: every front, then every back. This cuts it at split and interleaves the two halves, so front1, back1, front2, back2 and on.
A split of zero or less means the middle, rounded UP — ceil(n/2) — because an odd stack has the unpaired sheet at the END of the fronts, not the start of the backs. Thirteen pages split at seven, not six.
⛔ reverseBacks is not a convenience, it is the common case: the stack is turned over AS A STACK, so the last sheet's back is scanned first. Without it a thirty-sheet batch comes out with every back on the wrong front, which is a defect that reads as "the scan is fine, the order is odd" rather than as a reversal.
Blocks of different sizes do not stop it: the pairs collate first and whatever is left over follows in order, which is what the last single-sided sheet of a batch leaves behind.
func (*Doc) Encrypt ¶ added in v0.2.0
func (d *Doc) Encrypt(e reader.Encryption)
Encrypt protects the file that will be written. Two people can open it: whoever knows the user password, subject to the permissions, and whoever knows the owner password, subject to nothing.
An encrypted file is not byte-for-byte reproducible — encryption needs randomness, by design — so a document written twice with the same call comes out different both times, and neither can be compared with the other.
func (*Doc) Flatten ¶
func (d *Doc) Flatten()
Flatten draws each annotation's own appearance into the page and then drops the annotation, so what one reader sees is what every reader sees — which is what filling in a form and then flattening it means.
func (*Doc) InsertBlank ¶
InsertBlank puts an empty page before the page at i, counting from one; an index one past the end appends. The size is taken from the page it precedes, or from the one before it at the end of the document.
func (*Doc) Interleave ¶ added in v0.9.0
Interleave takes pages from each document in turn — the first of this, the first of the next, and round again — until every one of them is used up.
It is what a duplex scanner leaves behind. A stack fed through a single-sided feeder twice comes out as two files: the fronts in order, and the backs, which is the same document taken apart. Merging them end to end gives every front then every back; this gives the document.
The backs are usually in reverse: the stack is turned over as a stack, so the last sheet's back is scanned first. Reverse that one before interleaving and the pages land in the right order.
Documents of different lengths do not stop it. A shorter one simply runs out, and the rest of the longer one follows in order — which is what a scanner leaves when the last sheet is single-sided.
func (*Doc) Layers ¶ added in v0.15.0
Layers reports the document's layers, in the order the document asks them to be shown and with their nesting.
A document with no optional content has none.
func (*Doc) Move ¶
Move takes the page at from and puts it at to, both counting from one, the other pages closing up behind it.
func (*Doc) NUp ¶
NUp lays n pages on each sheet, in reading order. The sheet keeps the size of the first page, and the grid is whichever arrangement of at least n cells gives cells closest in shape to the pages going into them.
func (*Doc) OnePage ¶ added in v0.9.0
OnePage puts every page on a single sheet, one below the other.
A page is a unit of paper, not a unit of reading: a receipt, a chat log and a web page cut into A4 are one thing that a printer divided. This puts them back, so what is read scrolls rather than turns.
The sheet is as wide as the widest page and as tall as all of them stacked. Pages narrower than the widest are centred, because a column of text that jumps from side to side is harder to read than one that does not.
func (*Doc) Overlay ¶
Overlay draws each page of another document on top of the pages here, in order. When the other document has fewer pages its last page is not repeated: pages past its end are left alone.
func (*Doc) PageLabels ¶ added in v0.15.0
PageLabels reports what each page of the document is labelled, in order, as a viewer would show it. A page with no label comes back as "".
It answers for the document as it stands: the labels a caller set, or the ones carried over from the files the pages came from.
func (*Doc) PageNumbers ¶
PageNumbers writes a number at the foot of the pages a range names. The format is a stamp's text, so "{page} of {pages}" and "— {page} —" both work.
func (*Doc) Picture ¶ added in v0.8.0
Picture adds a page holding one image, the size of the image.
This is the other half of drawing a page: a scanner, a camera and a screenshot all produce a picture, and what people want of a PDF toolkit is to be handed one back with the picture in it.
Every format go-gfx/gfx reads is accepted, which is more than a PDF can carry. A JPEG is put in as it stands, because a PDF carries JPEG and re-encoding one loses a little of it for nothing; everything else is decoded and written as samples, compressed. An image with any transparency in it gets a soft mask, so a PNG drawn over the page's white does not come out with black behind it.
dpi says how many of the image's pixels go into an inch of paper; 0 means 72, one point per pixel. A photograph from a telephone at 72 is a page the size of a wall, and at 300 it is a photograph.
func (*Doc) Poster ¶ added in v0.11.0
Poster spreads each page over across×down sheets, so that the sheets printed and taped edge to edge make one page the size of a wall. It is the inverse of Doc.NUp, which puts several pages on one sheet.
Every sheet is the size of the page it came from. A poster of an A4 document therefore prints on A4, and each piece has the page's own proportions — pieces of some other shape do not tape back into the page they were cut from. Because the sheets keep their shape, a wall of them is only the page's shape again when across and down are equal; otherwise the page is enlarged as far as it will go inside the wall and centred, and the sheets at the edges carry the white that is left over.
The sheets meet exactly: nothing is repeated from one to the next, and no margin is left for taping. An overlap would have to be a constant here, because Poster is told how many sheets to use and not how wide the printer's unprinted border is; too small a guess still leaves a seam, too large a one loses more of the poster to trimming than it saves, and neither could be turned off. Meeting exactly is also the only arrangement that is exactly undone: every part of the page lands on one sheet and one only, so the pieces butt together — taped from behind — with nothing to cut away and nothing printed twice.
The sheets come out in reading order: left to right, top to bottom, the top-left one first, so a printed pile can be laid out on a table in the order it came off the printer.
func (*Doc) Protection ¶ added in v0.2.0
func (d *Doc) Protection() (reader.Protection, bool)
Protection reports how the file this document was read from was protected, and false when it was not protected at all — or when the document was not read from a file. It says nothing about how the document will be written: that is what was passed to Doc.Encrypt.
func (*Doc) RecolourText ¶ added in v0.16.0
RecolourText paints the text of the pages a range names in one colour, leaving everything else on the page as it was.
The colour is red, green and blue, each from zero to one.
⛔ It reaches the text in each PAGE'S OWN content stream. Text drawn through a Form XObject is NOT recoloured, and the reason is not that it would be hard: an XObject is SHARED, so recolouring one would change pages the caller did not name. Doc.RecolourText therefore counts what it could not reach and Doc.UnreachedText reports it — because a tool that silently did nothing to a document whose text is all in XObjects would be worse than one that refused.
func (*Doc) RemoveAnnotations ¶
func (d *Doc) RemoveAnnotations()
RemoveAnnotations drops every annotation: links, comments, form fields and all. What was drawn on the page stays; what sat on top of it goes.
func (*Doc) Repaired ¶ added in v0.15.0
Repaired says whether any file this document's pages came from had to be rebuilt before it could be read: a cross-reference table that did not match the objects, a trailer that was not there, an offset that pointed into the middle of something else.
reader does the rebuilding on its own, and quietly, which is the right behaviour for a reader — a caller asking for page three wants page three, not a lecture. But it leaves nobody able to SAY it happened, and that is worth saying for two different reasons: a file that needed rebuilding should be written back out and kept in its rebuilt form, and a file that did not need it should not be presented as rescued.
⛔ ANY, not all. A merged document's pages come from several files, and one damaged source is the answer to "did this need repairing": a true that depended on every source being broken would be false for every real merge.
func (*Doc) Rotate ¶
Rotate turns the pages the range names by the given number of degrees, which must be a multiple of ninety. The rotation is relative to what the page already had, so rotating twice by ninety turns a page upside down.
func (*Doc) Sanitize ¶
func (d *Doc) Sanitize()
Sanitize strips the parts of a file that do something rather than show something: page and annotation actions, JavaScript, launching, form submission, files travelling with a page, and the annotation types that exist to embed or play something.
A document written by this package always carries a catalogue of this package's own making, so document-level scripts, automatic actions on opening and embedded file trees are gone whatever this setting says; sanitising deals with what travels attached to a page.
func (*Doc) Select ¶
Select keeps only the pages the range names, in the order it names them, so it extracts, reorders and duplicates in one verb.
func (*Doc) SetInfo ¶
SetInfo replaces one entry of the information dictionary. An empty value removes it.
func (*Doc) SetLayerVisible ¶ added in v0.15.0
SetLayerVisible turns a layer on or off.
⛔ A LOCKED layer is refused. The lock is the document asking that this one not be switched — a drawing's dimension layer that everything else is positioned against — and a tool that switched it anyway would be ignoring the only thing the file says about its own layers.
func (*Doc) SetOutline ¶ added in v0.4.0
SetOutline writes these bookmarks rather than carrying over the ones the sources had. An entry pointing at a page this document has not got is left out, and so is everything under it: a heading whose section has gone is not a heading any more.
Passing nothing puts the sources' own bookmarks back.
func (*Doc) SetPageLabels ¶ added in v0.15.0
SetPageLabels replaces the document's page labels.
The rules are applied in order, so a later rule wins where two overlap. A page no rule names has no label, and a viewer then shows its position in the file — which is the right answer and is what an unlabelled document does.
Passing no rules removes the labels.
func (*Doc) SetRotation ¶
SetRotation turns the pages the range names to an absolute angle.
func (*Doc) SetVersion ¶
SetVersion sets the version written in the header.
func (*Doc) SplitAt ¶
SplitAt cuts the document before each of the given page numbers, which is how a report is broken into chapters.
func (*Doc) UnreachedText ¶ added in v0.16.0
UnreachedText reports how many text-showing operations the last write left in a colour of their own because they are inside a Form XObject, which is shared and so cannot be recoloured for one page without changing others.
It is zero until the document has been written, because until then there is nothing to have reached.
type Filling ¶ added in v0.5.0
type Filling struct {
// contains filtered or unexported fields
}
A Filling is a document's form, opened so that it can be filled in and written back.
func OpenForm ¶ added in v0.5.0
OpenForm reads a document's form. It reports false, with no error, for a document that simply has none — including one carrying an AcroForm dictionary a producer left behind with an empty field list, which 561 of the figure corpus's 118 833 files do.
func OpenFormWithPassword ¶ added in v0.5.0
OpenFormWithPassword is the same for a document that is protected.
func (*Filling) Bytes ¶ added in v0.5.0
Bytes writes the original file with the changes appended to it.
type Font ¶
type Font string
A Font names one of the four faces this package can draw with.
type LabelRule ¶ added in v0.15.0
type LabelRule struct {
// Pages is a range in this package's usual form: "1-4", "7", "odd",
// "1-9,30-40". Empty means every page.
Pages string
// Style is how the number is written. The zero value writes no number,
// which is [LabelNone] and is a style rather than an omission.
Style LabelStyle
// Prefix goes before the number: "A-" makes A-1, A-2, A-3.
Prefix string
// Start is the value of the first label in the range. Zero means one.
//
// ⛔ It must be at least one, and that is the FORMAT's rule rather than a
// choice here: ISO 32000-1 table 159 says /St "shall be greater than or
// equal to 1". A zero-based numbering scheme cannot be written as a
// numeric style at all, so Start of less than one is refused rather than
// written out of specification — a file that opens in one viewer and
// renumbers itself in another is worse than a refusal.
Start int
// Continue carries the numbering across the pieces of a DISJOINT range.
//
// ⛔ A page-label range in a PDF is CONTIGUOUS: the file holds the first
// page of each run and the viewer counts forward from there, so a rule
// over "1-9,30-40" has to become two runs. Without Continue the second
// run starts again at Start; with it, it carries on from where the first
// left off. "odd" over a hundred pages is fifty runs of one page, and
// both answers are expressible only because the rule is compiled into
// runs rather than stored as written.
Continue bool
}
A LabelRule labels the pages a range names.
Page labels are what a VIEWER shows in its toolbar — "iv of 320" — and never what is printed on the paper. For a number on the page, see Doc.PageNumbers.
type LabelStyle ¶ added in v0.15.0
type LabelStyle string
A LabelStyle is how the numeric part of a page label is written. They are the format's own one-letter names, so that what goes in the file is what the caller asked for.
const ( LabelDecimal LabelStyle = "D" // 1, 2, 3 LabelLowerRoman LabelStyle = "r" // i, ii, iii LabelUpperRoman LabelStyle = "R" // I, II, III LabelLowerLetters LabelStyle = "a" // a, b, c … z, aa, bb LabelUpperLetters LabelStyle = "A" // A, B, C … Z, AA, BB // LabelNone writes no number at all: the label is the prefix alone, which // is how a run of pages is marked "Cover" or "Insert". LabelNone LabelStyle = "" )
type Layer ¶ added in v0.15.0
type Layer struct {
// Name is what the viewer shows. ⛔ It is NOT unique: a document may hold
// two layers of the same name, and the methods here say so rather than
// guessing which was meant.
Name string
// Visible is whether the document's default configuration has it on.
Visible bool
// Locked is whether the document asks that it not be switched: a viewer
// shows the layer greyed, and [Doc.SetLayerVisible] refuses it.
Locked bool
// Depth is how deeply the layer is nested in the document's order, from
// zero. A drawing groups its layers, and the nesting is what makes a list
// of forty of them readable.
Depth int
}
A Layer is one of a document's optional content groups — what a viewer calls a layer, and what a drawing keeps its dimensions, its markup and its alternatives on.
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
A Page is one page of a document, borrowed from the file it came from. The rotation is what will be written, not what the source said.
type Stamp ¶
type Stamp struct {
Text string
Font Font
Size float64 // in points; zero means twelve
Colour [3]float64 // red, green and blue, each from zero to one
Opacity float64 // zero means fully opaque
Rotate float64 // degrees, anticlockwise, about the text's own centre
Position Position
Margin float64 // distance from the edge, in points; zero means 24
Start int // the first value of {n}; zero means one
Digits int // {n} padded to this many digits
}
A Stamp is a line of text drawn on a page.
The text may name what it is being drawn on: {page} is the page's number, {pages} the number of pages, and {n} a counter that starts wherever the stamp says and advances once per page stamped, which is what a numbering scheme like Bates needs.
type XFAReport ¶ added in v0.12.0
type XFAReport struct {
// Sheets is how many pages the form came to.
Sheets int
// Drawn is how many elements were put on them.
Drawn int
// Hidden is how many the template asks not to be shown. They are placed —
// they take up room, and what follows them sits below — and not drawn.
Hidden int
// Pictures is how many of the drawn elements carried one.
Pictures int
// Unplaced is everything the layout could not place, and every picture
// that could not be drawn, one line each with the reason. Empty is the
// ordinary case.
Unplaced []string
}
An XFAReport says what laying a form out came to. A caller showing somebody the result needs to be able to say what is missing from it.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
pdfops
command
Command pdfops does to a PDF the things people actually want done to one: merge, extract, delete, reorder, rotate, crop, split, and read or strip the metadata.
|
Command pdfops does to a PDF the things people actually want done to one: merge, extract, delete, reorder, rotate, crop, split, and read or strip the metadata. |