Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert multiple HTML to multiple pdf using a for loop. #43

Open
Keatooon opened this issue Dec 20, 2017 · 0 comments
Open

Convert multiple HTML to multiple pdf using a for loop. #43

Keatooon opened this issue Dec 20, 2017 · 0 comments

Comments

@Keatooon
Copy link

Hi, I'm trying to convert multiple html file to multiple pdf file using a for loop, however, the app crashes with Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT).

Why?

Here's the code I'm using:

for (int i=0; i<= 47; i++) {

    NSString *inputHTMLfileName = [NSString stringWithFormat:@"wkhtml_tempfile_%d",j];
    NSString *outputPDFfileName = [NSString stringWithFormat:@"~/Documents/%d_delegateDemo%d.pdf",loop,j];

    NSURL *htmlFileUrl = [[NSBundle mainBundle]
                          URLForResource:inputHTMLfileName withExtension:@"html"];


    // Check for existing pdf file and remove it
    NSError *pdfDeleteError;
    if ([[NSFileManager defaultManager] fileExistsAtPath:outputPDFfileName]){
        //removing file
        if (![[NSFileManager defaultManager] removeItemAtPath:outputPDFfileName error:&pdfDeleteError]){

            NSString * errorMessage = [NSString stringWithFormat:@"wk %d Could not remove old pdf files. Error:%@",j, pdfDeleteError];
            NSLog(@"%@",errorMessage);
        }
    }

    self.PDFCreator = [NDHTMLtoPDF createPDFWithURL:htmlFileUrl pathForPDF:[outputPDFfileName stringByExpandingTildeInPath] pageSize:kPaperSizeA4 margins:UIEdgeInsetsMake(10, 5, 10, 5) successBlock:^(NDHTMLtoPDF *htmlToPDF) {
        NSString *result = [NSString stringWithFormat:@"HTMLtoPDF did succeed (%@ / %@)", htmlToPDF, htmlToPDF.PDFpath];
        NSLog(@"%@",result);
        self.resultLabel.text = result;
    } errorBlock:^(NDHTMLtoPDF *htmlToPDF) {
        NSString *result = [NSString stringWithFormat:@"HTMLtoPDF did fail (%@)", htmlToPDF];
        NSLog(@"%@",result);
        self.resultLabel.text = result;
    }];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant