尝试创建一个不能以任何方式修改的PDF,并测试不同的字典选项,看看它们是如何工作的。问题是,虽然文档中说我可以使用一件东西,但它不允许我使用那个东西和应用程序崩溃。这是我的装备;
NSDictionary *tempDict = [NSDictionary dictionaryWithObjectsAndKeys:@"user", kCGPDFContextOwnerPassword, (kCGPDFAllowsCommenting | kCGPDFAllowsLowQualityPrinting), kCGPDFContextAccessPermissions, nil];
UIGraphicsBeginPDFContextToFile(self.savePath, CGRectZero, tempDict);来自UIGraphicsBeginPDFContextToFile的文档:
指定要与PDF文件关联的附加信息的字典。您可以使用这些键为PDF指定其他元数据和安全信息,例如PDF的作者或访问它的密码。本词典中的键与传递给CGPDFContextCreate函数的键相同,并在CGPDFContext的辅助字典键部分中进行了描述。字典由新上下文保留,因此返回时您可以安全地释放它。
来自kCGPDFContextAccessPermissions的文档
/*文档的访问权限,表示为CFNumber。ORing将数字定义为所需的CGPDFAccessPermissions值。*/
CG_EXTERN const CFStringRef kCGPDFContextAccessPermissions
CG_AVAILABLE_STARTING(10.13,11.0);
来自CGPDFDocument的文档
//要从CGPDFDocument获得访问权限,请调用CGPDFDocumentGetAccessPermissions。设置权限//只能使用传递给CGPDFContextCreate的辅助信息字典中的CGPDFContextCreate属性进行。
因此,根据我收集的信息,我应该能够将属性或属性合并为:(kCGPDFAllowsCommenting \ kCGPDFAllowsLowQualityPrinting),以便将这些属性推入PDF创建辅助字典,从而能够使用这些权限编写PDF。另一个问题是,如果我不想打开或关闭某些权限,怎么办?这些权限如下:
typedef CF_OPTIONS(uint32_t, CGPDFAccessPermissions) {
kCGPDFAllowsLowQualityPrinting = (1 << 0), // Print at up to 150 DPI
kCGPDFAllowsHighQualityPrinting = (1 << 1), // Print at any DPI
kCGPDFAllowsDocumentChanges = (1 << 2), // Modify the document contents except for page management
kCGPDFAllowsDocumentAssembly = (1 << 3), // Page management: insert, delete, and rotate pages
kCGPDFAllowsContentCopying = (1 << 4), // Extract content (text, images, etc.)
kCGPDFAllowsContentAccessibility = (1 << 5), // Extract content, but only for the purpose of accessibility
kCGPDFAllowsCommenting = (1 << 6), // Create or modify annotations, including form field entries
kCGPDFAllowsFormFieldEntry = (1 << 7) // Modify form field entries
};我希望字段kCGPDFAllowsDocumentChanges关闭,这样就不能对PDF进行任何更改。我尝试通过PDFKit编写带有选项的文件来实现这一点,我也尝试使用上面的方法,同样的事情也发生了。我可以编写CGPDFContext.h中包含的所有其他选项,但是如果没有系统崩溃,我就不能为kCGPDFContextAccessPermissions编写权限。
任何帮助都会被感谢,因为这是一个很大的问题,因为零文档或代码示例使这个工作关闭kCGPDFAllowsDocumentChanges是根本不存在的。
发布于 2019-10-24 22:26:35
您正在尝试将普通int (实际上是uinit32_t)存储在NSDictionary中。你不能这么做。您只能将对象存储在NSDictionary中。因此,您需要将您的值包装在一个NSNumber中。
使用现代目标-C,您的代码将是:
NSDictionary *tempDict = @{
(NSString *)kCGPDFContextOwnerPassword : @"user",
(NSString *)kCGPDFContextAccessPermissions : @(kCGPDFAllowsCommenting | kCGPDFAllowsLowQualityPrinting)
};https://stackoverflow.com/questions/58549717
复制相似问题