PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Aug 22, 2019 7:38 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Apr 22, 2015 9:20 am 
Offline

Joined: Wed Apr 22, 2015 9:17 am
Posts: 3
Hello everyone,

I am working with Migradoc documents. I succeded to print many documents very easily thanks to this tool. But I have a problem with a new document model I have to print. I noticed that with migradoc, elements are stacked on the page. Instead, I would like to place them with coordinates. From exemple, I would like to write 4 paragraphs, one on each corner. But the DocumentObject elements doesn't have coordinates, is it possible to place them anyway ?

Thank you and sorry for my poor english level.


Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 22, 2015 9:38 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2958
Location: Cologne, Germany
Hi!

You can use TextFrames to place paragraphs at absolute positions. It's up to you to prevent overlapping between main body and TextFrames (e.g. by setting top and bottom margins accordingly).

Or maybe mix MigraDoc and PDFsharp and use PDFsharp to draw at absolute positions.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 22, 2015 1:05 pm 
Offline

Joined: Wed Apr 22, 2015 9:17 am
Posts: 3
Hi !

thank you for your answer, I tried it but I have diffuculties to place textframes. For exemple, I have 4 paragraphs, I want to place them on each corner of the document. So I did this :

TextFrame tf1=document.LastSection.AddTextFrame();
tf1.MarginLeft=0;
tf1.MarginTop=0;
tf1.Add(para1);
TextFrame tf2=document.LastSection.AddTextFrame();
tf2.MarginLeft=Unit.FromCentimeter(10);
tf2.MarginTop=0;
tf2.Add(para2);
TextFrame tf3=document.LastSection.AddTextFrame();
tf3.MarginLeft=0;
tf3.MarginTop=Unit.FromCentimeter(20);
tf3.Add(para3);
TextFrame tf4=document.LastSection.AddTextFrame();
tf4.MarginLeft=Unit.FromCentimeter(10);
tf4.MarginTop=Unit.FromCentimeter(20);
tf4.Add(para4);

The numbers 10 and 20 are just test numbers, to see if I can place it where I want.
But the generated document is not at all what I want, maybe you could help me ? I don't know what to use between tf.Top, tf.RelativeTop, lf.MarginTop.


Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 22, 2015 1:59 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2958
Location: Cologne, Germany
Here is sample code using Image (Image and TextFrame share the same base class):
Code:
// Create image, 2 cm from top-left corner:
var image = document.LastSection.AddImage(@"C:\Users\...");
image.WrapFormat.Style=WrapStyle.Through;
image.WrapFormat.DistanceTop = "2cm";
image.WrapFormat.DistanceLeft = "2cm";
image.RelativeVertical = RelativeVertical.Page;
image.RelativeHorizontal = RelativeHorizontal.Page;
// Create image, 2 cm from top-right corner:
image = document.LastSection.AddImage(@"C:\Users\...");
image.WrapFormat.Style = WrapStyle.Through;
image.WrapFormat.DistanceTop = "2cm";
image.WrapFormat.DistanceRight = "2cm";
image.Left = ShapePosition.Right;
image.RelativeVertical = RelativeVertical.Page;
image.RelativeHorizontal = RelativeHorizontal.Page;
// Create image, 2 cm from bottom-right corner:
image = document.LastSection.AddImage(@"C:\Users\...");
image.WrapFormat.Style = WrapStyle.Through;
image.WrapFormat.DistanceBottom = "2cm";
image.WrapFormat.DistanceRight = "2cm";
image.Left = ShapePosition.Right;
image.Top = ShapePosition.Bottom;
image.RelativeVertical = RelativeVertical.Page;
image.RelativeHorizontal = RelativeHorizontal.Page;
"2cm" is the distance from the edge of the page. "image.Left = ShapePosition.Right" is a bit cryptical, but it works.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 22, 2015 3:05 pm 
Offline

Joined: Wed Apr 22, 2015 9:17 am
Posts: 3
Thank you for your help, I will try with this sample.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 6 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