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
paintingapage [2015/04/02 14:47]
christian [Program design]
paintingapage [2017/10/05 12:54] (current)
christian [Hello World - How text gets onto a page]
Line 1: Line 1:
-====== How does text get onto a PDF page ======+====== How text gets onto a page ======
  
 A PDF page has a content stream (**''/Contents''**) containing a list of graphics operator with their parameters. The operators are sequentially executed and can set aspects of the **GraphicsState** or paint in the context of the current GraphicsState. A PDF page has a content stream (**''/Contents''**) containing a list of graphics operator with their parameters. The operators are sequentially executed and can set aspects of the **GraphicsState** or paint in the context of the current GraphicsState.
Line 25: Line 25:
 To achieve this in Smalltalk you can write the following: To achieve this in Smalltalk you can write the following:
 <code smalltalk> <code smalltalk>
-page := Page newInBounds: (0 @ 0 corner: 50 @ 20) colorspace: DeviceCMYK new render: [:renderer |+page := Page newInBounds: (0 @ 0 corner: 70 @ 20) colorspace: DeviceCMYK new render: [:renderer |
   renderer fillColor: CmykColor black.   renderer fillColor: CmykColor black.
   renderer textObjectDo: [   renderer textObjectDo: [
Line 32: Line 32:
     renderer showString: 'Hello World']].     renderer showString: 'Hello World']].
 </code> </code>
 +{{pdf:demo01_helloworld.pdf}} See the class method ''demo01_HelloWorld'' in class ''Document''.
 +
 You notice that I did not use the font ID **''/F1''** but the font directly (referenced as the global #Helvetica). ''renderer **setFont:**'' takes care of that and puts the font into the resources and assigns it to an internal name which is used in the content stream. This mechanism works for all resource types so that the programmer can always use the appropriate object directly and never needs to care about the internal IDs. You notice that I did not use the font ID **''/F1''** but the font directly (referenced as the global #Helvetica). ''renderer **setFont:**'' takes care of that and puts the font into the resources and assigns it to an internal name which is used in the content stream. This mechanism works for all resource types so that the programmer can always use the appropriate object directly and never needs to care about the internal IDs.
  
Line 98: Line 100:
 to get the simple string ''10 5 Td''? to get the simple string ''10 5 Td''?
  
-Firstly, I wanted operators as objects and not just as strings you write into the contents stream. The objects can be read from a PDF (try: from the [[PDFExplorer]] inspect a **''/Contents''** object and send it ''#operations'') and the list of operator you create can be written to a PDF. There are some things a program could do with operators:+Firstly, I wanted operators as objects and not just as strings you write into the contents stream. The objects can be read from a PDF (try: from the [[pdf:pdfexplorer]] inspect a **''/Contents''** object and send it ''#operations'') and the list of operator you create can be written to a PDF. There are some things a program could do with operators:
  
   * check the consistency/validity. F.ex. **''BeginText (BT)''** must be written before **''EndText (ET)''** and must enclose certain text operators; they cannot be nested etc. etc.   * check the consistency/validity. F.ex. **''BeginText (BT)''** must be written before **''EndText (ET)''** and must enclose certain text operators; they cannot be nested etc. etc.
Line 133: Line 135:
 I like to develop my abstractions from the bottom up and try to keep them as simple as possible. Maybe, over time, users will develop abstractions which are generally useful. In the end it should be a community discussion and consensus of what should be included. So far, only the bare metal on the spec will be available and you have to evolve your own abstractions. I like to develop my abstractions from the bottom up and try to keep them as simple as possible. Maybe, over time, users will develop abstractions which are generally useful. In the end it should be a community discussion and consensus of what should be included. So far, only the bare metal on the spec will be available and you have to evolve your own abstractions.
  
-==== Comments ====+===== Comments =====
  
-=== Higher level abstractions ===+==== Higher level abstractions ====
  
 Submitted by bobcalco on Tue, 2012-01-24 10:32. Submitted by bobcalco on Tue, 2012-01-24 10:32.
Line 147: Line 149:
 I know about this because I used an earlier version of Prawn to code a PDF generation feature of a content delivery system, which I am now needing to replace in Smalltalk, having decided to make the switch. I am a bit sad at the state of PDF generation in Smalltalk. There are so many other strengths in Smalltalk for the kind of distributed system I am building that wooed me over, but this deficiency is going to cost me some late nights and lamp oil. I know about this because I used an earlier version of Prawn to code a PDF generation feature of a content delivery system, which I am now needing to replace in Smalltalk, having decided to make the switch. I am a bit sad at the state of PDF generation in Smalltalk. There are so many other strengths in Smalltalk for the kind of distributed system I am building that wooed me over, but this deficiency is going to cost me some late nights and lamp oil.
  
-=== Here is a PDF manual ===+==== Here is a PDF manual ====
  
 Submitted by bobcalco on Tue, 2012-01-24 12:03. Submitted by bobcalco on Tue, 2012-01-24 12:03.
Line 155: Line 157:
 http://prawn.majesticseacreature.com/manual.pdf external http://prawn.majesticseacreature.com/manual.pdf external
  
-=== Re: Higher level abstractions ===+==== Re: Higher level abstractions ====
  
 Submitted by ChristianHaider on Tue, 2012-01-24 11:58. Submitted by ChristianHaider on Tue, 2012-01-24 11:58.
Line 161: Line 163:
 Interesting. I am curious what experiences you have while porting from Prawn to PDF4Smalltalk. Maybe some good concepts can be integrated... If you have any questions, please ask in the forum - sometimes I am responsive :-) Interesting. I am curious what experiences you have while porting from Prawn to PDF4Smalltalk. Maybe some good concepts can be integrated... If you have any questions, please ask in the forum - sometimes I am responsive :-)
  
-=== Thanks! ===+==== Thanks! ====
  
 Submitted by bobcalco on Tue, 2012-01-24 12:06. Submitted by bobcalco on Tue, 2012-01-24 12:06.
  • paintingapage.1427978823.txt.gz
  • Last modified: 2015/04/02 14:47
  • by christian