2012-08-25 4 views
0

지난 몇 시간 동안의 문제로 어려움을 겪고 있습니다. 프로그래밍 방식으로 PDF를 만들고 ~/라이브러리/Application Support/iPhone Simulator/...에 저장하면 프로그램이 시뮬레이터에서 잘 작동합니다. webView에서 PDF를 저장하고 검색 할 수 있습니다.시뮬레이터에서는 pdf가 표시되지만 iPhone에서는 표시되지 않습니다.

하지만 iPhone4 기기에서 앱을 테스트 할 때 검색 할 때 PDF 파일이 표시되지 않습니다. 나는 새롭다 그래서 수동으로 수표가 장치에서 창조 된 ㄴ다는 것을 있건 없건간에 모른다.

제게 도움을주십시오.

감사

는이 코드에서 PDF로 저장 : 전에이 문제로 실행했습니다

- (void)generatePdfButtonPressed{ 

pageSize = CGSizeMake(612, 792); 
NSString *fileName = @"Demo.pdf"; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName]; 

[self generatePdfWithFilePath:pdfFileName]; 
} 


- (void) generatePdfWithFilePath: (NSString *)thefilePath 
{ 
UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil); 

NSInteger currentPage = 0; 
BOOL done = NO; 
do 
{ 
    // Mark the beginning of a new page. 
    UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil); 

    // Draw a page number at the bottom of each page. 
    currentPage++; 
    //[self drawPageNumber:currentPage]; 

    //Draw a border for each page. 
    // [self drawBorder]; 

    //Draw text fo our header. 
    [self drawHeader]; 

    //Draw a line below the header. 
    [self drawLine]; 


    //Draw personel details 
    [self drawPersonelDetail]; 

    //Draw Education 
    [self drawEducation]; 




    //Draw work Experiences 
    [self drawWorkExperiences]; 

    //Draw work Activities 
    [self drawActivities]; 


    //Draw Skills 
    [self drawSkils]; 


    //Draw some text for the page. 
// [self drawText]; 

    yCord=550; 
// [self drawText]; 

    //Draw an image 
// [self drawImage]; 
    done = YES; 
} 
while (!done); 

// Close the PDF context and write the contents out. 
UIGraphicsEndPDFContext(); 
} 
+1

어디에서나 로그 메시지를 추가하고 리턴 코드를 확인하고 로그하십시오. 분명히 당신이 전화로하고있는 것은 작동하지 않고 이것이 당신이 그 장소를 찾을 수있는 방법입니다. 또한 "응용 프로그램 지원"이 휴대 전화의 응용 프로그램에 미리 존재하는지 잘 모르겠습니다. 프로그래밍 방식으로 작성해야 할 수도 있습니다. (내가 말했던 것처럼 확실하지는 않습니다.) –

+0

@DavidH 답장을 보내 주셔서 감사합니다. 나는 알고 싶어한다. 내 장치에 pdf를 저장하는 것을 올바르게 코딩하고 있습니까? (시뮬레이터에서 잘 작동합니다.) – QueueOverFlow

+0

또한 생성 한 파일 경로를 저장하는 방법과 PDF를 웹보기로로드하려는 방법이 표시되지 않습니다. –

답변

2

오랜 고투 끝에 나는 내 자신의 질문에 대한 해결책을 찾았습니다. 아래 해결책을 제시하면 다른 도움이 될 수 있습니다.

- (void)generatePdfButtonPressed{ 

pageSize = CGSizeMake(612, 792); 
NSString *fileName = @"Demo.pdf"; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName]; 

[self generatePdfWithFilePath:pdfFileName]; 
} 


- (void) generatePdfWithFilePath: (NSString *)thefilePath 
{ 
UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil); 

NSInteger currentPage = 0; 
BOOL done = NO; 
do 
{ 
// Mark the beginning of a new page. 
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil); 

// Draw a page number at the bottom of each page. 
currentPage++; 
[self drawPageNumber:currentPage]; 

//Draw a border for each page. 
[self drawBorder]; 

//Draw text our header. 
[self drawHeader]; 

//Draw a line below the header. 
[self drawLine]; 


//Draw personel details 
[self drawPersonelDetail]; 

//Draw Education 
[self drawEducation]; 


//Draw an image 
[self drawImage]; 

done = YES; 
} 
while (!done); 

// Close the PDF context and write the contents out. 
UIGraphicsEndPDFContext(); 
} 



And for Display the pdf file the method is : 

- (void)showPdfClicked 
{ 

pdf1View.scalesPageToFit = YES; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 

NSLog(@"%@",documentsDirectory); 

NSString *path1 =[documentsDirectory stringByAppendingPathComponent:@"Demo.pdf"]; 

NSLog(@"Retruve Save path is %@: ",path1); 
// NSString *path1 = [[NSBundle mainBundle] pathForResource:@"pdf1" ofType:@"pdf"]; 
NSURL *targetURL1 = [NSURL fileURLWithPath:path1]; 
NSURLRequest *request1 = [NSURLRequest requestWithURL:targetURL1]; 
[pdf1View loadRequest:request1]; 

} 
+0

이 코드와 원본 코드의 차이점은 무엇입니까? 무엇이 당신의 문제를 해결 했습니까? –

+0

@SixtenOtto 전에 바보 같은 실수를하고 있습니다. PDF를 만들 때 "Demo.pdf"라는 이름을 붙였습니다. 그러나 "demo.pdf"를 사용하여 pdf 파일에 액세스 할 때 표시되지 않습니다. – QueueOverFlow

0

. 내 생각 엔 메모리 문제 일까?로드하려는 PDF 파일의 크기가 얼마나 큽니까? UIWebView에는 대용량 파일을 버퍼링하는 데 문제가있는 것 같습니다.

0

본인이 작성한 PDF를이 코드를 통해 전자 메일로 보낼 수 있습니다. 이것이 당신을 도울 수 있습니다 (dottorfeelgood).

-(IBAction)emailButtonClicked 
{ 


MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
picker.mailComposeDelegate = self; 
[picker setSubject:@"Subject"]; 


NSString *fileName = @"Demo.pdf"; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName]; 



NSMutableData *pdfData = [NSMutableData data]; 


pdfData = [NSData dataWithContentsOfFile:pdfFileName]; 

CGRect bounds=CGRectMake(0, 0, 612, 792); 
[picker addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"SomeFile.pdf"]; 




// Fill out the email body text 
NSString *emailBody = @"Image is attached"; 
[picker setMessageBody:emailBody isHTML:NO]; 
[self presentModalViewController:picker animated:YES]; 

//[picker release]; 


} 

해피 코딩!

관련 문제