On Nov 29, 2008, at 6:42 PM, Torsten Curdt wrote:

I am a little stuck here. I am trying to extract (and later modify)
text and images in a PDF. First I turned to PDFkit but that seems to
be way to high level for these things. Now I am trying with Quartz.

Hi Torsten,

Quartz is indeed the level at which you'll need to work with this.

There is a CGPDFScannerScan but that doesn't look right either.

It's definitely part of the puzzle. Essentially

You'll need to create an operator table:
        CGPDFOperatorTableRef table = CGPDFOperatorTableCreate();

Then add the PDF operators you're interested in to the table like this:
        // Close, fill, and stroke path using nonzero winding number rule
        CGPDFOperatorTableSetCallback(table, "b", operator_b);

…where " operator_b" is your callback function, and "b" is the name of the operator.

Obtain the content stream for the page, and create a scanner to scan it:

CGPDFContentStreamRef contentStream = CGPDFContentStreamCreateWithPage(cgPage); CGPDFScannerRef scanner = CGPDFScannerCreate(contentStream, table, self);

You can pass a pointer to the object from which you scan (likely "self") in the last argument, so that you can easily reach back into the higher level environment.

Finally start scanning:

 CGPDFScannerScan(scanner);

After this call, whenever the scanner finds an operator that you added to the operator table it will call your callback function. One option is to simply hook back into Objective-C level, passing the scanner to the appropriate method, and perform your parsing there:

void operator_b(CGPDFScannerRef scanner, void *info)
{
        [(MyScanningObject *)info operator_b_withScanner:scanner];
}

- (void)operator_b_withScanner:(CGPDFScannerRef)scanner
{
        // Do whatever is appropriate
}


António

--------------------------------------------------------
Today you are You, that is truer than true.
There is no one alive who is Youer than You.
Today I am Me, and I am freer than free.
There is no one alive who is Me-er than Me.
I am the BEST I can possibly be.

--Dr. Seuss
--------------------------------------------------------


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to