PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Aug 16, 2018 2:31 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: MigraDoc/PdfSharp Images
PostPosted: Fri Jan 19, 2018 9:59 am 
Offline

Joined: Fri Jan 19, 2018 9:28 am
Posts: 2
Hi all,
This is my first project using MigraDoc/PdfSharp. I am writing C# program converting excel workbook into pdf file.
I have a problem with image positioning. The main issue is that I can't find already drawn row height.
All what i can find to this moment is row height same as in Excel, but when I'm creating pdf and text wraps in a cell,
the row expands and the picture overlaps the text.

Currently I'm doing it using method with MigraDoc header. I'hv already tried doing it as a watermart in PdfSharp but I'hv had the same problem.

Do you have any idea how to solve this problem?
Thanks in advance

Here is the part of code:
Code:
 List<ExcelDrawing> pictures = worksheet.Drawings.ToList();
 Bitmap imageBmp = (drawing as ExcelPicture).Image as Bitmap;
                imageBmp.Save(Application.StartupPath + "\\img.jpg");
                var position_start_row = drawing.From.Row ;
                var position_start_column = drawing.From.Column ;
               
             
                MigraDoc.DocumentObjectModel.Shapes.Image himg = section.Headers.Primary.AddImage(Application.StartupPath + "\\img.jpg");
                double imagePositionFromTop = 0;
                double imagePositionFromLeft = 0;

               
                for (int i = 0; i < position_start_column; i++)
                {
                    imagePositionFromLeft += table.Rows[position_start_row].Cells[i].Column.Width;
                }
 //this is the only way i cant access row height, when i try to it in different way I always  get 0 
                for (int i = 0; i < position_start_row + 1; i++)
                {
                    imagePositionFromTop += table.Rows[i].Cells[position_start_column].Row.Height;



                }
                himg.Top = imagePositionFromTop;
                himg.Left = imagePositionFromLeft;



Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 19, 2018 10:05 am 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 388
Location: CCAA
Hi!
Bubczak wrote:
Do you have any idea how to solve this problem?
Images and text do not overlap if you just add the images to paragraphs.
If you place images at absolute positions (like you do) then you are responsible to prevent overlapping between text and images.

I don't understand your requirements, so I cannot give any hints.

Using PDFsharp you have full control of text and image positions.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 19, 2018 10:44 am 
Offline

Joined: Fri Jan 19, 2018 9:28 am
Posts: 2
I will try to explain best as i can
Maybe overlaps was the wrong word.

Here it is how it looks in excel
Attachment:
loremipsum.PNG
loremipsum.PNG [ 30.02 KiB | Viewed 789 times ]


And here is how it looks like in my generated Pdf
Attachment:
pdf1.PNG
pdf1.PNG [ 28.34 KiB | Viewed 789 times ]


All i cant get from excel are cells where the picture starts(left upper corner), where picture ends and i can read height and width of the cells.
Now, using this i need to set position of my picture in the pdf. The issue is that when text in pdf wraps and the row expands i get what u can see above.
I must point out that this program should generate pdf's from different workbooks, not only from this particular one so i can't do it "by hand."


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 19, 2018 1:40 pm 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 388
Location: CCAA
You can set the vertical position of images relative to the current paragraph; if the paragraph above has several lines then the image will move downwards and will appear below the text.

Or make sure the text above fits a single line - can be done by truncating the text or by increasing the width of the page.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


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

All times are UTC


Who is online

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