Create rectangles with rounded corners

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: Daniel - PDF-XChange, PDF-XChange Support, Vasyl - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Xmedia
User
Posts: 58
Joined: Thu Aug 12, 2021 12:41 am

Create rectangles with rounded corners

Post by Xmedia »

Hello everyone,

Is there an (update) possibility to create rectangles with rounded corners?

Kind Regards
Xmedia
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19846
Joined: Mon Jan 12, 2009 8:07 am

Re: Create rectangles with rounded corners

Post by Stefan - PDF-XChange »

Hello Xmedia,

Unfortunately that is not possible for annotations - the annotations are defined in the PDF specification and there's no provision for rounded corners.

However I managed to achieve a rounded corner for a base content item using these steps:
1) Add a rectangular annotation
2) Flatten it to make it a base content item
3) With the "Edit objects" tool selected, double click on the rectangle to start editing it as vector shapes.
4) Add two new points to one corner:
image.png
5) remove the original corner point:
image(1).png
6) convert the diagonal line to a Bezier:
image(2).png
7) Edit the Bezier to make the needed curve:
image(3).png
8) Click "Finish Editing" - and you now have a rectangle with one rounded corner:
image(4).png
Kind regards,
Stefan
You do not have the required permissions to view the files attached to this post.
User avatar
PHK
User
Posts: 1394
Joined: Tue Nov 24, 2020 4:02 pm

Re: Create rectangles with rounded corners

Post by PHK »

Wow!
All best,

FringePhil
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19846
Joined: Mon Jan 12, 2009 8:07 am

Create rectangles with rounded corners

Post by Stefan - PDF-XChange »

:)
Mathew
User
Posts: 567
Joined: Thu Jun 19, 2014 7:30 pm

Re: Create rectangles with rounded corners

Post by Mathew »

*EDIT* I made an updated version posted below: viewtopic.php?p=186834#p186834

This gave me an idea: Could use javascript to draw a rounded corner rectangle as a polygon using the properties of a selected rectangle.

Unzip and save to the Javascripts folder.
rounded rectangles v0.1.zip
There are two things you can change to customize the corners on line 17 & 19 in the code. Number of segments is how smooth to draw the rounded corners. Radius of the corner is in points:

Code: Select all

	// number for segments to draw
	nSeg: 6,
	// radius of corners
	R: 8,
It will add a button to the addins toolbar:
image.png
Select a rectangle you want to convert to rounded corners, then press the button. It converts that rectangle to a polyline with rounded corners. If you undo right after it's done, the rectangle you drew will be restored.

If nothing is selected, it starts the rectangle tool, and if you draw a rectangle, it immediately changes it to rounded corners.

Limitations
  • If the rectangle is smaller than the radius, it will draw funny shapes.
You do not have the required permissions to view the files attached to this post.
Last edited by Mathew on Tue Nov 19, 2024 6:57 pm, edited 1 time in total.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19846
Joined: Mon Jan 12, 2009 8:07 am

Re: Create rectangles with rounded corners

Post by Stefan - PDF-XChange »

Hello Mathew,

That is lovely!
I've just tested it and it does work nicely (with large enough rectangles) :)

Once again a wholeheartedly thank you for making and sharing this script with everyone else!

Kind regards,
Stefan
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Create rectangles with rounded corners

Post by MedBooster »

if only this were a setting you could set with the oval tool. Basically making it round on the edges. Or the rectangle tool. If you do this and save it as default, will the corners be round by default?
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
Mathew
User
Posts: 567
Joined: Thu Jun 19, 2014 7:30 pm

Re: Create rectangles with rounded corners

Post by Mathew »

I did see something in the PDF Reference that gave me hope that it's something that could be implemented as part of the annotation properties, although it sounds like some viewers would ignore the property:
image.png
The rounded rectangles tool I made is a workaround that will show rounded corners in any viewer, but it has many problems (it's a separate annotation and there's currently no way to group it, it doesn't update when the rectangle size is changed, etc)
You do not have the required permissions to view the files attached to this post.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10998
Joined: Wed Jan 03, 2018 6:52 pm

Re: Create rectangles with rounded corners

Post by Daniel - PDF-XChange »

Hello, Mathew

Does your copy of the documentation offer any definition changes to that in PDF 1.7 or PDF 2.0? PDF 1.0 is quite old, and often unused these days, alongside that note bout this property being replaced in PDF 1.2, I would expect some other changes have come along since then. I don't have a copy myself, and the Dev team is quite busy at the moment, so I cannot go bother them unless it is mission critical.

Given the popularity of this request, I expect that if the spec has clear rules for it, we should offer it, but if it is a vague case open to interpretation, or one where many competitors would not have a consistent implementation, or respect the property, we would choose not to, for the sake of ensuring our files and features remain compatible with as many others as possible.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 567
Joined: Thu Jun 19, 2014 7:30 pm

Re: Create rectangles with rounded corners

Post by Mathew »

Most recent I have access to is 1.7 at this link: https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf

After digging a bit further, it's a bit disheartening: The BS (border style) entry has no information about radius, and will override the Border Entry.
image.png
image(1).png
image(2).png
Unless more recent versions added some other values under the BE entry S key, I get the feeling the best I can hope for is that PDFXChange implements grouping annotations and then I can group a 'rounded corner' polygon with a text box that has no border.
You do not have the required permissions to view the files attached to this post.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10998
Joined: Wed Jan 03, 2018 6:52 pm

Re: Create rectangles with rounded corners

Post by Daniel - PDF-XChange »

Hello, Mathew

That certainly isn't the most promising... If the Dev team has any news to share about there being an alternative solution for this, I will come back, or perhaps they will post here directly. For now, I cannot offer any promises of changes to come.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 567
Joined: Thu Jun 19, 2014 7:30 pm

Re: Create rectangles with rounded corners

Post by Mathew »

**SOLVED** as of build 388!

But: Can I request that the radius is accessible from javascript? Currently I see no way for a script to know that the corners are rounded, so any fill (ie hatch) cannot be made to fit inside the rounded corners. Also, would be great if the corners could be rounded on text boxes too...
User avatar
Paul - PDF-XChange
Site Admin
Posts: 7359
Joined: Wed Mar 25, 2009 10:37 pm

Re: Create rectangles with rounded corners

Post by Paul - PDF-XChange »

Hi, Mathew

we will be doing more work in this area, and the devs have agreed this is reasonable:
RT#7121: Feature Request :: editor :: access to rectangle round corners radius via JavaScript

I do not anticipate it in the next release, but it is officially in the pipe. We will have to wait and see how this pans out.
Best regards

Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
Mathew
User
Posts: 567
Joined: Thu Jun 19, 2014 7:30 pm

Re: Create rectangles with rounded corners

Post by Mathew »

Even though this script is mostly obsolete I did make some updates to it; it has a dialog box for the corner radius, and adds rectangles on text boxes, etc. but didn't think to upload. Here's the most recent version, and I added it to the ribbon UI on the home ribbon (it's in Tools > Add-in Tools for the classic UI).

rounded rectangles v0.4.zip

It still generates a polygon, because there's no way to access the corner radius property from javascript.

Changes:
  • add to ribbon home, and move to Add-in Tools in classic UI
  • changes to code to make more reusable
  • add inside/outside option, apply to other markup, add menu, save preferences, remove interactive draw rectangle (buggy)
You do not have the required permissions to view the files attached to this post.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10998
Joined: Wed Jan 03, 2018 6:52 pm

Create rectangles with rounded corners

Post by Daniel - PDF-XChange »

:)
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Create rectangles with rounded corners

Post by MedBooster »

I added this to the master Mathew Javascript scripts post as well (feel free to post in that thread as well Mathew) when you add new scripts.

Anyway......
these Javascript tools confuse me, and what still is a bummer; that you can't place shortcuts to it or bind keyboard shortcuts through the traditional keyboard shortcut menu freely like with native commenting types.
Also...
It seems these javascript tool "comments" don't actually appear in the comments pane :/
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
Mathew
User
Posts: 567
Joined: Thu Jun 19, 2014 7:30 pm

Re: Create rectangles with rounded corners

Post by Mathew »

MedBooster wrote: Wed Nov 20, 2024 12:31 pm Also...
It seems these javascript tool "comments" don't actually appear in the comments pane :/
I'm not sure what you mean? They show up for me:
image.png
You do not have the required permissions to view the files attached to this post.
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Create rectangles with rounded corners

Post by MedBooster »

By the way do you have something similar for rounded highlighting? Some of us prefer the rounded look highlights used to have in PDF-XCE a few years ago.
viewtopic.php?t=40387&hilit=highlight

Right under *polygon "shapes" maybe I had the comment category disabled, my bad!
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
Mathew
User
Posts: 567
Joined: Thu Jun 19, 2014 7:30 pm

Re: Create rectangles with rounded corners

Post by Mathew »

MedBooster wrote: Wed Nov 20, 2024 9:21 pm By the way do you have something similar for rounded highlighting? Some of us prefer the rounded look highlights used to have in PDF-XCE a few years ago.
viewtopic.php?t=40387&hilit=highlight
hmm. no... the problem is that javascript doesn't have access to the Blend Mode property (as far as I know) - otherwise one could make a solid color rectangle and give it rounded corners. One could do a workaround with three steps by setting the Blend Mode manually:

Draw a rectangle with solid color in your highlight style. I've made a few presets with Blend Mode set to "Multiply" so I can highlight areas:
image.png
Then run the rounded corners on it. The new shape will get everything except the Blend mode:
image(1).png
Select the annotation and change Blend Mode to "Multiply":
image(2).png
You do not have the required permissions to view the files attached to this post.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10998
Joined: Wed Jan 03, 2018 6:52 pm

Re: Create rectangles with rounded corners

Post by Daniel - PDF-XChange »

Hello, Mathew

At that point, we may as well just use the new official handling, and save the step of reapplying the blend mode:
PDFXEdit_iHi3TlNAEh.gif
This property is also available to the new "highlight area" tool:
image.png
Kind regards,
You do not have the required permissions to view the files attached to this post.
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 567
Joined: Thu Jun 19, 2014 7:30 pm

Re: Create rectangles with rounded corners

Post by Mathew »

:oops: good point!
User avatar
Dimitar - PDF-XChange
Site Admin
Posts: 2205
Joined: Mon Jan 15, 2018 9:01 am

Create rectangles with rounded corners

Post by Dimitar - PDF-XChange »

:)
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Create rectangles with rounded corners

