-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PolyLine annotation is not visible #1805
Comments
Please share the output of "pdfly pagemeta" https://pypi.org/project/pdfly/ of the first page of that document |
|
If you look at the pdf, you will see the polyline. To make it visible change the color. The problem is just the default color. Set it to red ie. |
Interesting, I would have thought that black is the default color. Here is a complete example: from pypdf import PdfWriter
from pypdf.generic import AnnotationBuilder, NameObject, FloatObject, ArrayObject
writer = PdfWriter()
writer.add_blank_page(200, 200)
annotation = AnnotationBuilder.polyline(
vertices=[
(50, 50),
(50, 150),
(150, 150),
(150, 50),
(50, 50),
],
)
# Change the border color of the PolyLine:
annotation[NameObject("/C")] = ArrayObject(
[FloatObject(0.9), FloatObject(0.1), FloatObject(0)]
)
writer.add_annotation(page_number=0, annotation=annotation)
with open("output.pdf", "wb") as f:
writer.write(f) From the specs: |
It seems that the problem is on the side of the visualization of the pdf on Mac. I don't see the annotation using either Preview or Chrome, but I do see it using an online pdf reader. |
Is the new code I shared also causing those issues or is it just the old code? |
The code you shared did not solve the issue. from pypdf import PdfWriter
from pypdf.generic import AnnotationBuilder
writer = PdfWriter()
writer.add_blank_page(200, 200)
# Add the rectangle
annotation = AnnotationBuilder.rectangle(
rect=(50, 150, 150, 50),
)
writer.add_annotation(page_number=0, annotation=annotation)
with open("output.pdf", "wb") as f:
writer.write(f) The generated pdf has a visible annotation on Chrome but not on Preview (which seems to be known for poor annotation support). |
if the issue in on Preview, I think we can close this issue |
Let's leave it open to either document the color-thing or change the default value (which is blocked by the annotation PR #1745). This will be pretty easy to close once the annotation PR is merged (I now hope for mid of May) |
I'm trying to add a polyline annotation to a pdf file.
It does not work whether it is an existing file or a new file (add_blank_page).
Environment
Which environment were you using when you encountered the problem?
$ python -m platform macOS-12.6.1-arm64-arm-64bit $ python -c "import pypdf;print(pypdf.__version__)" 3.8.0
Code + PDF
This is a minimal, complete example that shows the issue:
The output pdf file is empty: output.pdf
The text was updated successfully, but these errors were encountered: