Loch Sebastian wrote:
> we need to convert drawings in CALS raster format
> (http://www.fileformat.info/format/cals/)
> to pdf.
>
> Is it possible to use podofo for the conversion, e.g. to embed the
> document as image?
[Dom: please yell at me if there's a simple and obvious way to do this
that I've overlooked]
I don't see why not. If you can get the CITT Group 4 image data out of
the CALS file along with any additional parameters required to decode
it, you have enough to create a PDF image XObject with the data.
PoDoFo's PdfImage class might not be the best way to go about this,
though, since it's better suited to raw image data rather than
already-compressed/filtered data. It'd be nice to have a class that made
it a little easier to populate an image with pre-encoded data, but I
don't think there really is one at present.
I'd do it the lower level way. I *think* the following is correct, but
someone with more PDF knowledge than me can probably point out a better
way to do it.
I'd construct a new PdfObject and attach a stream to it with GetStream()
. Fill the stream with your CITT Group 4 image data, and populate the
/DecodeParms dictionary entry with the parameters required to decode
your image data, as specified in PDF Reference section 3.3.5
(CCITTFaxDecode Filter) . You'd also need to add a /Type Image entry and
a /Filter CITTFaxDecode entry.
If I'm not hopelessly mistaken - I'm not a PDF expert - you'll want to
land up with something like this:
1 0 obj
<<
/Type /XObject
/Subtype /Image
/Width REPLACE_WITH_IMAGE_WIDTH_PIXELS
/Height REPLACE_WITH_IMAGE_HEIGHT_PIXELS
/ColourSpace $$$$$
/BitsPerComponent 1
/Filter /CITTFaxDecode
/DecodeParms
<<
/K -1
/Columns IMAGE_WIDTH_PIXELS
>>
>>
stream
BINARY STREAM DATA HERE
endstream
endobj
The /DecodeParms will probably look different depending on the
particular options required for your images.
Once you have your image XObject, you need to draw it. I'm not sure what
the best way to do that in podofo is, since I've done very little with
it's graphics & drawing stuff. I'm also somewhat hobbled by being on a
new laptop without any tools, so I can't really test anything yet. In
any case, possibilities that come to mind:
- Constructing a PdfImage from the XObject you've built, then drawing
that using PdfPainter.
- Using PdfPage::AddResource() to register the resource, then writing
the drawing operations yourself with PdfPage::GetContentsForAppending()
- Generating the content stream yourself, adding the required resource
entries, etc.
--
Craig Ringer
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users