Border around a PDF document
Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Border around a PDF document
Hello, I need to draw a border (rectangle) of a certain width and color around the whole document. What appropriate function could I use to do it?
Last edited by relapse on Fri Jan 20, 2012 12:20 pm, edited 1 time in total.
-
- Site Admin
- Posts: 19913
- Joined: Mon Jan 12, 2009 8:07 am
Re: Border around a PDF document
Hello relapse,
You have posted in the Viewer SDK forums. If you are a developer - then you should be able to simply place a rectangle with no filling, and a border with the desired colour and thickness on each page - and make it as big as the page itself - and this should do the trick.
You should be able to do that with a simple JS.
Best,
Stefan
You have posted in the Viewer SDK forums. If you are a developer - then you should be able to simply place a rectangle with no filling, and a border with the desired colour and thickness on each page - and make it as big as the page itself - and this should do the trick.
You should be able to do that with a simple JS.
Best,
Stefan
You do not have the required permissions to view the files attached to this post.
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Border around a PDF document
Hi, I thought there is any SDK function to frame e.g. a new page that contents an area cropped from an original document. I don't use JavaScript, only C#.
-
- Site Admin
- Posts: 19913
- Joined: Mon Jan 12, 2009 8:07 am
Re: Border around a PDF document
Hi relapse,
You can execute JS code inside the Viewer AX - and you can call that from your C# code
Please check the examples in
C:\Program Files\Tracker Software\PDF-XChange Viewer SDK\Examples\C#Examples\JavaScript
And the full set of JS commands you can find here:
JavaScript for Acrobat API Reference
Best,
Stefan
You can execute JS code inside the Viewer AX - and you can call that from your C# code

Please check the examples in
C:\Program Files\Tracker Software\PDF-XChange Viewer SDK\Examples\C#Examples\JavaScript
And the full set of JS commands you can find here:
JavaScript for Acrobat API Reference
Best,
Stefan
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Border around a PDF document
Sorry, I can't find the appropriate JS function with that you drew that nice rect in your file 

-
- Site Admin
- Posts: 19913
- Joined: Mon Jan 12, 2009 8:07 am
Re: Border around a PDF document
Hello relapse,
Actually - I created the sample file manually using the end user Viewer, but here is a script that will add a border rectangle on an A4 page. If your pages are with different dimensions you will need to calculate the rectangle size in points yourself before calling this script:
Best,
Stefan
Actually - I created the sample file manually using the end user Viewer, but here is a script that will add a border rectangle on an A4 page. If your pages are with different dimensions you will need to calculate the rectangle size in points yourself before calling this script:
Code: Select all
var annot = this.addAnnot({
page: 0,
type: "Square",
author: "Stefan Dzhukelov",
name: "border rect",
rect: [0,0,595.275,841.889],
width: 20
})
Stefan
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Border around a PDF document
Sorry, I knew a similar example, I didn't think that an annotation could be used as a graphical figure.
I tried your code but i got the border frame displaced (see the file below). The rect do has a right size but it's placed wrong. His is my code:
I have to drag the rect one time, then it is placed properly. I think it's the point in the left lower corner of the whole page and not of the selection.

I tried your code but i got the border frame displaced (see the file below). The rect do has a right size but it's placed wrong. His is my code:
Code: Select all
object w, h;
ctrl.GetDocumentProperty(_documentId, "Pages[0].Width", out w, 0);
ctrl.GetDocumentProperty(_documentId, "Pages[0].Height", out h, 0);
double dW = Convert.ToDouble(w);
double dH = Convert.ToDouble(h);
string sResult;
string sJavaScipt = "this.addAnnot({page: 0, type: \"Square\", author: \"Your Name\", name: \"myStamp\", rect: [0, 0, " + dW.ToString(CultureInfo.InvariantCulture) + ", " + dH.ToString(CultureInfo.InvariantCulture) + "], width: 2})";
try
{
ctrl.RunJavaScript(sJavaScipt, out sResult, 0, 0);
}
catch (Exception ex)
{
ShowErrorMessage(System.Runtime.InteropServices.Marshal.GetHRForException(ex));
return;
}
You do not have the required permissions to view the files attached to this post.
-
- Site Admin
- Posts: 19913
- Joined: Mon Jan 12, 2009 8:07 am
Re: Border around a PDF document
Hello relapse,
Yes - the script as given in my previous post is using as (0,0) the lower left corner of the whole page - so you will need to calculate the appropriate offset based on where your selected text is.
Best,
Stefan
Yes - the script as given in my previous post is using as (0,0) the lower left corner of the whole page - so you will need to calculate the appropriate offset based on where your selected text is.
Best,
Stefan
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Border around a PDF document
Thanx, it works! 

-
- Site Admin
- Posts: 19913
- Joined: Mon Jan 12, 2009 8:07 am
Re: Border around a PDF document
Great to hear!
Best,
Stefan
Best,
Stefan