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

Method copyObject

src/document/object-copier.ts:139–163  ·  view source on GitHub ↗

* Deep copy any PDF object, remapping references to destination.

(obj: T)

Source from the content-addressed store, hash-verified

137 * Deep copy any PDF object, remapping references to destination.
138 */
139 copyObject<T extends PdfObject>(obj: T): T {
140 if (obj instanceof PdfRef) {
141 // oxlint-disable-next-line typescript/no-unsafe-type-assertion
142 return this.copyRef(obj) as unknown as T;
143 }
144
145 if (obj instanceof PdfStream) {
146 // oxlint-disable-next-line typescript/no-unsafe-type-assertion
147 return this.copyStream(obj) as unknown as T;
148 }
149
150 if (obj instanceof PdfDict) {
151 // oxlint-disable-next-line typescript/no-unsafe-type-assertion
152 return this.copyDict(obj) as unknown as T;
153 }
154
155 if (obj instanceof PdfArray) {
156 // oxlint-disable-next-line typescript/no-unsafe-type-assertion
157 return this.copyArray(obj) as unknown as T;
158 }
159
160 // Primitives (PdfName, PdfNumber, PdfString, PdfBool, PdfNull)
161 // are immutable and can be reused directly
162 return obj;
163 }
164
165 /**
166 * Copy a reference, creating the referenced object in dest if needed.

Callers 7

copyPageMethod · 0.95
copyRefMethod · 0.95
copyStreamRefMethod · 0.95
copyDictValuesMethod · 0.95
copyArrayMethod · 0.95
embedPageMethod · 0.95

Calls 4

copyRefMethod · 0.95
copyStreamMethod · 0.95
copyDictMethod · 0.95
copyArrayMethod · 0.95

Tested by

no test coverage detected