簡體   English   中英

如何在pymupdf中實現PDF文件中Rect之前的文本

[英]How to achieve the text before Rect in PDF file in pymupdf

我正在嘗試實現“______”所在的坐標。 我可以使用 MuPDF 輕松實現。 獲得此矩形坐標后,我需要獲取此矩形坐標之前的字符串或字符。

我的主要目標是閱讀 PDF 文件,只要有用戶輸入,我就需要在那里繪制矩形並獲取要在該用戶輸入中填充的數據。

我希望我聽起來很清楚。

請看一下我到目前為止所做的代碼。

import fitz

file = "real.pdf"

doc = fitz.open(file)

def searchTextAndHighLight(page):
  text = "_"
  text_instances = page.searchFor(text)
  i = 0
  for inst in text_instances:
    print(inst)
    print("<----------------------------------------->")
    i+=1
    highlight = page.addRectAnnot(inst)
  print(i)
  doc.save("output.pdf", garbage=4, deflate=True, clean=True)

  for page in doc:
    searchTextAndHighLight(page)

任何建議都非常歡迎來完成我的任務。 提前致謝

我和你有同樣的問題。 嘗試這個。 這個對我有用。

import fitz

file = "real.pdf"

doc = fitz.open(file)

def searchTextAndHighLight(page):
  text = "_"
  text_instances = page.searchFor(text)
  i = 0
  for inst in text_instances:
    print(inst)
    print("<----------------------------------------->")
    i+=1
    highlight = page.addRectAnnot(inst)
    highlight.setBlendMode(fitz.PDF_BM_Multiply)
    highlight.update()
  print(i)
  doc.save("output.pdf", garbage=4, deflate=True, clean=True)

for page in doc:
  searchTextAndHighLight(page)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM