1

NSView1ページのPDFで表示したいと思います。

これまでのところ、2 つの解決策がありますが、どちらにも欠点があります。誰でもこれらの欠点を手伝ってもらえますか?

最初の解決策: NSImage と NSImageView を使用

   NSString *path= [[NSBundle mainBundle] pathForResource:name ofType:@"pdf"];
   NSImage * image = [[NSImage alloc] initWithContentsOfFile:path] ;

   NSImageView * imageView = [[NSImageView alloc] init] ;
   imageView.frame = NSMakeRect(0, 0, 2*image.size.width, 2*image.size.height) ;
   imageView.image = image ;
   imageView.imageScaling = NSImageScaleAxesIndependently ;

   return imageView

欠点:

  • 画像はアンチエイリアスされていません
  • 2係数が必要な理由がわかりません。PDF が、Finder よりも NSView で小さく表示されるのはなぜですか?

2 番目の解決策: PDFDocument と PDFView を使用

    NSString *path= [[NSBundle mainBundle] pathForResource:name ofType:@"pdf"];
    NSURL *urlPDF = [NSURL fileURLWithPath:path] ;

    PDFDocument * myPDFDocument = [[PDFDocument alloc] initWithURL:urlPDF] ;

    PDFView *myPDFView = [[PDFView alloc] init] ;
    myPDFView.document = myPDFDocument ;

    PDFPage * firstPage = [myPDFDocument pageAtIndex:0] ;
    NSRect myBounds = [firstPage boundsForBox:kPDFDisplayBoxMediaBox] ;
    NSRect myNewBounds = NSMakeRect(0, 0, myBounds.size.width*2, myBounds.size.height*2+5) ;

    myPDFView.frame = myNewBounds ;
    myPDFView.autoScales = YES ;

    return myPDFView ;

欠点:

  • PDFのテキストを選択できます。ズームインまたはズームアウトできます。しかし、これらの可能性なしに、PDF ドキュメントを画像として表示したい
  • 2係数が必要な理由がわかりません。Finder よりも NSView の方が PDF が小さく表示されるのはなぜですか?
  • 私の画像の周りにいくつかの余白があります
4

1 に答える 1