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

Mix migradoc and images
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2718
Page 1 of 1

Author:  Tester [ Mon Jan 27, 2014 8:56 am ]
Post subject:  Mix migradoc and images

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);
}

Author:  Thomas Hoevel [ Mon Jan 27, 2014 10:10 am ]
Post subject:  Re: Mix migradoc and images

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.

Author:  Tester [ Wed Jan 29, 2014 9:10 am ]
Post subject:  Re: Mix migradoc and images

Thanks. Is there a way to scale images down?

Author:  Thomas Hoevel [ Wed Jan 29, 2014 9:40 am ]
Post subject:  Re: Mix migradoc and images

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.

Author:  Tester [ Wed Jan 29, 2014 10:12 am ]
Post subject:  Re: Mix migradoc and images

How do I specify height and width for the image?

Author:  Thomas Hoevel [ Wed Jan 29, 2014 12:17 pm ]
Post subject:  Re: Mix migradoc and images

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

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