[pdf4st] Append another PDF document

Submitted by bobn on Tue, 2012-01-24 15:56

Can PDF4Smalltalk be used to append another PDF document to one that is
being created? 

The result would be one document, with the pages of the external PDF
document added to the end. 


Adding pages from another PDF


Submitted by ChristianHaider on Tue, 2012-01-24 16:44.

I think that should be easy, since Page are quite self contained: 

1.      have your Document object: document := PDF.Document
createWithAllMyContent. 
2.      read other PDF with: pdf := PDF.File read: aFilename. 
3.      add the pages from the read document: pdf root pagesDo: [:page |
document root addPage: page]. 

I have not tested the code, but I guess it could work similar to this...


(I just implemented #pagesDo: - reload the code to use it :-) ) 


pagesDo: problem


Submitted by bobn on Wed, 2012-01-25 20:04.

I tried a simple example to append pages to a current document. An
exception was raised at... 

 Graphis.PDF.Pages>>pagesDo: oneArgumentBlock
        self Kids do: [:pageTree <PIPE> pageTree pagesDo:
oneArgumentBlock]

...since #pageTree (a Graphis.PDF.Reference instance) does not
understand #pagesDo: 

My example code is this... 

        | report document pdf | 
        report := self exampleAlignCenter.
        document := report buildPDF.
        pdf := PDF.File read:  'exampleAlignCenterMiddle.pdf'
asFilename.
        pdf root pagesDo: [:page | document root addPage: page].

...where document is an instance of Graphics.PDF.Document and pdf is the
expected instance of PDF.File 


Latest PDF package


Submitted by bobn on Wed, 2012-01-25 19:27.

I am trying to use the latest released code in the Cincom Store for PDF:
1.2.4.5 

It fails in the method... 

Graphics.PDF.Textstring>>fromString: aByteString
        | encoder wst |
        wst := ByteArray new writeStream.
        encoder := Graphics.Fonts.Font pdfDocEncoder.
        aByteString do: [:char | wst nextPut: (encoder encode: char)].
        ^self content: wst contents

...because #pdfDocEncoder is not understood by Font. It is implemented
in previous versions.
The method is sent from... 

DocumentInformation class>>empty

...I commented out the line... 

inst at: #Producer put: (Textstring fromString: 'PDF4Smalltalk ' , PDF
libraryVersionString).

...and that go me around the problem. 

BTW: the timestamp added to the file makes my SUnit test a bit more of a
challenge, since I can't use a simple byte array snapshot to check for
differences. Is there is way to generate the PDF and explicitly exclude
the 'DocumentInformation class>>empty' content? It is something that I
would only use in SUnit tests. 

 DocumentInformation class>>empty
        ...
        inst at: #CreationDate put: timestamp.
        inst at: #ModDate put: timestamp.
        ...


DocumentInformation


Submitted by ChristianHaider on Thu, 2012-01-26 14:02.

The DocumentInformation is just an ordinary PDF Dictionary. You can
remove keys by setting the value to nil like: 

document info at: #CreationDate put: nil.
document info at: #ModDate put: nil.


Latest packages


Submitted by ChristianHaider on Thu, 2012-01-26 13:55.

I moved the encoder stuff around in mid december. It is now with the
fonts - a better place. You should always work with the latest versions
of all involved pundles ("Values Development", "Fonts Development" and
"PDF Development"). 


Loaded latest package


Submitted by bobn on Thu, 2012-01-26 15:39.

From the public Store, I now have loaded what I assume are the latest
versions... 

Values Development 1.1.1.0
Fonts Development 1.2.3.1
PDF Development 1.2.4.6

...the same error is raised... 

MessageNotUnderstood 
a Message with selector: #pagesDo: and arguments: #(BlockClosure [] in
PDFReport.TSreportTest>>checkAppendReport)

...in Graphics.PDF.Pages>>pagesDo: 

Is there something else that I should have loaded? 

Also, using... 

 document info at: #CreationDate put: nil.
 document info at: #ModDate put: nil.

...works great for the SUnit tests. Thanks. 


pagesDo:


Submitted by ChristianHaider on Thu, 2012-01-26 16:30.

hmm, that happens - I didn't try the pagesDo: code :-) 

The problem (often) is that I confuse references and objects. Here, I
used the Kids of a Pages (which are references), but I wanted the
objects of course... 

The versions are right (which should solve the encoding walk back). With
the fix for #pagesDo:, the latest version of "PDF Development" is
1.2.4.7  :-) 

And it seems to work fine - cool! 


update works fine


Submitted by bobn on Thu, 2012-01-26 17:18.

PDF Development 1.2.4.7 fixed everything nicely. Works great. Thanks. 

 

Other related posts:

  • » [pdf4st] Append another PDF document - Christian Haider