我正在构建一个将生成 PDF 的应用程序。我可以很好地生成 PDF,但它是构建和保存 PDF 的一键式操作。我想做的是将其更改为显示 PDF 的预览,然后提供编辑内容或将其保存到 Documents 文件夹的选项。我该怎么做呢?这是我所拥有的保存它的东西。
- (IBAction)generatePdfButtonPressed:(id)sender
{
pageSize = CGSizeMake(792, 612);
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);
BOOL done = NO;
do
{
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);
[self drawImage];
[self drawText];
[self drawText2];
[self drawText3];
[self drawText4];
done = YES;
}
while (!done);
// Close the PDF context and write the contents out.
UIGraphicsEndPDFContext();
}