PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Place element with coordinates
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3090
Page 1 of 1

Author:  brice34 [ Wed Apr 22, 2015 9:20 am ]
Post subject:  Place element with coordinates

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.

Author:  Thomas Hoevel [ Wed Apr 22, 2015 9:38 am ]
Post subject:  Re: Place element with coordinates

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.

Author:  brice34 [ Wed Apr 22, 2015 1:05 pm ]
Post subject:  Re: Place element with coordinates

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.

Author:  Thomas Hoevel [ Wed Apr 22, 2015 1:59 pm ]
Post subject:  Re: Place element with coordinates

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.

Author:  brice34 [ Wed Apr 22, 2015 3:05 pm ]
Post subject:  Re: Place element with coordinates

Thank you for your help, I will try with this sample.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/