Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
releasenotes [2020/02/22 11:15]
christian [PDFtalk 2.3]
releasenotes [2021/07/29 20:10] (current)
christian [PDFtalk 2.5.0]
Line 1: Line 1:
 ====== Release Notes ====== ====== Release Notes ======
  
 +===== PDFtalk 2.5.0 =====
 +
 +July 2021
 +
 +This release was triggered by Bob Nemec from HTS to improve error handling when appending PDFs. Two errors were seen: objects referenced but missing and streams with one extra byte.
 +
 +The use case of **appending PDFs** is the topic of this release. Some internal structures were redesigned and the bugs are handled. Also, the performance for appending large files was improved.
 +
 +Since the HTS systems run on Gemstone, the Gemstone version of the library was updated.
 +
 +==== Error handling ====
 +
 +Two structural errors were discovered which need to be handled. For describing these errors in more detail, a new page [[monsters|Monsters]] was created to collect some observations from the wild.
 +
 +=== Handling missing object errors ===
 +
 +A reference pointing to an non-existing object (see [[monsters#missing_object|Missing object]] for details). A ''MissingObject'' is created with the list of expected types allowing useful error messages and the creation of dummy objects.
 +
 +On writing, the MissingObject is written as string saying that the object is missing. This preserves the references and leads to a TypeMismatch error on next reading, which can be handled easily.
 +
 +=== Handling incorrect stream length errors ===
 +
 +The ''/Length'' of a stream is different from the number of bytes in the content (see [[monsters#incorrect_stream_length|Incorrect stream length]] for details). In our case, the stream contents was always exactly one byte longer than stated by the ''/Length'' attribute. That last byte was probably not needed for the stream to be correct considering the filters applied, like ''/FlateDecode''. This was checked for a few instances.
 +
 +Therefore, a very specific error ''ExtraCharacterInStreamError'' is raised in this case and the extra byte is ignored (giving the ''/Length'' attribute priority). This error can resume meaningfully. On writing, ''/Lenght'' bytes are written to the content, dropping the extra byte.
 +==== New APIs ====
 +
 +=== Document>>appendAllPagesFrom: ===
 +
 +A PDF (all pages) can be appended efficiently to a PDF Document.
 +<code smalltalk>Document>>appendAllPagesFrom: aPDFtalkFile</code>
 +
 +All objects of the PDF to be appended are read from the file by resolving all references reachable from the ''Catalog''. This happens with a protection against ''Type''- and ''FileError''s, which can savely be resumed. 
 +
 +To concatenate some PDFs do:
 +<code smalltalk>
 +| doc |
 +doc := Document new.
 +doc appendAllPagesFrom: (File read: 'file1.pdf' asFilename).
 +doc appendAllPagesFrom: (File read: 'file2.pdf' asFilename).
 +doc appendAllPagesFrom: (File read: 'file3.pdf' asFilename).
 +doc saveAs: 'file123.pdf'.
 +</code>
 +
 +=== Raw objects ===
 +
 +There is also a variant 
 +<code smalltalk>Document>>appendAllRawPagesFrom: aPDFtalkFile</code>
 +which reads all objects without typing. The objects are raw - generic ''Dictionary'' and ''Array'' objects. Note: the only purpose is to write out the PDF immediately, because nothing useful can be done with the raw objects.
 +
 +In ''VisualWorks'', the raw version is performing slightly faster (~ 5%) than the standard version with typing. 
 +
 +On ''Gemstone'', the difference is much bigger (~ 75%) - 4 times faster! My guess is that ''Pragmas'', with which the type annotations are implemented, are not efficient in ''Gemstone''.
 +
 +==== Internal changes ====
 +
 +The user of the library is not affected by these changes.
 +
 +=== Improving performance for large files ===
 +
 +When reading many objects at once, the library was slow with large files. In this investigation, a few issues came up which were never a problem when clicking through objects one by one.
 +
 +  * Object streams were created and initialized for each access to an object inside. Now, the streams are kept alive in a cache.
 +  * References from traversing the PDF objects were collected in an OrderedCollection. The visited check was done with this collection. The time grows exponentially with the number of collected objects, so that large files can become very slow. Now, for the visited check, a Set is used. The OrderedCollection for the collected references is kept to ensure a reproducable order.
 +
 +=== Redesigned references and tracing ===
 +
 +Objects are picked (read) from a PDF file stream when they are needed. Originally, this was done using blocks stored in place of the value (referent) of a reference. When the value is requested, the block is evaluated and the resulting PDF object is stored as the referent. The block reads the raw object and converts it to the proper type. This can be nested and several types may apply.
 +
 +Unfortunately, the design with blocks does not allow to defer the typing. This led to problems where a general type overtook a more specific, better matching type. So, I reified the blocks to ''FileReference'' which can read an object from file and has a list of types to be applied to the raw object. The types list is maintained to reflect the subtype order.
 +
 +While at it, the number and generation of references was extracted to an ''ObjectId''.
 +
 +=== Changed internal streams to bytes ===
 +
 +The ''Writer'' (internal write stream) writes now bytes instead of characters to produce the PDF file. When writing the physical file, the string was converted to a byte array to write the binary data. This copy is not needed anymore.
 +
 +==== Gemstone ====
 +
 +This release updates the Gemstone code for the library and also the [[pdftalk4gemstone|PDFtalk for Gemstone]] page. The biggest addition is the [[postscript|PostScript]] module used with [[cmap|CMaps]] introduced in [[releasenotes#pdftalk_23|version 2.3]].
 +
 +=== Encoded PostScript sources ===
 +
 +PostScript source methods (mainly cmaps and examples) are reencoded with ASCII85 to allow fileIn to Gemstone. Topas from Gemstone as well as PostScript use the % character at the beginning of a line for directives and comments. Since cmaps are PostScript programs, their source cannot be embedded directly without disturbing Gemstone.
 +
 +Interestingly, I believe that Gemstone and PostScript share some early history which can also be seen in the way the dictionary stack is used in both.
 +
 +=== Optional CMaps ===
 +
 +The [[cmap|CMaps module]] is used to decode strings to unicode. The library uses this when a font supplies a ''/ToUnicode'' attribute. In case you want to use this for Asian languages as Japanese, Chinese or Korean, the standard CMap files for these languages are needed. There are 182 standard CMaps defined which are all needed when dealing with arbitrary PDFs. These CMap source files, in PostScript, are stored in the image and parsed by the PostScript interpreter on demand.
 +
 +Since they are very big, there are two Gemstone source files: **''PDFtalk.gs''** (3.8 MB) and **''PDFtalkWithCMaps.gs''** (12.1 MB). Unless you do serious things with Asian text, the smaller one is recommended.
 +==== other changes ====
 +
 +In VisualWorks 9.1, icons were renamed and changed. In order to use the library's UI in all versions, some icons were copied from older releases.
 +
 +
 +===== PDFtalk 2.4.0 =====
 +
 +March 2021
 +
 +Embedded OpenType(PS) fonts can now be used for the screen on windows without having them installed.
 +
 +''aPage **pageNumber**'' finds the page number of aPage. This is interesting, because pages do not contain their number for a good reason: modifying the order of pages should not lead to modified pages all over the place. Therefore, there is no explicit place where the page number is stored. To find it, a page needs to ask its anchestors for its position.
 +
 +Added cache for tabular glyph variants to improve performance.
 +===== PDFtalk 2.3.5 =====
 +
 +January 2021
 +
 +I worked on extracting content from PDFs for the [[https://unsere-gelder.de/dokuwiki/doku.php|Unsere Gelder project]]. While doing this, I worked freely in the library and in the experimental code for content recognition. As always, by looking at many different PDFs, there are always some bug or things to improve in the UI.
 +
 +This messed up the base a bit and test cases were starting to fail.
 +
 +With this release, everything is clean again: the code **{PDFtalk Project}** loads without warnings or undeclareds. All tests pass (almost. See [1]).
 +The same goes for the **[Report4PDF]** package. Loads clean, all tests pass.
 +
 +One functional enhancement is that text is now properly decoded for the UI. "add Picture"
 +
 +Happy hacking
 +
 +
 +[1] There is a strange problem when one or two tests fail in an fresh image. But only the first time. After the first run, they all pass.
 ===== PDFtalk 2.3 ===== ===== PDFtalk 2.3 =====
 +
 +February 2020
 +==== PostScript ====
 +
 +Added **[[PostScript]]** to the PDFtalk runtime.
 +
 +The package **[PostScript]** implements some low level methods which are used by PDFtalk. 
 +
 +PostScript was implemented after PDFtalk and used some basic methods of it (Number reading and writing, ASCII85 encoding and PostScript character names). These dependencies have been reversed so that PostScript can be used stand-alone while PDFtalk now depends on it. This also reflects the correct historical relationship.
 +
 +==== CMaps ====
 +
 +Added **[[CMap]]** to the **{PDFtalk Fonts}** bundle.
 +
 +**CMaps** are PostScript programs defining complex code mappings. The mechanism is very general and allows for variable byte length encodings. Because of its generality, CMaps are used by some PDF writers to even encode simple mappings. Hence, it is necessary to fully implement CMaps in order to decode PDF text.
 +
 +This is not intended to be used by the user of the library. Rather, it is part of the basic font infrastructure enabling decoding of PDF strings. This will be the base for Text extraction in the next step.
 +
 +=== Standard CMaps ===
 +
 +PDF defines 181 standard CMaps which are to be understood by a conforming reader. These CMaps are available at GitHub(([[https://github.com/adobe-type-tools/cmap-resources]] Standard CMaps from Adobe)). All maps have been imported as methods containing the source of the CMaps. Since they are rather large (16 MB with sources), it might be important to not load them into a runtime image when you don't need them, i.e. do text extraction in your application.
 +
 +Therefore, I put them into a seperate package (outside of the runtime, but part of the project bundle): **[PostScript CMap instances]**. The CMaps are constructed from the source methods lazily when needed. If the package is not loaded, the source of a requested CMap is downloaded from GitHub, which is slower.
 +
 +=== Known problem ===
 +
 +The PDF specification allows bfchar-mappings to have a string of UTF-16BE characters as destination. This is not yet implemented.
 +
 +==== Typing ====
 +
 +=== Allow narrower types to shadow broader types ===
 +
 +Example:
 +<code smalltalk>
 +DecodeParms
 + <type: #ZipFilterParameter>
 + <type: #Dictionary>
 +</code>
 +
 +''ZipFilterParameter'' is a subtype of ''Dictionary''. Because it is declared before, it is tried to match it first. Before, both alternatives were equal and ''Dictionary'' might have matched, even when the dictionary was a valid ''ZipFilterParameter''.
 +
 +=== Generalized ''Textstring'' to ''String'' ===
 +
 +Textstring does not need to be differenciated. We can rely on VisualWorks handling of multi byte strings.
  
 ===== PDFtalk 2.2 ===== ===== PDFtalk 2.2 =====
 +
 +August 2019
  
 Renamed ''OrderedDictionary'' to ''Valuemap'' in the **[Values]** package. Renamed ''OrderedDictionary'' to ''Valuemap'' in the **[Values]** package.
Line 11: Line 180:
  
 ===== PDFtalk 2.1 ===== ===== PDFtalk 2.1 =====
 +
 +July 2019
  
 Flate encoding is using zlib of VW 8.1 now. Flate encoding is using zlib of VW 8.1 now.
Line 16: Line 187:
 ===== PDFtalk 2.0 ===== ===== PDFtalk 2.0 =====
  
-This is the release of the second major version of the PDF library in October 2017.+October 2017
  
 ==== What's new ==== ==== What's new ====
  • releasenotes.1582366530.txt.gz
  • Last modified: 2020/02/22 11:15
  • by christian