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

Method getPageContentData

src/api/pdf.ts:1915–1962  ·  view source on GitHub ↗

* Get the concatenated content stream data from a page.

(source: PDF, page: PDFPage)

Source from the content-addressed store, hash-verified

1913 * Get the concatenated content stream data from a page.
1914 */
1915 private getPageContentData(source: PDF, page: PDFPage): Uint8Array {
1916 const contents = page.dict.get("Contents", source.getObject.bind(source));
1917
1918 if (!contents) {
1919 return new Uint8Array(0);
1920 }
1921
1922 // Single stream (resolved from ref or direct)
1923 if (contents instanceof PdfStream) {
1924 return contents.getDecodedData();
1925 }
1926
1927 // Array of streams - concatenate with newlines
1928 if (contents instanceof PdfArray) {
1929 const chunks: Uint8Array[] = [];
1930
1931 for (let i = 0; i < contents.length; i++) {
1932 const ref = contents.at(i);
1933
1934 if (ref instanceof PdfRef) {
1935 const stream = source.getObject(ref);
1936
1937 if (stream instanceof PdfStream) {
1938 if (chunks.length > 0) {
1939 // Add newline separator
1940 chunks.push(new Uint8Array([0x0a]));
1941 }
1942
1943 chunks.push(stream.getDecodedData());
1944 }
1945 }
1946 }
1947
1948 // Concatenate all chunks
1949 const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
1950 const result = new Uint8Array(totalLength);
1951 let offset = 0;
1952
1953 for (const chunk of chunks) {
1954 result.set(chunk, offset);
1955 offset += chunk.length;
1956 }
1957
1958 return result;
1959 }
1960
1961 return new Uint8Array(0);
1962 }
1963
1964 // ─────────────────────────────────────────────────────────────────────────────
1965 // Object creation

Callers 1

embedPageMethod · 0.95

Calls 6

getDecodedDataMethod · 0.80
atMethod · 0.80
pushMethod · 0.80
getObjectMethod · 0.65
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected