4
A
回答
5
4
您可以使用UIKit的生成PDF。它非常簡單。你只需要啓動一個PDP上下文和寫出來的內容吧:
看到這個:http://www.ioslearner.com/generate-pdf-programmatically-iphoneipad/
5
即使世界創建PDF一個偉大的開源API。您可以將文本,圖像和標題添加到PDF,然後發送PDF或將其保存到文件。 API是在http://code.google.com/p/pdf-api-iphonesdk/wiki/PDFAPI 如果您對此有任何疑問,支持是很大的,只是接觸[email protected]
0
- (IBAction)generatePdfButtonPressed:(id)sender
{
pageSize = CGSizeMake(612, 792);
NSString *fileName = @"Demo.pdf";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
[self generatePdfWithFilePath:pdfFileName];
}
- (void) generatePdfWithFilePath: (NSString *)thefilePath
{
UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);
NSInteger currentPage = 0;
BOOL done = NO;
do
{
// Mark the beginning of a new page.
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);
// Draw a page number at the bottom of each page.
currentPage++;
[self drawPageNumber:currentPage];
//Draw a border for each page.
[self drawBorder];
//Draw text fo our header.
[self drawHeader];
//Draw a line below the header.
[self drawLine];
//Draw some text for the page.
[self drawText];
//Draw an image
[self drawImage];
done = YES;
}
while (!done);
// Close the PDF context and write the contents out.
UIGraphicsEndPDFContext();
}
- (void) drawBorder
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
UIColor *borderColor = [UIColor brownColor];
CGRect rectFrame = CGRectMake(kBorderInset, kBorderInset, pageSize.width-kBorderInset*2, pageSize.height-kBorderInset*2);
CGContextSetStrokeColorWithColor(currentContext, borderColor.CGColor);
CGContextSetLineWidth(currentContext, kBorderWidth);
CGContextStrokeRect(currentContext, rectFrame);
}
- (void) drawLine
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(currentContext, kLineWidth);
CGContextSetStrokeColorWithColor(currentContext, [UIColor blueColor].CGColor);
CGPoint startPoint = CGPointMake(kMarginInset + kBorderInset, kMarginInset + kBorderInset + 40.0);
CGPoint endPoint = CGPointMake(pageSize.width - 2*kMarginInset -2*kBorderInset, kMarginInset + kBorderInset + 40.0);
CGContextBeginPath(currentContext);
CGContextMoveToPoint(currentContext, startPoint.x, startPoint.y);
CGContextAddLineToPoint(currentContext, endPoint.x, endPoint.y);
CGContextClosePath(currentContext);
CGContextDrawPath(currentContext, kCGPathFillStroke);
}
- (void) drawText
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(currentContext, 0.0, 0.0, 0.0, 1.0);
NSString *textToDraw = @"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
UIFont *font = [UIFont systemFontOfSize:14.0];
CGSize stringSize = [textToDraw sizeWithFont:font
constrainedToSize:CGSizeMake(pageSize.width - 2*kBorderInset-2*kMarginInset, pageSize.height - 2*kBorderInset - 2*kMarginInset)
lineBreakMode:UILineBreakModeWordWrap];
CGRect renderingRect = CGRectMake(kBorderInset + kMarginInset, kBorderInset + kMarginInset + 50.0, pageSize.width - 2*kBorderInset - 2*kMarginInset, stringSize.height);
[textToDraw drawInRect:renderingRect
withFont:font
lineBreakMode:UILineBreakModeWordWrap
alignment:UITextAlignmentLeft];
}
- (void) drawImage
{
UIImage * demoImage = [UIImage imageNamed:@"demo.png"];
[demoImage drawInRect:CGRectMake((pageSize.width - demoImage.size.width/2)/2, 350, demoImage.size.width/2, demoImage.size.height/2)];
}
相關問題
- 1. 使用OpenXML SDK創建Word文檔 - 使用OpenXML SDK創建CLI
- 2. 創建PDF文檔
- 3. 如何使用iPhone SDK創建GUID/UUID
- 4. 如何在iPhone上創建包含數據表的PDF文檔?
- 5. 使用mysql變量創建PDF文檔
- 6. 使用PSPDFKit動態創建PDF文檔
- 7. 使用IText創建PDF文檔#
- 8. 使用VB.NET創建PDF文檔?
- 9. 使用OpenXml創建Excel文檔sdk 2.0
- 10. 如何爲Itext創建子文檔PDF
- 11. 使用iPhone SDK閱讀PDF文檔時出現問題?
- 12. 如何使用C#或VB.NET的Acrobat SDK從文件創建PDF?
- 13. 如何使用Google Drive JavaScript SDK V3創建帶文本的Google文檔文檔?
- 14. PHP to PDF - 使用XML文檔中的文本創建PDF?
- 15. 如何使用PHP,Bootstrap和MySQL創建動態PDF文檔
- 16. 如何在Windows中使用Sphinx創建PDF文檔
- 17. 如何使用XML和iTextSharp在PDF文檔中創建表格?
- 18. 使用iPhone sdk編輯PDF
- 19. iphone從pdf頁面創建PDF文件
- 20. 使用Debenu Quick PDF創建自定義大小的PDF文檔
- 21. 用表單輸入創建PDF文檔
- 22. 如何使用PHP創建PDF文件?
- 23. 如何使用iPhone SDK將表格輸出到PDF文件?
- 24. 爲iPhone創建SDK
- 25. 如何使用Microsoft.Office.Interop.Word創建.docx文檔?
- 26. 如何使用XmlDocument創建XML文檔?
- 27. 如何使用Java創建JSON文檔?
- 28. 在asp.net 2.0中創建pdf文檔
- 29. 從System.IO.Stream對象創建pdf文檔?
- 30. 在VBA中創建PDF文檔