PDF 突出显示图像上方/文本下方

编程入门 行业动态 更新时间:2024-10-23 07:23:29
本文介绍了PDF 突出显示图像上方/文本下方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试突出显示 pdf 中的文本,并在文本下方绘制突出显示的矩形.

它在大多数 PDF 上都可以正常工作,但是当我要突出显示的文本下面有图像/背景时,我遇到了问题.问题是高光矩形也是在图片下面绘制的,所以不可见.

我的绘图顺序是这样的:

  • 根据页面大小绘制一个空白矩形
  • 画高光
  • 使用 CGContextDrawPDFPage(context, page) 绘制 pdf;

有没有办法分别绘制PDF图像和文本?这样我就可以去

  • 空白矩形
  • pdf 图像/背景
  • 突出显示
  • pdf 文本

我是否必须对 pdf/上下文做一些事情,以便它按照我想要的方式自动绘制它?我试过弄乱上下文,但到目前为止没有任何效果,它完全在完整的 pdf 之下或之上

我见过的每个读者都这样做(PDFExpert、GoodReader、iAnnotate 仅举几例),所以这不可能是不可能的,我只是还没有找到解决方案:)任何帮助都会有所帮助,提前致谢!!

干杯

解决方案

我的理解是,这些其他应用程序本身正在阅读和呈现 PDF(例如,它们支持选择文本或添加注释),因此他们将能够以您提到的方式更轻松地将事物分层.

您开始使用的 CGPDFDocument 是一个不透明对象(在 OO 意义上,不是透明度),它可以自行绘制,但我不知道有什么方法可以打破和渲染文档的各个子层.

作为一种前进的方式,您可以考虑使用 Core Image (iOS5+) 或其他一些方法将高光层与 PDF 混合.如果您使用了正确的过滤器(可能是乘法),较暗的文本仍然会通过,并且 0.3 alpha 高光会与任何背景混合.

i'm trying to highlight text in a pdf, and have the highlighted rectangle to be drawn under the text.

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. 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);

Is there a way to draw the PDF images and text separately? so that I could go

  • blank rectangle
  • pdf images/background
  • highlight
  • pdf text

Do I have to do something to the pdf / context so that it draws it automatically the way I want it to? I've tried messing with the context but nothing worked so far, it's all drawn entirely under or entirely above the full 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!!

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.

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.

As a way forward, you could look at using Core Image (iOS5+) or some other method to blend the highlights layer with the 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.

更多推荐

PDF 突出显示图像上方/文本下方

本文发布于:2023-06-07 21:57:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/568492.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   文本   PDF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!