This is an old revision of the document!


Changing existing PDFs

To change an existing PDF, the file has to be read with:

aFile := PDF.File read: <aFilename>

The file can then be converted to a Document, an object which can write itself as a PDF file by:

aDocument := aFile asDocument

After changing things in aDocument, the PDF file is written out with:

<aDocument> write: <aFilename>

The class PDF.File is for reading PDFs from files. It does so incrementally by just reading objects from disk when they are needed. On can see that in the PDFExplorer: 729 of 125179 objects have been read

The inital object read from a PDF is the /Trailer. Apart from some internal bookkeeping attributes, a trailer contains the /Root with a reference to the Catalog (the contents of the PDF), the /Info and the /ID. This trailer is held by a File in the #trailer instance variable.

The cloning of the PDF is done in the FileĀ»asDocument method:

asDocument
	"<Document>
	a new document with the same contents as the receiver for writing out the PDF later"
 
	| newDocument info |
	newDocument := Document new.
	newDocument root: self root.
	info := self trailer Info.
	info at: #ModDate put: Timestamp now.
	info at: #Producer put: PDF producerText.
	newDocument info: info.
	newDocument previousId: self trailer ID.
	^newDocument
  • changing.1464875521.txt.gz
  • Last modified: 2016/06/02 15:52
  • by christian