1

Right now I am able to generate a PDF using the code below. The issue is that the generated PDF is not searchable nor its texts copyable. (like the whole PDF is a image).

Is there a way to create a PDF using ios (Swift) that has its texts copyable/searchable?

Part of my code that generates the pdf:

let pdfFrame:CGRect = CGRect(x: 0, y: 0, width: sourceView.contentSize.width, height: sourceView.contentSize.height);

UIGraphicsBeginPDFContextToFile(dataFilename, pdfFrame, nil);
UIGraphicsBeginPDFPageWithInfo(pdfFrame, nil);

sourceView.contentOffset = CGPoint.zero;
sourceView.frame = pdfFrame;
let pdfContext : CGContext = UIGraphicsGetCurrentContext()!;
sourceView.layer.render(in: pdfContext);

UIGraphicsEndPDFContext();
Arasuvel
  • 2,971
  • 1
  • 25
  • 40
rsc
  • 10,348
  • 5
  • 39
  • 36

1 Answers1

2

In order to generate a PDF that is searchable, you need to create a PDF file that contains text. Your PDF is being created only with images. You can't use render(in:). Whatever text you want in the PDF needs to be drawn into the PDF context. See How to draw text in PDF context in Swift? for an example.

Community
  • 1
  • 1
rmaddy
  • 314,917
  • 42
  • 532
  • 579