Hi, im trying to calculate distance from inserted image to top/bottom of image parrent page. Is it possible? Tryed pic.top property but its value is 0 (my pic is like in middle of the page).
Thanks!
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("test.pdf");
foreach (PdfPageBase page in pdf.Pages)
{
foreach (PdfImageInfo pif in page.ImagesInfo)
{
RectangleF bounds = pif.Bounds;
//float topDistance = bounds.Top;
//float bottomDistance = page.Size.Height - bounds.Bottom;
float topDistance = bounds.Y;
float bottomDistance = page.Size.Height - bounds.Y - bounds.Height;
////Convert the unit
//PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
//float pixelTop = unitCvtr.ConvertUnits(topDistance, PdfGraphicsUnit.Point, PdfGraphicsUnit.Pixel);
//float pixelBottom = unitCvtr.ConvertUnits(bottomDistance, PdfGraphicsUnit.Point, PdfGraphicsUnit.Pixel);
}
}
Document doc = new Document();
doc.LoadFromFile("test.docx");
MemoryStream ms = new MemoryStream();
doc.SaveToStream(ms,Spire.Doc.FileFormat.PDF);
PdfDocument pdf = new PdfDocument();
pdf.LoadFromStream(ms);
foreach (PdfPageBase page in pdf.Pages)
{
foreach (PdfImageInfo pif in page.ImagesInfo)
{
RectangleF bounds = pif.Bounds;
//float topDistance = bounds.Top;
//float bottomDistance = page.Size.Height - bounds.Bottom;
float topDistance = bounds.Y;
float bottomDistance = page.Size.Height - bounds.Y - bounds.Height;
////Convert the unit
//PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
//float pixelTop = unitCvtr.ConvertUnits(topDistance, PdfGraphicsUnit.Point, PdfGraphicsUnit.Pixel);
//float pixelBottom = unitCvtr.ConvertUnits(bottomDistance, PdfGraphicsUnit.Point, PdfGraphicsUnit.Pixel);
}
}
Document doc = new Document();
doc.LoadFromFile("sample.docx");
Section section = doc.Sections[0];
foreach (Paragraph para in section.Paragraphs)
{
foreach (DocumentObject obj in para.ChildObjects)
{
if (obj is ShapeObject)
{
ShapeObject shape = obj as ShapeObject;
double topDistance = shape.VerticalPosition;
double bottomDistance = section.PageSetup.PageSize.Height - topDistance - shape.Height;
}
if (obj is DocPicture)
{
DocPicture picture = obj as DocPicture;
double topDistance = picture.VerticalPosition;
double bottomDistance = section.PageSetup.PageSize.Height - topDistance - picture.Height;
}
}
}