Post by MedBooster »

PS: I was able to see the polygon or rounded rectangle when I tried again, I just made a mistake either when importing the script or when using the tool I guess... Or maybe it's not always it works the first attempt.


Anyway, here Mathew says this javascript tool is "superceded",
viewtopic.php?p=178663#p178663

is that by adjusting the property described above?
BTW. if you press add to default, is this property (corner radius) included into the custom rectangle?

(what terminology are we using? Custom tool? Preset? When we're talking about shapes with specific thickness color etc... ?
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19846
Joined: Mon Jan 12, 2009 8:07 am

Re: Create rectangles with rounded corners

Post by Stefan - PDF-XChange »

Hello MedBooster,

Maybe Mathew meant that now when we offer the "Corner Radius" setting directly, the custom tool he made is the one superseded.

It does not seem like the Corner Radius is remembered even if you "Set current style as default" - I will check with my colleagues if that is intended.

Kind regards,
Stefan
Mathew
User
Posts: 567
Joined: Thu Jun 19, 2014 7:30 pm

Re: Create rectangles with rounded corners

Post by Mathew »

MedBooster wrote: Thu Jan 30, 2025 9:16 am Anyway, here Mathew says this javascript tool is "superceded",
viewtopic.php?p=178663#p178663
Hi Medbooster,

I figured it's superceded because:
  1. PDF XChange now has a built-in way to make rounded corners on rectangles (although it's not accessible by javascript so any scripting won't account for the rounded corners); and
  2. I made a tool that does the same thing, but also with polygons and polylines. If one enters a fixed radius in the curved line tool, it will make rounded corners:
image.png
You do not have the required permissions to view the files attached to this post.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19846
Joined: Mon Jan 12, 2009 8:07 am

Create rectangles with rounded corners

Post by Stefan - PDF-XChange »

:)