empira / MigraDoc-1.5

MigraDoc Foundation - Creating documents on the fly
MIT License
218 stars 125 forks source link

FileNotFoundException #24

Closed ErSoul closed 4 years ago

ErSoul commented 5 years ago

I'm writing to a memory stream, but .net core says that the file doesn't exist, and then it highlights the pdfRenderer.RenderDocument()

The complete exception is: FileNotFoundException: Could not load file or assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

            image.Top = ShapePosition.Top;
            image.Left = ShapePosition.Right;
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();
            pdfRenderer.PdfDocument.Save(stream);
            return stream;
        }
    }

My complete code is:

public static MemoryStream PdfDoc()
        {
            MemoryStream stream = new MemoryStream();

            Document document = new Document();
            document.Info.Title = "Vouche";
            document.Info.Subject = "Muestra todo el proceso";
            document.Info.Author = "ersoul";

            MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");

            var style = document.Styles["Normal"];
            style.Font.Name = "Segoe UI";
            style.Font.Size = 16;
            style.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkBlue;

            Section section = document.AddSection();

            Paragraph paragraph = section.Headers.Section.AddParagraph();
            paragraph.AddFormattedText("First Line", TextFormat.Bold);
            paragraph.AddFormattedText("Second Line", TextFormat.Bold);
            paragraph.AddFormattedText("Third Line", TextFormat.Bold);

            Image image = section.Headers.Primary.AddImage("");
            image.LockAspectRatio = true;
            image.RelativeHorizontal = RelativeHorizontal.Margin;
            image.Top = ShapePosition.Top;
            image.Left = ShapePosition.Right;

            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
            pdfRenderer.Document = document;

            pdfRenderer.RenderDocument();
            pdfRenderer.PdfDocument.Save(stream);

            return stream;
        }

I'm following the example in here

TH-Soft commented 5 years ago

Something wrong with your .NET configuration for that project.