Ho un UIImage nel mio UIViewController e voglio migrare quell'immagine in formato PDF così è possibile questo tipo di migrazione? Per favore guidami non ne ho idea.Come posso creare Pdf da UIImage?
6
A
risposta
10
Se hai UIImageView in UIViewController quindi chiamare questo metodo:
-(NSData*)makePDFfromView:(UIView*)view
{
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, view.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
[view.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();
return pdfData;
}
Usa come questo:
NSData *pdfData = [self makePDFfromView:imgView];
//[pdfData writeToFile:@"myPdf.pdf" atomically:YES]; - save it to a file
9
Non è molto difficile, ma ci sono alcuni passaggi per impostare tutto. Fondamentalmente, è necessario creare un contesto grafico PDF e quindi disegnare con comandi di disegno standard. Per dirla semplicemente un UIImage in un PDF, si potrebbe fare qualcosa di simile al seguente:
// assume this exists and is in some writable place, like Documents
NSString* pdfFilename = /* some pathname */
// Create the PDF context
UIGraphicsBeginPDFContextToFile(pdfFilename, CGRectZero, nil); // default page size
UIGraphicsBeginPDFPageWithInfo(CGRectZero, nil);
// Draw the UIImage -- I think PDF contexts are flipped, so you may have to
// set a transform -- see the documentation link below if your image draws
// upside down
[theImage drawAtPoint:CGPointZero];
// Ending the context will automatically save the PDF file to the filename
UIGraphicsEndPDFContext();
Per ulteriori informazioni, vedere la Drawing and Printing Guide for iOS.
Problemi correlati
- 1. Conversione da PDF a UIImage
- 2. Come posso ottenere CGContextRef da UIImage?
- 3. Come posso ottenere UIImage da GPUImageView
- 4. Come creare un UIImage nero?
- 5. come creare più pagine PDF da HTML
- 6. Conversione di UIImage in file PDF
- 7. Caricamento UIImage da UIImagePickerControllerReferenceURL
- 8. Come ottenere l'URL da UIImage
- 9. Creare PDF stampabile da dom HTML
- 10. È necessario creare PDF da bytearray (Java)
- 11. Come ottenere UIImage da EAGLView?
- 12. Come creare un UIImage con UIBezierPath
- 13. Creare un sommario da un file pdf
- 14. Come posso convertire FBProfilePictureView in un UIImage?
- 15. Avendo problemi a creare UIImage da CIImage in iOS5
- 16. Crea UiImage da NSData
- 17. iPhone: come posso archiviare UIImage usando NSUserDefaults?
- 18. Come creare un file PDF da HTML usando PDFBox?
- 19. crea un UIImage da due UIImageView
- 20. Posso estrarre tabelle da PDF usando Perl?
- 21. URL dati/PNG da UIImage
- 22. Downcast da "UIImage?" a 'UIImage' scarta solo optional
- 23. Come posso creare un UIColor da RGBA?
- 24. Creazione di UIImage da CIImage
- 25. Come posso generare un file PDF da un file binario?
- 26. Come creare un UIImage dal contesto grafico corrente?
- 27. Come creare dinamicamente una UIImage 1x1 colorata su iPhone?
- 28. Get UIBezierpath da mascherare un UIImage
- 29. Come creare un'immagine da UILabel?
- 30. Come posso creare confetti?