4

新しいiPhoneアプリでpdfに取り組んでいます。PDFがロックされている(パスワードで保護されている)かどうかを確認しています

BOOL bIsUnlock = CGPDFDocumentIsUnlocked(PDFDocument);

PDFがロックされている場合

BOOL success = CGPDFDocumentUnlockWithPassword ( PDFDocument, [password UTF8String]);

ここで、ドキュメントのロックを解除することに成功しました。次に、ロック解除ドキュメントを app ディレクトリに保存します。

方法を探して見つけた

CGPDFPageRef _PDFPage =CGPDFDocumentGetPage(PDFDocument, 1);

CGRect pageRect = CGPDFPageGetBoxRect(_PDFPage, kCGPDFMediaBox);

//create empty pdf file;
UIGraphicsBeginPDFContextToFile(newFilePath, pageRect, nil);
size_t count = CGPDFDocumentGetNumberOfPages(PDFDocument);

for (size_t pageNumber = 1; pageNumber <= count; pageNumber++)

{

    //get bounds of template page

    CGPDFPageRef templatePage = CGPDFDocumentGetPage(PDFDocument, pageNumber);

    CGRect templatePageBounds = CGPDFPageGetBoxRect(templatePage, kCGPDFCropBox);

    //create empty page with corresponding bounds in new document
    UIGraphicsBeginPDFPageWithInfo(templatePageBounds, nil);

    CGContextRef context = UIGraphicsGetCurrentContext();

    //flip context due to different origins
    CGContextTranslateCTM(context, 0.0, templatePageBounds.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    //copy content of template page on the corresponding page in new file
    CGContextDrawPDFPage(context, templatePage);

    //flip context back
    CGContextTranslateCTM(context, 0.0, templatePageBounds.size.height);
    CGContextScaleCTM(context, 1.0, -1.0); 
 }
CGPDFDocumentRelease(PDFDocument);

UIGraphicsEndPDFContext(); 

しかし、PDFDocumentをNSdataディレクトリに変換して保存するなど、他の簡単な方法が必要です。助けてください。

4

2 に答える 2

1

iPDFdev が既に述べたように、ここでは Apple の CoreGraphics レンダリング エンジンを使用することはできません。おそらく、これをすべて自分で再実装する必要があります。おそらく数年はそうする必要はないので、ドキュメントを変更するのに役立つ製品がいくつかあります。

オープンソースの最前線には、問題を解決できる可能性のあるPoDoFoまたは muPDF (GPL/商用) があります。私は商用の PSPDFKit SDK に取り組んでおり、これを使用してドキュメントを書き換えることができますPSPDFProcessor。同様の API を Android にも提供しています。

于 2016-04-16T19:51:18.730 に答える