# Links within PDF getting removed after processing using PDFKit

**URL:** <https://forums.swift.org/t/links-within-pdf-getting-removed-after-processing-using-pdfkit/59567>\
**Category:** Using Swift\
**Tags:** macos, pdfkit\
**Created:** [August 10, 2022, 4:26pm UTC](https://forums.swift.org/t/links-within-pdf-getting-removed-after-processing-using-pdfkit/59567 "2022-08-10T16:26:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vyshak](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@vyshak](https://forums.swift.org/u/vyshak)\
**Post date:** [August 10, 2022, 4:26pm UTC](https://forums.swift.org/t/links-within-pdf-getting-removed-after-processing-using-pdfkit/59567/1 "2022-08-10T16:26:01Z")

</div>

I'm using the following code to draw a text over PDF page.Everything works fine, but if you process a PDF with internal links eg: a Book with Content links to pages, the resultant PDF file seems to have the links stripped off.Why does this happen?

```swift
 let data = NSMutableData()
                    let consumer = CGDataConsumer(data: data as CFMutableData)!
                    let context = CGContext(consumer: consumer, mediaBox: nil, nil)!
                    let pdffile=PDFDocument(url: input)                   
                    for y in stride(from: 0, to: pagecount, by: 1)
                    {
                    let page: PDFPage = pdffile!.page(at: y)!
                    var mediaBox = page.bounds(for: PDFDisplayBox.mediaBox)
                    NSGraphicsContext.current = NSGraphicsContext(cgContext: context, flipped: false)
                    
                    let bounds = page.bounds(for: PDFDisplayBox.mediaBox)
                    let size = bounds.size                   
                    page.draw(with: .mediaBox, to: context)
                    text.draw(in:drawrect,withAttributes:textFontAttributes);
                    context.endPDFPage()
                    }
                    context.closePDF()
                    try! data!.write(to: GetOutputFileName(inputfile: x), options[.atomicWrite])

```
