MCPcopy Create free account
hub / github.com/LibPDF-js/core / parse

Method parse

src/content/parsing/content-stream-parser.ts:28–69  ·  view source on GitHub ↗

* Parse all operations from the content stream.

()

Source from the content-addressed store, hash-verified

26 * Parse all operations from the content stream.
27 */
28 parse(): ParseResult {
29 const operations: AnyOperation[] = [];
30 const operands: ContentToken[] = [];
31
32 while (!this.tokenizer.eof()) {
33 const token = this.tokenizer.nextToken();
34
35 if (token === null) {
36 break;
37 }
38
39 if (token.type === "operator") {
40 if (token.name === "BI") {
41 // Special handling for inline images
42 const inlineImage = this.parseInlineImage();
43
44 operations.push(inlineImage);
45 } else {
46 operations.push({
47 operator: token.name,
48 operands: [...operands],
49 });
50 }
51
52 operands.length = 0;
53 } else {
54 operands.push(token);
55 }
56 }
57
58 // Trailing operands without operator
59 if (operands.length > 0) {
60 this.warnings.push(
61 `Content stream has ${operands.length} trailing operand(s) without operator`,
62 );
63 }
64
65 return {
66 operations,
67 warnings: this.warnings,
68 };
69 }
70
71 /**
72 * Iterate operations lazily.

Callers 4

extractAppearanceStyleFunction · 0.95
extractMethod · 0.95

Calls 4

parseInlineImageMethod · 0.95
eofMethod · 0.80
pushMethod · 0.80
nextTokenMethod · 0.45

Tested by

no test coverage detected