Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Converting PS file to PDF (I think I am close)

Converting PS file to PDF (I think I am close)
Thread Tools
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
Jul 11, 2002, 12:49 PM
 
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:[@&quot;~/Desktop/ReceivedFile.ps&quot; 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:@&quot;recieve&quot;] stringByExpandingTildeInPath];
tempString2 = [ tempString stringByAppendingString:@&quot;/&quot; ];
tempString3 = [ tempString2 stringByAppendingString:@&quot;ReceivedFile.pd f&quot;];

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
Reply With Quote
Jul 13, 2002, 06:29 AM
 
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
Reply With Quote
Jul 13, 2002, 01:35 PM
 
</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&lt;numOfPages)
{
tempString = @&quot;/tmp/receive/&quot;;
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:@&quot;recieve&quot;] stringByExpandingTildeInPath];
tempString2 = [ tempString stringByAppendingString:@&quot;/&quot; ];
tempString3 = [ tempString2 stringByAppendingString:@&quot;ReceivedFile.pd f&quot;];

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
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:01 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2