SORU
26 Mart 2011, CUMARTESİ


Nasıl UİView iOS içinde PDF Dönüştürmek için?

Bir App UIView bir PDF görüntüleme hakkında çok fazla kaynak var. Şu anda üzerinde çalıştığım UIViews bir PDF oluşturmak için.

Örneğin, Textviews, UILabels, UIImages gibi UIView, subviews ile nasıl bir dönüştürme varbüyükBir bütün olarak UIView tüm subviews dahil olmak üzere bir PDF subsubviews?

Apple's iOS reference kontrol ettim. Ancak, tek bir PDF dosyası için metin/resim parçalarını yazmak bahsediyor.

Karşı karşıyayım sorun PDF olarak bir dosya yazmak istiyorum. içeriği bir çok şey var. Eğer parça parça PDF yazmıştım, çok büyük iş olacak. Bir şekilde PDF veya bit eşlem bile UIViews yazmak için sabırsızlanıyorum.

Yığın içindeki diğer S/A dan kopyaladım kaynak kod Taşma denedim. Ama sadece bana UIView sınırları boyutu ile boş bir PDF sağlar.

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

    // Points the pdf converter to the mutable data object and to the UIView to be converted
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();

    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
    [aView drawRect:aView.bounds];

    // 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:aFilename];

    // instructs the mutable data object to write its context to a file on disk
    [pdfData writeToFile:documentDirectoryFilename atomically:YES];
    NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}

Yardım lütfen. Teşekkürler.

CEVAP
4 Temmuz 2011, PAZARTESİ


Aşağıdaki yöntemi oluşturur unutmayınsadece bir bit eşlembu görüş; gerçek tipografi oluşturmaz.

(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
    // Creates a mutable data object for updating with binary data, like a byte array
    NSMutableData *pdfData = [NSMutableData data];

    // Points the pdf converter to the mutable data object and to the UIView to be converted
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();


    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData

    [aView.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:aFilename];

    // instructs the mutable data object to write its context to a file on disk
    [pdfData writeToFile:documentDirectoryFilename atomically:YES];
    NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}

Ayrıca emin olun alma: /QuartzCore QuartzCore.h

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • bmarian22

    bmarian22

    22 Aralık 2007
  • Jonathan Flavell

    Jonathan Fla

    1 HAZİRAN 2006
  • Philip DeFranco

    Philip DeFra

    16 EYLÜL 2006