Skip to content
This repository was archived by the owner on Jul 24, 2019. It is now read-only.

Add PDF extraction support#24

Open
getaaron wants to merge 1 commit into
steventroughtonsmith:masterfrom
getaaron:master
Open

Add PDF extraction support#24
getaaron wants to merge 1 commit into
steventroughtonsmith:masterfrom
getaaron:master

Conversation

@getaaron

Copy link
Copy Markdown

This change adds PDF extraction support.

I only tested it on one Assets.car file and it extracted the PDFs successfully. Could use some extra testing. Feedback welcome or feel free to push directly to my fork.

Comment thread cartool/main.m

@property(readonly) bool isVectorBased;

-(id)initWithURL:(id)arg1 error:(id*)arg2;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This initializer replaces the need to use the CUIThemeFacet (in my limited testing)

Comment thread cartool/main.m

struct CGPDFDocument *pdfDocument = [catalog pdfDocumentWithName:key];

if (pdfDocument) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a PDF document, I'm skipping the extraction of the generated raster images and only extracting the PDF

Comment thread cartool/main.m
return images;
}

void writePDFtoFile(struct CGPDFDocument *pdfDocument, NSString *path, NSString *key) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with CGPDFDocument, but I cobbled this together from a few answers on Stack Overflow and pastern and it hasn't failed me yet

Comment thread cartool/main.m
/* Override CUICatalog to point to a file rather than a bundle */
[catalog setValue:facet forKey:@"_storageRef"];

carPath = [carPath stringByExpandingTildeInPath];

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well expand this path too

Comment thread cartool/main.m
for( CUINamedImage *image in images )
{
if( CGSizeEqualToSize(image.size, CGSizeZero) )
if ( ![image respondsToSelector:@selector(size)]) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if statement is kinda sloppy — I wish I could do something like if ( ![image isKindOfClass:[CGPDFDocument class]]), but of course CGPDFDocument isn't a class and I don't think there's any way to check the struct type at runtime. Wonder if you know of anything better.

@getaaron getaaron mentioned this pull request Sep 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant