Expand description
Extended graphics state, for advanced graphical operation (overprint, black point control, etc.)
Some of the operations can be done on the layer directly, but for advanced graphics,
you need to set the graphics state. A PDF has an internal default graphics state,
which can be reset to by setting ExtendedGraphicsState::default()
as the active gs
dictionary. Setting a new graphics state overwrites the old one, there is no “undo”.
In order to use a graphics state, it must be added to the Pages resource dicitionary.
This is done by the layer.set_graphics_state()
function, which returns a reference with the name of
the newly added dictionary. From inside a stream, the graphics state parameter is invoked
with the “gs” command using the name of the graphics state as a operator.
This is done using the layer.use_graphics_state()
.
A full graphics state change is done like this:
let mut new_state = ExtendedGraphicsState::default();
new_state.overprint_stroke = true;
// it is best to put the next lines in a seperate function
// A PdfLayerReferences contains the indices of the page and the layer
// as well as a `std::sync::Weak` reference to the document.
// This is why you need the braces, otherwise, you'll trigger a deadlock
{
// supposing mylayer is a PdfLayerReference
let doc = mylayer.document.upgrade().unwrap();
let mut doc = doc.lock().unwrap();
let mut page = doc.pages.get_mut(self.page.0).unwrap();
// see the documentation for add_graphics_state
page.add_graphics_state(new_state);
}
Structs
ExtGState
dictionaryExtendedGraphicsState
Enums
DeviceCMYK
color space should erase that component (EraseUnderlying
) or
leave it unchanged (KeepUnderlying
) when overprinting (see Section 4.5.6, “Over-
print Control”). Initial value: EraseUnderlying
BlackGenerationFunction
, too. Undercolor removal reduces the amounts
of the cyan, magenta, and yellow components to compensate for the amount of
black that was added by black generation.