new Filter()
Provides a generic view of a sequence of bytes.
A Filter is the abstract base class of all filters. A filter is an abstraction of
a sequence of bytes, such as a file, an input/output device, an inter-process communication
pipe, or a TCP/IP socket. The Filter class and its derived classes provide a generic view
of these different types of input and output, isolating the programmer from the specific
details of the operating system and the underlying devices.
Besides providing access to input/output sources Filters can be also to transform the data
(e.g. to compress the data stream, to normalize the image data, to encrypt data, etc).
Filters can also be attached to each other to form pipelines. For example, a filter used to
open an image data file can be attached to a filter that decompresses the data, which is
attached to another filter that will normalize the image data.
Depending on the underlying data source or repository, filters might support only some of
these capabilities. An application can query a stream for its capabilities by using the
IsInputFilter() and CanSeek() properties.
Note: To read or write data to a filter, a user will typically use FilterReader/FilterWriter class.
instead of using Filter methods
For example:
StdFile file("my_stream.txt", StdFile::e_read_mode); FilterReader reader(file); while (reader.Read(..)) ...
Extends
Members
-
<static> ReferencePos
-
Type:
- number
Properties:
Name Type Description e_begin
number e_end
number e_cur
number -
<static> StdFileOpenMode
-
Type:
- number
Properties:
Name Type Description e_read_mode
number e_write_mode
number e_append_mode
number
Methods
-
<static> createFlateEncode( [input_filter] [, compression_level] [, buf_sz])
-
Constructor for Flate encoder. FlateEncode filter can be used to compress any data stream using Flate (i.e. ZIP) compression method.
Parameters:
Name Type Argument Default Description input_filter
PDFNet.Filter <optional>
PDFNet.Filter("0") the input data stream compression_level
number <optional>
-1 compression_level must be a number between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all (the input data is simply copied a block at a time), -1 requests a default compromise between speed and compression (currently equivalent to level 6). buf_sz
number <optional>
256 filter buffer size (in bytes). Returns:
A promise that resolves to an object of type: "Filter" (generated documentation)- Type
- Promise.<PDFNet.Filter>
-
<static> createFromMemory(buf)
-
Parameters:
Name Type Description buf
ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray A memory buffer containing the underlying data. Returns:
A promise that resolves to a "Filter" created from the buffer- Type
- Promise.<PDFNet.Filter>
-
<static> createImage2RGB(img)
-
Parameters:
Name Type Description img
PDFNet.Image Returns:
A promise that resolves to an object of type: "PDFNet.Filter"- Type
- Promise.<PDFNet.Filter>
-
<static> createImage2RGBA(img, premultiply)
-
Parameters:
Name Type Description img
PDFNet.Image premultiply
boolean Returns:
A promise that resolves to an object of type: "PDFNet.Filter"- Type
- Promise.<PDFNet.Filter>
-
<static> createImage2RGBAFromElement(elem, premultiply)
-
Parameters:
Name Type Description elem
PDFNet.Element premultiply
boolean Returns:
A promise that resolves to an object of type: "PDFNet.Filter"- Type
- Promise.<PDFNet.Filter>
-
<static> createImage2RGBAFromObj(obj, premultiply)
-
Parameters:
Name Type Description obj
PDFNet.Obj premultiply
boolean Returns:
A promise that resolves to an object of type: "PDFNet.Filter"- Type
- Promise.<PDFNet.Filter>
-
<static> createImage2RGBFromElement(elem)
-
Parameters:
Name Type Description elem
PDFNet.Element Returns:
A promise that resolves to an object of type: "PDFNet.Filter"- Type
- Promise.<PDFNet.Filter>
-
<static> createImage2RGBFromObj(obj)
-
Parameters:
Name Type Description obj
PDFNet.Obj Returns:
A promise that resolves to an object of type: "PDFNet.Filter"- Type
- Promise.<PDFNet.Filter>
-
<static> createMappedFileFromUString(filename)
-
Parameters:
Name Type Description filename
string Returns:
A promise that resolves to an object of type: "PDFNet.Filter"- Type
- Promise.<PDFNet.Filter>
-
<static> createMemoryFilter(buf_sz, is_input)
-
Parameters:
Name Type Description buf_sz
number is_input
boolean Returns:
A promise that resolves to an object of type: "PDFNet.Filter"- Type
- Promise.<PDFNet.Filter>
-
<static> createURLFilter(url [, options])
-
Parameters:
Name Type Argument Description url
string A url from which the data can be downloaded. options
object <optional>
Additional options Properties
Name Type Description withCredentials
boolean Whether to set the withCredentials property on the XMLHttpRequest customHeaders
object An object containing custom HTTP headers to be used when downloading the document Returns:
A promise that resolves to a "Filter" created from the url- Type
- Promise.<PDFNet.Filter>
-
attachFilter(attach_filter)
-
Attaches a filter to the this filter. If this filter owns another filter it will be deleted. This filter then becomes the owner of the attached filter.
Parameters:
Name Type Description attach_filter
PDFNet.Filter filter object to attach Returns:
- Type
- Promise.<void>
-
begin()
-
Returns:
A promise that resolves to beginning of the buffer of Size() bytes that can be used to read or write data.- Type
- Promise.<number>
-
canSeek()
-
Returns:
A promise that resolves to true if the stream supports seeking; otherwise, false. default is to return false.- Type
- Promise.<boolean>
-
consume(num_bytes)
-
Moves the Begin() pointer num_bytes forward.
Parameters:
Name Type Description num_bytes
number number of bytes to consume. num_bytes must be less than or equal to Size(). Returns:
- Type
- Promise.<void>
-
count()
-
Returns:
A promise that resolves to the number of bytes consumed since opening the filter or the last Seek operation- Type
- Promise.<number>
-
createASCII85Encode(line_width, buf_sz)
-
Parameters:
Name Type Description line_width
number buf_sz
number Returns:
A promise that resolves to an object of type: "PDFNet.Filter"- Type
- Promise.<PDFNet.Filter>
-
createInputIterator()
-
Create Filter iterator. Filter iterator similar to a regular filter. However, there can be only one owner of the attached filter. Note: Derived classes should make sure that there is only one owner of the attached stream. Otherwise the attached stream may be deleted several times.
Returns:
A promise that resolves to an object of type: "PDFNet.Filter"- Type
- Promise.<PDFNet.Filter>
-
destroy()
-
Destructor
- Inherited From:
Returns:
- Type
- Promise.<void>
-
flush()
-
Forces any data remaining in the buffer to be written to input or output filter.
Returns:
- Type
- Promise.<void>
-
flushAll()
-
Forces any data remaining in the filter chain to the source or destination.
Returns:
- Type
- Promise.<void>
-
getAttachedFilter()
-
Returns:
A promise that resolves to returns attached Filter or a NULL filter if no filter is attached.- Type
- Promise.<PDFNet.Filter>
-
getDecodeName()
-
Returns:
A promise that resolves to string representing the name of corresponding decode filter as it should appear in document (e.g. both ASCIIHexDecode and ASCIIHexEncode should return ASCIIHexDecode).- Type
- Promise.<string>
-
getFilePath()
-
Returns:
A promise that resolves to the file path to the underlying file stream. Default implementation returns empty string.- Type
- Promise.<string>
-
getName()
-
Returns:
A promise that resolves to descriptive name of the filter.- Type
- Promise.<string>
-
getSourceFilter()
-
Returns:
A promise that resolves to returns the first filter in the chain (usually a file filter)- Type
- Promise.<PDFNet.Filter>
-
isInputFilter()
-
Returns:
A promise that resolves to boolean indicating whether this is an input filter.- Type
- Promise.<boolean>
-
mappedFileCompare(mf2)
-
Comparison function. Determines if parameter object is equal to current object.
Parameters:
Name Type Description mf2
PDFNet.Filter Returns:
A promise that resolves to True if the two objects are equivalent, False otherwise- Type
- Promise.<boolean>
-
mappedFileFileSize()
-
Returns:
A promise that resolves to an object of type: "number"- Type
- Promise.<number>
-
memoryFilterGetBuffer()
-
Note: MemoryFilter specific function.
Returns:
A promise that resolves to a pointer to the beginning of the buffer. Use method Count() to determine the number of bytes written to or read from MemoryFilter.- Type
- Promise.<number>
-
memoryFilterReset()
-
Returns:
- Type
- Promise.<void>
-
memoryFilterSetAsInputFilter()
-
Note: MemoryFilter specific function used to change filter mode from output to input. The utility function is useful in cases when and output data buffer should be converted to an input stream. Note: The function has no effect on an input MemoryFilter.
Returns:
- Type
- Promise.<void>
-
releaseAttachedFilter()
-
Release the ownership of the attached filter. After the attached filter is released this filter points to NULL filter.
Returns:
A promise that resolves to Previously attached filter.- Type
- Promise.<PDFNet.Filter>
-
seek(offset, origin)
-
When overridden in a derived class, sets the position within the current stream.
Parameters:
Name Type Description offset
number A byte offset relative to origin. If offset is negative, the new position will precede the position specified by origin by the number of bytes specified by offset. If offset is zero, the new position will be the position specified by origin. If offset is positive, the new position will follow the position specified by origin by the number of bytes specified by offset. origin
number PDFNet.Filter.ReferencePos = { e_begin : 0 e_end : 2 e_cur : 1 }
A value of type ReferencePos indicating the reference point used to obtain the new position Note: After each Seek() operation the number of consumed bytes (i.e. Count()) is set to 0.Returns:
- Type
- Promise.<void>
-
setCount(new_count)
-
Sets a new counting point for the current filter. All subsequent Consume() operations will increment this counter. Make sure that the output filter is flushed before using SetCount().
Parameters:
Name Type Description new_count
number number to set the counting point of the filter to. Returns:
A promise that resolves to the value of previous counter- Type
- Promise.<number>
-
setStreamLength(bytes)
-
The functions specifies the length of the data stream. The default implementation doesn't do anything. For some derived filters such as file segment filter it may be useful to override this function in order to limit the stream length.
Parameters:
Name Type Description bytes
number the length of stream in bytes Returns:
- Type
- Promise.<void>
-
size()
-
Returns:
A promise that resolves to the size of buffer returned by Begin(). If the Size() returns 0 end of data has been reached.- Type
- Promise.<number>
-
takeOwnership()
-
Take the ownership of this object, so that PDFNet.runWithCleanup won't destroy this object.
- Inherited From:
Returns:
- Type
- void
-
tell()
-
Reports the current read position in the stream relative to the stream origin.
Returns:
A promise that resolves to The current position in the stream- Type
- Promise.<number>
-
truncate(new_size)
-
Truncates the underlying data. This method is for a writeable, seekable filter only and will throw otherwise. Note: For a filter representing a file, truncation would mean resizing the file.
Parameters:
Name Type Description new_size
number the number of bytes to resize the filter to Returns:
A promise that resolves to The new size of the filter- Type
- Promise.<number>
-
writeToFile(path, append)
-
Writes the entire filter, starting at current position, to specified filepath. Should only be called on an input filter.
Parameters:
Name Type Description path
string the output filepath. append
boolean 'true' to append to existing file contents, 'false' to overwrite. Returns:
- Type
- Promise.<void>