簡體   English   中英

Syncfusion PDF圖片Xamarin.ios

[英]Syncfusion PDF Images Xamarin.ios

目前,我正在從Xamarin.ios應用程序中生成動態PDF。 但是,即時消息當前正在嘗試做的是添加一個自定義列表類,該類包含一個字節數組(Image)和一個用於圖像標題的字符串。 但是,當我生成PDF文檔時,我對列表中包含的結果使用了foreach循環,以獲取每個圖像字節數組和相應的標題。

我遇到的問題是,當我獲得生成的PDF時,似乎將4張圖像打印到PDF中。 我不確定自己做錯了什么,但看不到我在做什么?

創建PDF網格的圖像部分:

        #region ATTACHED IMAGES GRID
        PdfGrid imagesGrid = new PdfGrid();

        imagesGrid.Columns.Add(2);
        imagesGrid.Columns[0].Width = 110;
        imagesGrid.Columns[1].Width = 400;

        PdfGridRow imagesGridTitle = imagesGrid.Rows.Add();
        imagesGridTitle.Cells[0].Value = "Attached Photos";


        AddImages(imagesGrid);


        #region CUSTOMISE STYLES

        imagesGrid.Style.CellPadding = generalPadding;

        imagesGridTitle.ApplyStyle(pdfGridHeaderStyle);



        imagesGrid.Rows.SetSpan(0, 0, 1, 2);

        #endregion

動態創建額外行的方法:

private static void AddImages(PdfGrid imagesGrid)
    {
        foreach (var image in FormResults.photoResults)
        {
            PdfGridRow newGridRow = imagesGrid.Rows.Add();
            newGridRow.Cells[0].Value = image.Caption;
            newGridRow.Cells[1].Value = CreatePDFImage(image.ImageByte);

            newGridRow.Cells[1].ImagePosition = PdfGridImagePosition.Fit;
        }
    }

從字節數組創建pdfimage的方法:

private static PdfImage CreatePDFImage(byte[] byteArray)
    {
        MemoryStream imageMs = new MemoryStream(byteArray);

        PdfImage image = new PdfBitmap(imageMs);

        return image;
    }

最后,我的自定義列表類:

public class PhotoResults
    {
        public byte[] ImageByte { get; set; }
        public string Caption { get; set; }
    }

使用BeginCellLayout事件處理程序可以實現您的要求。 請在下面找到示例並輸出PDF以供參考。

樣本: http //www.syncfusion.com/downloads/support/directtrac/217022/ze/Sample1494155968

輸出PDF: http : //www.syncfusion.com/downloads/support/directtrac/217022/ze/output-1577237401

注意:我為Syncfusion工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM