如何在C#中使用Graphics.DrawString保存PDF?

时间:2013-04-25 20:21:02

标签: c# pdf-generation

我有打印预览的Graphics.DrawString方法。

现在我想使用相同的代码将其另存为PDF。我有一个Form,我创建了一个printprewiew,我想将printPrview保存为pdf。

这样做是否可行?

1 个答案:

答案 0 :(得分:0)

我有一个可能对您有帮助的解决方案,但它需要下载并安装" CutePDF Writer"。 CutePDF Writer是免费软件。你可以从那里的官方网站下载。

import UIKit
import MapKit
import CoreLocation

class ViewController: `UIViewController, CLLocationManagerDelegate` {
  @IBOutlet weak var Mapview: MKMapView!
  var manager = CLLocationManager()

  override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let pinLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(51.5078788, -0.08773210000003928)
    let objectAnn = MKPointAnnotation()
    objectAnn.coordinate = pinLocation
    objectAnn.title = "London Bridge"
    objectAnn.subtitle = "London, United kingdom"
    self.Mapview.addAnnotation(objectAnn)
  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }

  @IBAction func Directions(sender: AnyObject) {
    UIApplication.sharedApplication().openURL(NSURL(string: "http://maps.apple.com/maps?daddr=51.5078788,-0.08773210000003928")!)
  }

  @IBAction func LocateMe(sender: AnyObject) {
    manager.delegate = self
    manager.desiredAccuracy = kCLLocationAccuracyBest
    manager.requestWhenInUseAuthorization()
    manager.startUpdatingLocation()

    Mapview.showsUserLocation = true
  }

  func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let userlocation:CLLocation = locations[0] as CLLocation

    manager.stopUpdatingLocation()

    let location = CLLocationCoordinate2D(latitude: userlocation.coordinate.latitude, longitude: userlocation.coordinate.longitude)
    let span = MKCoordinateSpanMake(0.5, 0.5)
    let region = MKCoordinateRegion(center: location, span: span)

    Mapview.setRegion(region, animated: true)
  }
}

但它会显示保存为对话框以将文件保存为pdf。