PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 11:34 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Mar 19, 2020 3:29 pm 
Offline

Joined: Thu Mar 19, 2020 2:31 pm
Posts: 1
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.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 19, 2020 3:58 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 147 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