PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Adding Image in MigraDoc Table error
http://forum.pdfsharp.com/viewtopic.php?f=2&t=4116
Page 1 of 1

Author:  mirrh [ Thu Mar 19, 2020 3:29 pm ]
Post subject:  Adding Image in MigraDoc Table error

First of all, Thank you so much for providing this a great tool.

I am trying to generate a PDF file from .NET Core Web API with each product image in the MigraDoc Table as below.

Version info
    .NET Core 2.1
    MigraDoc.DocumentObjectModel.Core 1.0
    MigraDoc.Rendering.Core 1.0
    PdfSharp.Core 1.0

Code:
/// <summary>
/// Populate the data table from DataSource.
/// </summary>
void FillContent()
{
    /*omitted
    ...
    */
    Table _table;

    var r = this._table.AddRow();
    int index = 0;

    foreach()
    {
        using (var webClient = new WebClient())
        {
            byte[] imageBytes = webClient.DownloadData(_baseUrl + value.ToString());
            string imageFilename = MigraDocFilenameFromByteArray(imageBytes);

            if(!string.IsNullOrEmpty(imageFilename))
            {
                var image = r.Cells[index].AddParagraph().AddImage(imageFilename);
                image.Height = "0.7cm";
                image.Width = "1.5cm";
                image.LockAspectRatio = true;
                image.RelativeVertical = RelativeVertical.Line;
                image.RelativeHorizontal = RelativeHorizontal.Margin;
                image.Top = ShapePosition.Top;
                image.Left = ShapePosition.Left;
                image.WrapFormat.Style = WrapStyle.Through;
            }
            _table.SetEdge(0, _table.Rows.Count - 2, _dataFields.Count, 2, Edge.Box, BorderStyle.Single, 0.75);
        }   
        index++;
    }

    /*omitted
    ...
    */
}

static string MigraDocFilenameFromByteArray(byte[] image)
{
    return "base64:" +
            Convert.ToBase64String(image);
}


However, The following error occurred.


---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
Internal error? JPEG image, but file not found!
---- Assert Long Message ----

at PdfSharp.Pdf.Advanced.PdfImage.InitializeJpeg()
at PdfSharp.Pdf.Advanced.PdfImage..ctor(PdfDocument document, XImage image)
at PdfSharp.Pdf.Advanced.PdfImageTable.GetImage(XImage image)
at PdfSharp.Pdf.PdfPage.GetImageName(XImage image)
at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.GetImageName(XImage image)
at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.Realize(XImage image)
at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.DrawImage(XImage image, XRect destRect, XRect srcRect, XGraphicsUnit srcUnit)
at PdfSharp.Drawing.XGraphics.DrawImage(XImage image, XRect destRect, XRect srcRect, XGraphicsUnit srcUnit)
at MigraDoc.Rendering.ImageRenderer.Render()
at MigraDoc.Rendering.Renderer.RenderByInfos(XUnit xShift, XUnit yShift, RenderInfo[] renderInfos)
at MigraDoc.Rendering.ParagraphRenderer.RenderImage(Image image)
at MigraDoc.Rendering.ParagraphRenderer.RenderElement(DocumentObject docObj)
at MigraDoc.Rendering.ParagraphRenderer.RenderLine(LineInfo lineInfo)
at MigraDoc.Rendering.ParagraphRenderer.Render()
at MigraDoc.Rendering.Renderer.RenderByInfos(XUnit xShift, XUnit yShift, RenderInfo[] renderInfos)
at MigraDoc.Rendering.TableRenderer.RenderContent(Cell cell, Rectangle innerRect)
at MigraDoc.Rendering.TableRenderer.RenderCell(Cell cell)
at MigraDoc.Rendering.TableRenderer.Render()
at MigraDoc.Rendering.DocumentRenderer.RenderPage(XGraphics gfx, Int32 page, PageRenderOptions options)
at MigraDoc.Rendering.DocumentRenderer.RenderPage(XGraphics gfx, Int32 page)
at MigraDoc.Rendering.PdfDocumentRenderer.RenderPages(Int32 startPage, Int32 endPage)
at MigraDoc.Rendering.PdfDocumentRenderer.RenderDocument()
at MaxApi.Common.PdfProvider.PdfService`1.CreatePdf(PdfData`1 pdfData, IHttpContextAccessor httpContextAccessor) in C:\WebApps.Source\MaxApi\MaxApi\Common\PdfProvider\PdfService.cs:line 26
at MaxApi.Controllers.ProductsController.GetProductPriceList(Int32[] productIds, String[] itemNos, String[] prices, Boolean includeCommissions, String[] listings, String[] lifeCycles, Boolean includeAccessories, String rebateStateId, Nullable`1 rebateProgramId, Boolean rebateOnly, String returnType) in C:\WebApps.Source\MaxApi\MaxApi\Controllers\ProductsController.cs:line 492
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.<>c.<OutputWaitEtwEvents>b__12_0(Action innerContinuation, Task innerTask)
at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(Action action, Boolean allowInlining)
at System.Threading.Tasks.Task.RunContinuations(Object continuationObject)
at System.Threading.Tasks.Task.FinishSlow(Boolean userDelegateExecute)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
at System.Threading.ThreadPoolWorkQueue.Dispatch()

I've tried other methods and spent so much time to resolve this issue.
Could anyone help me with this?

Thank you so much in advance.

Author:  Thomas Hoevel [ Thu Mar 19, 2020 3:58 pm ]
Post subject:  Re: Adding Image in MigraDoc Table error

mirrh wrote:
First of all, Thank you so much for providing this a great tool.
You are not using our tool. You use a port of our tool. Sorry, I cannot help.

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