Curnelious
Curnelious

Reputation: 1

Draw a Bezier to a pdf using UIGraphics

So the creation of pdf works great, then I have some bezier path in which I want to add to this pdf, I am not sure how to add it and set it's location inside the file :

  //pdf
   UIGraphicsBeginPDFContextToFile(pathForPDF, CGRect.zero, nil)
   UIGraphicsBeginPDFPageWithInfo(CGRect(x: 0, y: 0, width: 1000, height: 1000), nil)

   // draw the bezier
   let pathFromSVGFile:UIBezierPath = // some bezier from file.

   let context = UIGraphicsGetCurrentContext()  // *obviously wrong
   context?.addPath((pathFromSVGFile?.cgPath)!)

   UIGraphicsEndPDFContext()

This will not add the path, but I am able to add other things to this file easily, not sure how to add a path and set a location.

Upvotes: 1

Views: 689

Answers (1)

Rob
Rob

Reputation: 437872

First, you don't have to use UIGraphicsGetCurrentContext. You can just pathFromSVGFile.stroke(). But before you do that, make sure to set your stroke color (e.g. UIColor.blue.setStroke()) and set the line width (e.g. pathFromSVGFile.lineWidth = 3).

So,

UIGraphicsBeginPDFContextToFile(pathForPDF, CGRect.zero, nil)
UIGraphicsBeginPDFPageWithInfo(CGRect(x: 0, y: 0, width: 1000, height: 1000), nil)

// draw the bezier
let pathFromSVGFile:UIBezierPath = // some bezier from file.

UIColor.blue.setStroke()
pathFromSVGFile.lineWidth = 3
pathFromSVGFile.stroke()

UIGraphicsEndPDFContext()

Upvotes: 1

Related Questions