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 PDF to TIFF (problem with my code?)

Converting PDF to TIFF (problem with my code?)
Thread Tools
Senior User
Join Date: Jun 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
Jul 2, 2002, 07:54 PM
 
If the input pdf file i 7 pages, I will get 7 tiff files, but they are all of the first page only. How do I get at the other pages correctly. I am doing the setCurrentPage, and setting it correctly, but I never get more than the first page. Does it have to do with how I am drawing it out?

Any help would be great.

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> NSImage *myImageToSave;
NSImage *image1;
NSData *data;
int numPages = 0;
int curpage = 0;
NSNumber *iAsNumber;
NSPDFImageRep *myPDF;
NSData *myPDFasData;
NSSize kUSLetterSize = NSMakeSize(612, 792);
NSString *tempString;
NSString *temp2String;
NSString *temp3String;

myPDFasData = [[NSData alloc] initWithContentsOfFile:@&quot;/myFile.pdf&quot;];

myPDF = [[NSPDFImageRep alloc] initWithData:myPDFasData];
curpage = [myPDF currentPage];
numPages = [myPDF pageCount];

do
{
[myPDF setCurrentPage:curpage+1];
myPDFasData = [myPDF PDFRepresentation];

image1 = [[NSImage alloc] initWithData:myPDFasData];
myImageToSave = [[NSImage alloc] initWithSize:kUSLetterSize];
[myImageToSave lockFocus];
[image1 compositeToPoint:NSZeroPoint operation:NSCompositeCopy];
[myImageToSave unlockFocus];

data = [myImageToSave TIFFRepresentationUsingCompression:NSTIFFCompressi onCCITTFAX3 factor:nil];

tempString = @&quot;/Output.pdf.&quot;;
if(curpage&lt;10)
{
temp2String = [tempString stringByAppendingString:@&quot;00&quot;];
iAsNumber = [[NSNumber alloc] initWithInt:curpage+1];
temp3String = [temp2String stringByAppendingString:[iAsNumber stringValue]];
}
else
{
temp2String = [tempString stringByAppendingString:@&quot;0&quot;];
iAsNumber = [[NSNumber alloc] initWithInt:curpage+1];
temp3String = [temp2String stringByAppendingString:[iAsNumber stringValue]];
}


[data writeToFile:temp3String atomically:YES];
curpage++;
}while( curpage &lt; numPages);</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">
     
   
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 09:57 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