Graphics state using JavaScript

To traverse the list of changes in the graphics state.

1WebViewer({ fullAPI: true })
2 .then(instance => {
3 const { PDFNet } = instance.Core;
4 await PDFNet.initialize();
5 const reader = await PDFNet.ElementReader.create();
6 const gs_itr = await reader.getChangesIterator();
7 for ( ; gs_itr.hasNext(); gs_itr.next())
8 {
9 switch(gs_itr.current())
10 {
11 case GState.Attribute.e_transform :
12 // Get transform matrix for this element. Unlike path.GetCTM()
13 // that return full transformation matrix gs.GetTransform() return
14 // only the transformation matrix that was installed for this element.
15 //
16 // await gs.getTransform();
17 break;
18 case GState.Attribute.e_line_width :
19 // await gs.getLineWidth();
20 break;
21 case GState.Attribute.e_line_cap :
22 // await gs.getLineCap();
23 break;
24 case GState.Attribute.e_line_join :
25 // await gs.getLineJoin();
26 break;
27 case GState.Attribute.e_miter_limit :
28 // await gs.getMiterLimit();
29 break;
30 case GState.Attribute.e_dash_pattern :
31 {
32 // await gs.GetDashPattern();
33 // await gs.GetPhase();
34 break;
35 }
36 // Etc.
37 }
38 }
39 })

PDF Data Extraction (Images, Text, Paths)
Full code sample which illustrates how to extract data, do color conversion, image normalization, and how to process changes in the graphics state.

About graphics state

After reading an Element using ElementReader.Next(), it is possible to access all graphical attributes of the Element through its graphics state. Some applications are more interested in changes in the graphics state than attribute values. For example, a transition from one Element to another may not involve changes in the graphics state. Or, perhaps, there may be changes only to a couple of attributes. In these cases, it isn't efficient to make memberwise comparisons between the old and current graphics states.

To make this easier and more efficient, Apryse SDK offers an API to enumerate the list of changes between subsequent Elements.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales