PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Wed Oct 29, 2025 3:33 pm

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  [ 6 posts ] 
Author Message
 Post subject: Mix migradoc and images
PostPosted: Mon Jan 27, 2014 8:56 am 
Offline

Joined: Mon Jan 27, 2014 8:50 am
Posts: 3
I'm using the sample MigraDoc code and it seems to be working fine. Now I want to add a couple of images at the end of the document. I suppose I have to do this with PDFSharp? How exactly would I go about adding an PNG image at the end of this sample code?

Code:
static void Main()
{
  // Create a MigraDoc document
  Document document = Documents.CreateDocument();
 
  //string ddl = MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToString(document);
  MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");
 
  PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
  renderer.Document = document;
 
  renderer.RenderDocument();
 
  // Save the document...
  string filename = "HelloMigraDoc.pdf";
  renderer.PdfDocument.Save(filename);
  // ...and start a viewer.
  Process.Start(filename);
}


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 27, 2014 10:10 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
Tester wrote:
I suppose I have to do this with PDFSharp?
You can use the AddImage method of the Section class to add images to the MigraDoc document.
That's better than using PDFsharp methods IMHO.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 29, 2014 9:10 am 
Offline

Joined: Mon Jan 27, 2014 8:50 am
Posts: 3
Thanks. Is there a way to scale images down?


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 29, 2014 9:40 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
What do you mean with "scale down"?
You can specify width and height for each image. Image data will not be modified.

To shrink the image, use .NET functions to create a new, smaller image before calling AddImage.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 29, 2014 10:12 am 
Offline

Joined: Mon Jan 27, 2014 8:50 am
Posts: 3
How do I specify height and width for the image?


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 29, 2014 12:17 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
A simple example:
Code:
Image image = section.AddImage("../../images/Logo landscape.png");
image.Width = "10cm";
From here:
http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

Another example:
Code:
  // Put a logo in the header
  Image image = section.Headers.Primary.AddImage("../../PowerBooks.png");
  image.Height = "2.5cm";
  image.LockAspectRatio = true;
  image.RelativeVertical = RelativeVertical.Line;
  image.RelativeHorizontal = RelativeHorizontal.Margin;
  image.Top = ShapePosition.Top;
  image.Left = ShapePosition.Right;
  image.WrapFormat.Style = WrapStyle.Through;
From here:
http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot], TH-Soft and 159 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