2015-04-06 45 views
0

我正在創建一個PDF,我已經將很多NSString值添加到了PDF中,但是現在我想添加一些我已經創建的HTML樣式的文本到PDF中;唯一的一點是,當我打開它像一個正常的字符串是這樣的:如何添加UIWebView到CGContextRef PDF?

[materialsHTML drawInRect:CGRectMake(55.0, 523.0, kDefaultPageWidth-100, 137.0) withAttributes:grayAttributes]; 

我失去所有的格式和所有你能看到的是HTML標籤等

這是我開始我打開頁面,我希望有人能告訴我如何插入某種UIWebView。

// create some sample data. In a real application, this would come from the database or an API. 
    NSString* path = [[NSBundle mainBundle] pathForResource:@"sampleData" ofType:@"plist"]; 

    // get a temprorary filename for this PDF 
    path = NSTemporaryDirectory(); 
    self.pdfFilePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"Job Sheet #%@.pdf", jobSheetNumber]]; 

    // Create the PDF context using the default page size of 612 x 792. 
    // This default is spelled out in the iOS documentation for UIGraphicsBeginPDFContextToFile 
    UIGraphicsBeginPDFContextToFile(self.pdfFilePath, CGRectZero, nil); 

    // get the context reference so we can render to it. 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    // every student gets their own page 
    // Mark the beginning of a new page. 
    UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, kDefaultPageWidth, kDefaultPageHeight), nil); 

///.... 

回答

-1

試試這個 -

UIGraphicsBeginPDFContextToFile(...); 
UIGraphicsBeginPDFPageWithInfo(...); // load first uiwebview 
// ... 
UIGraphicsBeginPDFPageWithInfo(...); // load second uiwebview 
// ... 
UIGraphicsEndPDFContext(); 
+0

不幸的是沒有,那是從一個UIWebView使得整個PDF,我想兩個小UIWebViews中添加到PDF,我猜你會稱它爲層。 – HurkNburkS 2015-04-06 06:51:27

+0

嘗試更新的答案。測試工作正常 – 2015-04-06 07:36:11

+0

我認爲,更新只是創建一個兩頁PDF ...我有PDF創建罰款,我希望添加兩個視圖內我已經創建的PDF包含HTML。 – HurkNburkS 2015-04-06 08:07:22