Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Insert_text and and Adobe Acrobat DC has encountered an unknown error. #2121

Discussion options

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.

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 video, how it works

This is input file. Input file from Autodesk Autocad (dwg to pdf.pc3)
in.pdf
This is output file
out.pdf

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
1 reply
Comment options

Thank You very much!

Answer selected by Avtonkadov
Comment options

I also encountered this problem in version 1.24.11, python3.8.10

You must be logged in to vote
0 replies
Comment options

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

You must be logged in to vote
1 reply
Comment options

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.

Comment options

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.

You must be logged in to vote
1 reply
Comment options

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.

Comment options

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

You must be logged in to vote
0 replies
Comment options

And when the PDF output using the morph parameter is converted using Ghostscript, such an error will occur
image
Uploading 4.pdf...

You must be logged in to vote
1 reply
Comment options

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.

Comment options

You must be logged in to vote
0 replies
Comment options

So, perhaps the inserted text does have problems indeed

You must be logged in to vote
0 replies
Comment options

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

You must be logged in to vote
0 replies
Comment options

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?

You must be logged in to vote
1 reply
Comment options

No.

Comment options

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
image
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /