-
Notifications
You must be signed in to change notification settings - Fork 651
Insert_text and and Adobe Acrobat DC has encountered an unknown error. #2121
-
With PyMuPDF I add text to pdf, but then if open output file with Adobe Acrobat and try to edit this file, it massage error.
import io
import os
import fitz
doc = fitz.open("in.pdf")
ffile = "C:/windows/fonts/times.ttf"
text = "Раздел 22. Book 1. Chapter 2.pdf"
for page in doc:
w=page.rect.width
h=page.rect.height
page.clean_contents()
page.insert_font (fontname="f0", fontfile=ffile, encoding=fitz.TEXT_ENCODING_CYRILLIC)
if page.rotation==270:
ww = int(w-190/0.352)
#excess = page.insert_textbox(fitz.Rect(0, ww, 14,ww+300), text+"iijij",fontname="f0", fontsize = 12, rotate=-90)
excess = page.insert_text(fitz.Point(5, ww), text,fontname="f0", fontsize = 12, rotate=-90)
else:
ww = int(w-190/0.352)
#excess = page.insert_textbox(fitz.Rect(ww, h-14, ww+300,h+14), text,fontname="f0", fontsize = 12, rotate=0)
excess = page.insert_text(fitz.Point(ww, h-5), text, fontname="f0", fontsize = 12, rotate=0)
doc.ez_save( "out.pdf")
print (doc.page_count)
doc.close()
This is input file. Input file from Autodesk Autocad (dwg to pdf.pc3)
in.pdf
This is output file
out.pdf
Beta Was this translation helpful? Give feedback.
All reactions
You did not mention your PyMuPDF version.
Presumably your problem has to do with an issue fixed in the most current release 1.21.1rc1.
I checked your script and reproducer PDF and no problem occurred.
Replies: 11 comments 5 replies
-
You did not mention your PyMuPDF version.
Presumably your problem has to do with an issue fixed in the most current release 1.21.1rc1.
I checked your script and reproducer PDF and no problem occurred.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank You very much!
Beta Was this translation helpful? Give feedback.
All reactions
-
I also encountered this problem in version 1.24.11, python3.8.10
Beta Was this translation helpful? Give feedback.
All reactions
-
I updated python to 3.13.2 and pymupdf to the latest version, but this problem still exists. It is present in all pdf files that have inserted text using pymupdf. Before the text was inserted, acrobat could edit normally. I have also tried editing with other versions of acrobat. But the same problem exists........ Very strange. Is this a problem of the computer environment? @JorjMcKie
Beta Was this translation helpful? Give feedback.
All reactions
-
I am not able to tell what the problem of Adobe Acrobat may have.
The text inserted with PyMuPDF follows the standard PDF specifications, can be displayed by all PDF viewers and likewise can be extracted by relevant software.
So I am sorry to say that I have no advice on how to proceed.
Beta Was this translation helpful? Give feedback.
All reactions
-
Most PDF editors have no problem opening PDF files with text inserted using pymupdf, except Acrobat. Could it be that the PDF standards used are inconsistent? I tried adding text using PDF-xchange and then opening it with Acrobat, but this issue did not occur.
Beta Was this translation helpful? Give feedback.
All reactions
-
You cannot add standard text with PDF-xchange (the free version at least): you probably used one of these tools
image
That's not what we are talking about here.
Beta Was this translation helpful? Give feedback.
All reactions
-
I conducted many tests and found that this problem would not occur if the default helv was used instead of using insert_font to insert the font. But when I output files using cjk, acrobat will go wrong. The following are my files and code segments.
import fitz # PyMuPDF # doc = fitz.open('1.pdf') page = doc.load_page(0) font = fitz.Font(fontname="cjk") page.insert_font(fontname="cjk", fontbuffer=font.buffer) page.insert_text((50, 50), "text1", fontsize=20, fontname="cjk", ) doc.save('3.pdf',garbage=3,deflate=True)
1 is the original file, 2 is the file using helv, and 3 is the file using cjk. 3 will cause acrobat to report an error, but 2 won't
1.pdf
2.pdf
3.pdf
Beta Was this translation helpful? Give feedback.
All reactions
-
And when the PDF output using the morph parameter is converted using Ghostscript, such an error will occur
image
Uploading 4.pdf...
Beta Was this translation helpful? Give feedback.
All reactions
-
What "morph" parameter?
I see no indication for any problem. MuPDF's CLI tool can read it, compress it or build subset fonts, etc. The usual text extraction packages also have no problem at all.
I also looked at the code in the page's /Content
and manually checked the coding of the inserted text.
So, as long as Adobe cannot tell us details about what it thinks is wrong ("unknown error" is a ridiculous message) there is no way to do anything here.
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
So, perhaps the inserted text does have problems indeed
Beta Was this translation helpful? Give feedback.
All reactions
-
The fourth file was not uploaded successfully,This is the file after adding the morph parameter.
4.pdf
image
This error occurred when using Ghostscript for processing
image
It doesn't conform to adobe's PDF specification. This is not a reminder from adobe
Beta Was this translation helpful? Give feedback.
All reactions
-
However, when this parameter uses the helv font and inserts text without using insert_font, there will be no error. So, could it be a problem with insert_font?
Beta Was this translation helpful? Give feedback.
All reactions
-
No.
Beta Was this translation helpful? Give feedback.
All reactions
-
i also have the problem. my code is :
doc = pymupdf.open(template_path)
page = doc[0]
css = """
@font-face {
font-family: SimSun;
src: url(simsun.ttc);
font-weight: normal;
}
* {font-family: SimSun,sans-serif;text-align: justify;}
"""
archive = pymupdf.Archive(os.path.dirname(template_path))
rect = pymupdf.Rect([408, 625, 490, 680])
page.clean_contents()
page.insert_htmlbox(
rect,
f"<p style='font-size:14px;'>{notice_date}</p>",
css=css,
archive=archive,
)
doc.subset_fonts()
doc.ez_save(output_path)
return output_path
Beta Was this translation helpful? Give feedback.