 |
 |
Converting PS file to PDF (I think I am close)
|
 |
|
 |
|
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status:
Offline
|
|
I need to convert a .ps file to PDF. I have a start, but keep getting some bad errors. Here is my code:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> NSData *data;
NSRect myRect;
NSImage *myPDF;
NSRect USLetterSize;
int myHeight;
NSString *tempString;
NSString *tempString2;
NSString *tempString3;
NSImageView *myView;
myPDF = [[NSImage alloc] initWithContentsOfFile:[@"~/Desktop/ReceivedFile.ps" stringByExpandingTildeInPath]];
myHeight = 792*numOfPages;
USLetterSize = NSMakeRect(0, 0, 612, myHeight);
myView = [[NSImageView alloc] initWithFrame:USLetterSize];
[myView lockFocus];
[myPDF compositeToPoint:NSZeroPoint operation:NSCompositeCopy];
[myView unlockFocus];
tempString = [[[NSUserDefaults standardUserDefaults] objectForKey:@"recieve"] stringByExpandingTildeInPath];
tempString2 = [ tempString stringByAppendingString:@"/" ];
tempString3 = [ tempString2 stringByAppendingString:@"ReceivedFile.pd f"];
data = [myView dataWithPDFInsideRect: USLetterSize];
[data writeToFile:tempString3 atomically:YES];</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">And this is the error project builder gives me when I run the code:
lockFocus sent to a view whose window is deferred and does not yet have a corresponding platform window
So does this mean I have to have the view drawn in a window? If so, would I need to create a hidden, really large window (say I have a 5 pager I am converting)? This doesn't seem right, and I am probably just doign somethign a little wrong.
Thanks,
Ben
PS I actually have the individual pages stored as .tiff files that I convert to one big ps file. If it would be easier to go from teh tiff file to pdf, rather than from ps to pdf let me know.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
I think that in order to do offscreen drawing you should use NSImage. NSView is for onscreen user interface stuff.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Angus_D:
<strong>I think that in order to do offscreen drawing you should use NSImage. NSView is for onscreen user interface stuff.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Correct, I just did a bit more work, and got it to work (sorta).
The problem now, is say I have 3 tiff files I want to put into one pdf. I run through the following code, and it puts it into a 1 page pdf file (the 1 page is just as tall as the 3 pages added up). Not what I wanted. If any one has an idea on how to get the pdf file to come out as multipages, please let me know.
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">numPages = [mergeArray count];
myImageToSave = [[NSImage alloc] initWithSize:NSMakeSize(612, numPages*792)];
while(i<numOfPages)
{
tempString = @"/tmp/receive/";
tempString2 = [tempString stringByAppendingString:[mergeArray objectAtIndex:numOfPages-i]];
myPDF = [[NSImage alloc] initWithContentsOfFile:tempString2];
[myImageToSave lockFocus];
[myPDF compositeToPoint:NSMakePoint(0, 792*(i+1)) operation:NSCompositeCopy];
[myImageToSave unlockFocus];
i++;
}
myHeight = 792*numOfPages;
kUSLetterSize = NSMakeSize(612, myHeight);
[tempWindow setContentSize:kUSLetterSize];
[tempImageView setImage:myImageToSave];
tempString = [[[NSUserDefaults standardUserDefaults] objectForKey:@"recieve"] stringByExpandingTildeInPath];
tempString2 = [ tempString stringByAppendingString:@"/" ];
tempString3 = [ tempString2 stringByAppendingString:@"ReceivedFile.pd f"];
myRect = [tempImageView bounds];
data = [tempImageView dataWithPDFInsideRect:myRect];
[data writeToFile:tempString3 atomically:YES];</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Thanks,
Ben
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|