Hello, I've been using MigraDoc for a while now and I encountered two problems in version 1.32 (
http://pdfsharp.codeplex.com/releases/view/83749 ).
1. There is a casting problem in image rendering from double to float when using GetValueAsIntended. (ImageRenderer.cs attached) also was reported before on forum
2. The second problem is that in PDF the image is resized as requested but in RTF it is not. I can't find the problem so maybe I can get some help
I have attached image and the dlls.
Update:
It seems that its not actually a problem from migradoc.
\picscalex \picscaley
\picw \pich
Image resize arguments are written as is supposed to be but when opening the RTF in word document every image that doesn't have square format is altered by dividing picscaley by 4
ex: if we have an image with the arguments:
\picscalex22
\picscaley22\pichgoal66150\picwgoal27285\pich116681\picw48127
it will actually be read by Word as
\picscalex22\
picscaley8\pichgoal66150\picwgoal27285\pich116681\picw48127
but if we have a square image:
\picscalex22\picscaley22\pichgoal960\picwgoal960\pich1693\picw1693
the reading is done properly
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using MigraDoc.RtfRendering;
namespace ConsoleApplication4 {
class Program {
static void Main(string[] args) {
Document document = new Document();
// Add a section to the document
Section section = document.AddSection();
// Add a paragraph to the section
Paragraph paragraph = section.AddParagraph();
// Add some text to the paragraph
var image = section.AddImage(@"C:\template_figure.png");
image.LockAspectRatio = true;
image.Height = Unit.FromMillimeter(243.3611);
image.ScaleHeight = 0.95;
//PDF
const bool unicode = true;
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode);
pdfRenderer.Document = document.Clone();
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Save(@"C:\template_figure.pdf");
//RTF
RtfDocumentRenderer renderer = new RtfDocumentRenderer();
renderer.Render(document.Clone(), @"C:\template_figure.rtf", null);
}
}
}
Just change C:\template_figure.png to where the image is and update the dlls location.