PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sun Sep 14, 2025 3:52 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Thu Aug 20, 2015 7:35 am 
Offline

Joined: Fri Jul 03, 2015 1:16 pm
Posts: 8
Hi, I have a pdf document template with predefined table and rows/columns. I use pdfsharp to fill the form fields with data (as demonstrated in your samples). I was able to set font of the content. Now I need to set a border visible, is this possible or do I have to use MigraDoc and draw the whole template from scratch?

Thanks in advance


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 20, 2015 8:28 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3135
Location: Cologne, Germany
Hi!
Zare wrote:
Now I need to set a border visible, is this possible or do I have to use MigraDoc and draw the whole template from scratch?
I cannot answer that with the information I have. You do not show your template. Can you add the borders to the template?
viewtopic.php?f=2&t=832

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 20, 2015 8:39 am 
Offline

Joined: Fri Jul 03, 2015 1:16 pm
Posts: 8
My mistake, I didn't specify that I want to add border only to those rows I add data to. In my template there is a table with predefined 10 rows, 3 columns per row. I fill some of those rows (usually not more than 2) programmatically based on the data I get from a web service. I didn't think that posting an image of the template would give any more information, as it contains a company specific data and a blank table (no borders). I am actually interseted only in bottom border of the table row.


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 20, 2015 8:59 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3135
Location: Cologne, Germany
There are no tables in PDF.
You can easily draw some lines based on co-ordinates saved in your code. Disadvantage: Changes of the template will require changes of the code.

Getting co-ordinates from code would be better, but I think it is much more complicated.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 20, 2015 10:47 am 
Offline

Joined: Fri Jul 03, 2015 1:16 pm
Posts: 8
Thanks, do you have any example for this or know which of the downloaded samples includes simplest form to do this?


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 20, 2015 11:23 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3135
Location: Cologne, Germany
Use gfx.DrawLine() as in this sample:
http://www.pdfsharp.net/wiki/Graphics-s ... le_lines_0

You can use XUnit.FromMillimeter or XUnit.FromInch and others for unit conversions.
Code:
gfx.DrawLine(XPens.DarkBlue, XUnit.FromMillimeter(0), XUnit.FromMillimeter(150), XUnit.FromMillimeter(210), XUnit.FromMillimeter(150));

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 20, 2015 2:09 pm 
Offline

Joined: Fri Jul 03, 2015 1:16 pm
Posts: 8
Thanks. I also found that I can use Elements collection on the PdfTextField and a key "/Rect" to get coordinates. But there is something strange, my lines are drawn as if I got coordinates from the bottom of the page.


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 20, 2015 2:23 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3135
Location: Cologne, Germany
Maybe WorldToDefaultPage can help:
Code:
rect = gfx.Transformer.WorldToDefaultPage(New XRect(New XPoint(100, 400), New XSize(350, 150)))


If not then you may need a different transformation.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 20, 2015 2:26 pm 
Offline

Joined: Fri Jul 03, 2015 1:16 pm
Posts: 8
I will test some more, thanks for the help.


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 24, 2015 7:57 am 
Offline

Joined: Fri Jul 03, 2015 1:16 pm
Posts: 8
Very strange, I use the following to get coordinates of text field:
Code:
PdfArray coordinates = (PdfArray)txtField.Elements["/Rect"];
double x = double.Parse(coordinates.Elements[0].ToString(), System.Globalization.CultureInfo.GetCultureInfo("en-US"));
double y = double.Parse(coordinates.Elements[1].ToString(), System.Globalization.CultureInfo.GetCultureInfo("en-US"));
double w = double.Parse(coordinates.Elements[2].ToString(), System.Globalization.CultureInfo.GetCultureInfo("en-US"));
double h = double.Parse(coordinates.Elements[3].ToString(), System.Globalization.CultureInfo.GetCultureInfo("en-US"));
xg.DrawLine(XPens.Black, x, y, w, y);


It seems as I get coordinates from the bottom of the page and when I call the DrawLine it draws from the top.


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 24, 2015 9:12 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3135
Location: Cologne, Germany
Zare wrote:
It seems as I get coordinates from the bottom of the page and when I call the DrawLine it draws from the top.
So instead of "y" you have to use something like "842 - y".
842 is the height of a DIN A4 page. You have to use the height of your template page.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 24, 2015 9:42 am 
Offline

Joined: Fri Jul 03, 2015 1:16 pm
Posts: 8
Thanks, it worked!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 143 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group