Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector text only if view is in hierarchy #119

Open
cameron-erdogan opened this issue Dec 19, 2019 · 5 comments
Open

Vector text only if view is in hierarchy #119

cameron-erdogan opened this issue Dec 19, 2019 · 5 comments

Comments

@cameron-erdogan
Copy link

I'm observing some weird behavior when generating PDFs. My goal is to get a PDF from a UIView with UILabels where the PDF has vectorized, searchable text, not a rasterization of text.

When I pass in a view in the hierarchy and visible on screen to PDFGenerator.generated(by: ), the PDF is rendered with vectorized text, but the view I passed in gets mangled as a result. If instead I create a new instance of that view and pass that in instead, the resulting PDF is completely rasterized.

Any thoughts?

@adam-konecny
Copy link

@cameron-erdogan I have the same issue, did you find a workaround?

@cameron-erdogan
Copy link
Author

@racak94 sadly no. I ended up just using the pdf with rasterized text.

@vaghasiya
Copy link

any update ?

@zyflovelam
Copy link

zyflovelam commented Feb 25, 2022

Same question, any update on this issue?

@adam-konecny
Copy link

adam-konecny commented Jul 11, 2022

I found a solution. I replaced every UILabel used in the PDF with my custom subclass that overrides draw(_:in:) like this:

override func draw(_ layer: CALayer, in ctx: CGContext) {
        let isPDF = !UIGraphicsGetPDFContextBounds().isEmpty

        if !self.layer.shouldRasterize && isPDF {
            self.draw(self.bounds)
        } else {
            super.draw(layer, in: ctx)
        }
}

Here you can find the Stack Overflow thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants