PDFtalk for Gemstone

Library for reading and writing PDF files in GsDevKit for Gemstone.

The source is on on Github and comes in two files: PDFtalk.gs with the runtime code and PDFtalkTesting.gs with tests and demos. UI tools and helpers used in VisualWorks are not included, because of the server nature of Gemstone.

With version 2.5 a new file of the library with the 182 standard CMaps was added: PDFtalkWithCMaps.gs.

The new symbol dictionary PDFtalkLibrary will appear in the symbol list after filein (and PDFtalkTesting after filing in the testing file). This symbol dictionary represents the namespace Smalltalk of the library with the Values code and some general tools. This dictionary need to be in scope (i.e. on the symbol list) when using it.

The namespaces from VisualWorks are implemented by symbol dictionaries in Gemstone. Therefore, the PDFtalkLibrary contains the dictionary PDFtalk with all PDF classes. The PDFtalk dictionary in turn contains the Fonts dictionary which includes the OpenType and CFF dictionaries. the following slide of the ESUG 2017 presentation shows the structure:

Namespace dictionaries in Gemstone

Accessing classes in namespaces is written differently. For example:

"in VisualWorks:"
"in Gemstone:"
((PDFtalk at: #Fonts) at: #OpenType) at: #Font

*Note that the second expression works in VisualWorks as well.

The dictionary PDFtalk (or the other namespace dictionaries) should not be in scope (on the symbol list) unless you extend or change the library itself. Unfortunately, you need to put the dictionaries on the symbol list in order to browse them :-(.

With the 2.5 release, the new PostScript dictionary is also present in the PDFtalkLibrary.

The proper way to get the fileout is to create it. For convenience, the files are accessible on Github, but I don't guarantee that they will reflect the most recent version in VisualWorks.

To create the fileout, you need to load the bundle {Smalltalk Transform Project} and the package [Gemstone Fileout PDFtalk] in an image with PDFtalk loaded. Then execute:

SmalltalkTransform.Gemstone fileOutPDFtalk.
SmalltalkTransform.Gemstone fileOutPDFtalkTesting.

You should change the directory in the two methods.

The library should be installed in the open source GsDevKit for Gemstone. In this installation, many modules from Pharo are installed which are needed by the PDFtalk library.

You have to log into GsDevKit as DataCurator (only this user has the Pharo code loaded). To file-in the code do:

output push PDFtalk.log only
input PDFtalk.gs
output pop

The created log file MUST be checked for problems. If you see:

topaz 1> # 
topaz 1> # Finished file-in successfully
topaz 1> # 
fileformat is now 8bit
topaz 1> output pop

…then everything is OK and PDFtalk can be used. In case of a problem, you will see an error message with a useful stacktrace.

Do the same to load PDFtalkTesting.gs.

When doing this repeatedly, one need to undo and clean up the previous installation with:

output push cleanUp.log only
	| policy |
	#(#PDFtalkLibrary) do: [:dictName |
		(GsPackageLibrary packageNamed: dictName) ifNotNil: [:package | 
			GsPackageLibrary uninstallPackage: package.
			(GsPackageLibrary packageLibrary removeDictionaryNamed: dictName)]].
	policy := GsPackagePolicy current.
	policy homeSymbolDict: UserGlobals.
	policy externalSymbolList: Array new.
	policy enable.

Loading PDFtalkTesting.gs provides all tests and some demos for the library.

Print the following:

PDF runAllTests

and check that 497 tests are passing without errors or failures.

In the PDFtalkLibrary dictionary, you find the class PDF with demo class methods.

The demos write the test PDFs in the $HOME directory on the Gemstone server. For demos 12, 13 and 14 you need to put the PDF specification there as well.

To quickly check all demos do:

PDF runAllDemos

to find many generated PDFs in your $HOME directory.

The last demo appends all demo PDFs into this PDF.

There are some global variables caching objects (fonts, encodings, the type hierarchy). These caches are lazily filled when accessed first. In a runtime, you may want to reset and fill all caches before deploying, either because of limited rights of the runtime user or to eliminate startup overhead.

After all your application code is loaded, do the following to reset and fill all caches:

PDF primeRuntime

There is code to save ImageXObjects as Value (i.e. source code which will reconstruct the object). To produce the source string for a PDF image you send it asSource. (Or you can send asPDF asSource to a VisualWorks Image). This string can be evaluated in Gemstone with evaluate and will reconstruct the ImageXObject, which can be put into a PDF page as usual. evaluate works when the PDFtalkLibrary symbol dictionary is in the symbol list; otherwise you can do something like I did in method PDFtalk.Tests»_gs_evaluate:.

I did not add any helper methods for saving or reading the string to / from disk.

My preferred way is to store such resources as methods. This may or may not work with your workflow. For this, I added a helper on ImageXObject. To save a PDF image as a class method of ImageXObject, you can call

anImageXObject asMethod: selectorSymbol in: protocolSymbol package: packageString

I added several example images with this to ImageXObject. You can also look at ImageXTests where the images are used. These methods can be transferred easily form VW to Gemstone and you get the image just by calling that method.

  • pdftalk4gemstone.txt
  • Last modified: 2022/03/07 10:31
  • by bekki