1

textView 框架的更改如何使其在 pdf 导出后无法选择文本?它是简单的光栅化与可怕的压缩。如果我导出 textView 并且不更改框架,我会得到完美的向量。

我用 textView 查看,然后用 textView 的内容导出 pdf,如下所示:

- (void) generatePDFWithFilename:(NSString *)filename
{
    // Creates a mutable data object for updating with binary data, like a byte array
    NSMutableData *pdfData = [NSMutableData data];

    //  pdf view
    _pdfView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 612, 792)];

    //  adding subview - for easier positioning
    CGRect tempFrame;
    UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, _pdfView.bounds.size.width - 20, _pdfView.bounds.size.height - 20)];
    tempView.backgroundColor = [UIColor redColor];
    _pdfView.backgroundColor = [UIColor lightGrayColor];
    [_pdfView addSubview:tempView];


    UITextView *pdfDescriptionTextView = [[UITextView alloc] initWithFrame:CGRectZero];
    pdfDescriptionTextView = _workDescriptionTextView;
    [tempView addSubview:pdfDescriptionTextView];
    // pdfDescriptionTextView.center = CGPointMake(50, 200); // working - vector data are preserved
    tempFrame = pdfDescriptionTextView.frame;
    tempFrame.origin = CGPointMake(100, 100);
    tempFrame.size = CGSizeMake(tempView.bounds.size.width - 40, pdfDescriptionTextView.contentSize.height);
    pdfDescriptionTextView.frame = tempFrame;
    pdfDescriptionTextView.backgroundColor = [UIColor greenColor];

    UIGraphicsBeginPDFContextToData(pdfData, CGRectZero, nil);
    UIGraphicsBeginPDFPageWithInfo(_pdfView.bounds, nil);
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();

    [_pdfView.layer renderInContext:pdfContext];

    // remove PDF rendering context
    UIGraphicsEndPDFContext();

    // Retrieves the document directories from the iOS device
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:filename];

    // instructs the mutable data object to write its context to a file on disk
    BOOL success = [pdfData writeToFile:documentDirectoryFilename atomically:YES];
    if(success)
    {
        [self sendEmailWithData:pdfData];
    }
}

框架未更改 - 矢量数据 框架改变 - 光栅化文本

4

1 回答 1

0

只是改变它的编辑模式......

pdfDescriptionTextView.editable = FALSE;

在此之后,用户将无法再更改文本

于 2013-03-15T10:14:13.640 回答