简体   繁体   English

PDF高亮显示图像上方/文本下方

[英]PDF Highlighting above image / below text

i'm trying to highlight text in a pdf, and have the highlighted rectangle to be drawn under the text. 我正在尝试突出显示PDF中的文本,并在文本下方绘制突出显示的矩形。

It works fine on most PDF's, but I jumped into a problem when the text I'm trying to highlight has an image/background under it. 它在大多数PDF上都可以正常工作,但是当我要突出显示的文本下面带有图像/背景时,我陷入了一个问题。 The problem is that the highlight rectangle is drawn under the image as well, so it is not visible. 问题在于高亮矩形也绘制在图像下方,因此它不可见。

The drawing order I have is this: 我的绘图顺序是这样的:

  • draw a blank rectangle with the page size 用页面大小绘制一个空白矩形
  • draw the highlight 画出亮点
  • draw the pdf using CGContextDrawPDFPage(context, page); 使用CGContextDrawPDFPage(context,page)绘制pdf;

Is there a way to draw the PDF images and text separately? 有没有办法分别绘制PDF图像和文本? so that I could go 这样我才能去

  • blank rectangle 空白矩形
  • pdf images/background pdf图像/背景
  • highlight 突出
  • pdf text pdf文字

Do I have to do something to the pdf / context so that it draws it automatically the way I want it to? 我是否需要对pdf /上下文执行某些操作,以便它按照我希望的方式自动绘制? I've tried messing with the context but nothing worked so far, it's all drawn entirely under or entirely above the full pdf 我尝试弄乱上下文,但到目前为止没有任何效果,它们全部绘制在完整pdf之下或完全高于完整pdf

Every reader I've seen does this (PDFExpert, GoodReader, iAnnotate to name a few), so it can't be impossible, I just haven't found the solution yet :) Any help will help, thanks in advance!! 我见过的每个读者都这样做(PDFExpert,GoodReader,iAnnotate等),所以这并非不可能,我只是还没有找到解决方案:)任何帮助都会有所帮助,在此先感谢!

Cheers 干杯

My understanding is that these other apps are reading and rendering the PDF themselves (they support selecting text, or adding annotations, for example), so they would be able to much more easily layer things in the way you're mentioning. 我的理解是,这些其他应用程序本身就是在读取和呈现PDF(例如,它们支持选择文本或添加注释),因此它们将能够以您提到的方式更轻松地分层处理。

The CGPDFDocument you're starting with is an opaque object (in the OO sense, not transparency) that can draw itself, but I don't know of any way to break out and render various sublayers of the document. 您开始使用的CGPDFDocument是一个不透明的对象(从OO的意义上讲,不是透明的),它可以自行绘制,但是我不知道有什么方法可以分解和渲染文档的各个子层。

As a way forward, you could look at using Core Image (iOS5+) or some other method to blend the highlights layer with the PDF. 作为前进的方法,您可以考虑使用Core Image(iOS5 +)或其他方法将高光层与PDF融合在一起。 If you used the right filter (Multiply, maybe), the darker text would still come through and a .3 alpha highlight would blend with any background. 如果您使用了正确的滤镜(也许是乘法),则较暗的文本仍会通过,并且.3 alpha高光将与任何背景混合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM