Image display on PDF file

Posted by: Swapnil.Walwadkar on 13 March 2022, 10:54 pm EST

  • Posted 13 March 2022, 10:54 pm EST

    Hi,

    We are having 3 images, added into PDF file at Left, Center, Right respectively.

    When Windows 10 is installed freshly and no other software is installed except .net framework.

    We added all 3 images but Right side logo is not displayed. (its invisible on PDF file).

    Though Left and Center Image is displayed properly.

    With the same code snippet we don’t observed this issue on other system.

    It is only occuring when we are using fresh PC without installing anything.

    We are using following function:

    private RenderObject GetPDFHeader(Font font)

    {

    if (SelectedUserSettings.IsLogoSelected)

    {

    string insertUserNameOnPDF = null;

    RenderGraphics Leftlogo = null;

    RenderGraphics Centerlogo = null;

    RenderGraphics Rightlogo = null;

                if (ToolSettingsData.Instance.ConfigData.AppSettings.LogoData.LeftLogo)
                {
                    Leftlogo = GetLeftRenderedLogo();
                }
                if (ToolSettingsData.Instance.ConfigData.AppSettings.LogoData.CenterLogo)
                {
                    Centerlogo = GetCenterRenderedLogo();
                }
                if (ToolSettingsData.Instance.ConfigData.AppSettings.LogoData.RightLogo)
                {
                    Rightlogo = GetRightRenderedLogo();
                }
    
                headerTable.Cells[rowIndex, 0].RenderObject = Leftlogo;
                headerTable.Cells[rowIndex, 0].Style.ImageAlign.AlignHorz = ImageAlignHorzEnum.Left;
                headerTable.Cells[rowIndex, 0].Style.ImageAlign.AlignVert = ImageAlignVertEnum.Center;
                headerTable.Cells[rowIndex, 2].RenderObject = Centerlogo;
                headerTable.Cells[rowIndex, 2].Style.ImageAlign.AlignHorz = ImageAlignHorzEnum.Center;
                headerTable.Cells[rowIndex, 2].Style.ImageAlign.AlignVert = ImageAlignVertEnum.Center;
                headerTable.Cells[rowIndex, 4].RenderObject = Rightlogo;
                headerTable.Cells[rowIndex, 4].Style.ImageAlign.AlignHorz = ImageAlignHorzEnum.Right;
                headerTable.Cells[rowIndex, 4].Style.ImageAlign.AlignVert = ImageAlignVertEnum.Center;
    
                rowIndex = rowIndex + 1;
    
                //Seperator
                headerTable.Cells[rowIndex, 0].Text = "          ";
                headerTable.Cells[rowIndex, 0].SpanCols = 5;
                headerTable.Rows[rowIndex].Height = new Unit(5, UnitTypeEnum.Mm);
                rowIndex = rowIndex + 1;
           }
    

    }

    We add this returned rendered object as a child to C1 Print Document.

    What will be the solution to display Right image on PDF file.

  • Posted 14 March 2022, 6:06 pm EST

    Hello Swapnil,

    Thanks for the code snippet.

    We suggests you to use RenderImage to load images in Pdf through C1PrintDocument.

    Also, set the column’s width accordingly. So,that the RenderedObject will visible on the document. (see code snippet for three equal columns)

    
    headerTable.Cols[0].Width = "33.3%";
    headerTable.Cols[1].Width = "33.3%";
    headerTable.Cols[2].Width = "33.3%";
    
    

    Please refer the attached sample for the same : PdfRenderObjectDemo.zip

    Best Regards,

    Nitin

  • Posted 15 March 2022, 8:26 pm EST - Updated 3 October 2022, 11:32 pm EST

    Hello Nitin,

    Thanks for your reply.

    We tried the above solution, however, the issue is only partially resolved.

    Please check the attached output.

    In ‘ImageIssue.jpg’, very small images were added in PDF. But we want to add images of 50(H) X 100(W) as described in ‘Expected.jpg’.

    Could you please look check and revert?

  • Posted 15 March 2022, 9:15 pm EST - Updated 3 October 2022, 11:32 pm EST

    Hi Swapnil,

    Thanks for the snapshot.

    The first Row Height of table is fixed with 5 mm, that’s why the image is displayed in smaller size. To achieve your requirement You can adjust row height accordingly.

    Like, if you want row height of 350 pixels, then you can set as: (see code snippet)

    
    headerTable.Rows[rowIndex].Height = new Unit(350, UnitTypeEnum.Pixel);
    
    

    See Image:

    Please refer the attached modified sample for the same: PdfRenderObjectDemo_Mod.zip

    Best Regards,

    Nitin

  • Posted 16 March 2022, 9:21 pm EST

    Hi Nitin,

    Thanks for the snapshot.

    Actually, irrespective of the size of the input image, we want to make that image of size 50 H * 100 W and add it to the PDF. Please find the CodeSnippet.jpg and let us know how can we stretch/resize input images to some fixed size 50 H * 100 W.

  • Posted 16 March 2022, 9:26 pm EST - Updated 3 October 2022, 11:32 pm EST

    Hi Nitin,

    Sorry, I forgot to attach snapshots in the previous post.

    Attaching following snapshots:

    CodeSnippet.png

    550X50.png: If we add this image, it occupies the entire space of that column. This is not expected.

  • Posted 16 March 2022, 10:24 pm EST - Updated 3 October 2022, 11:32 pm EST

    Hi Swapnil,

    Thanks for the snapshots.

    We have replicated you issue at our end. While rendering 500*50.png into three columns, it occupies the entire space of the column. You can resize this image at the time of loading as: (see code snippet)

    
    RenderImage Leftlogo = new RenderImage();
     Leftlogo.Image = new Bitmap(System.Drawing.Image.FromFile("../../logo.png"),100,50);
    
    

    See Previous Output:

    See Current Output:

    Please refer the attached modified sample for the same: PdfRenderObjectDemo_Mod2.zip

    Best Regards,

    Nitin

  • Posted 20 March 2022, 8:33 pm EST - Updated 3 October 2022, 11:32 pm EST

    Hi Nitin,

    We resize the image at the time of loading as per the above suggestion.

    We observed that size of the image is not same.

    Case 1: Please find the below snapshot when we used Resize image method :

    public RenderGraphics ResizeImage(Image image, int width, int height)

    {

    var destRect = new Rectangle(0, 0, width, height);

    var destImage = new Bitmap(width, height);

            RenderGraphics renderGraphics = new RenderGraphics();
            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
    
            renderGraphics.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            renderGraphics.Graphics.CompositingMode = CompositingMode.SourceCopy;
            renderGraphics.Graphics.InterpolationMode = 
    

    InterpolationMode.HighQualityBicubic;

    renderGraphics.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

    renderGraphics.Graphics.CompositingQuality = CompositingQuality.HighQuality;

    using (ImageAttributes wrapMode = new ImageAttributes())

    {

    wrapMode.SetWrapMode(WrapMode.TileFlipXY);

    renderGraphics.Graphics.DrawImage(image, new Rectangle(0, 0, width, height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);

    }

            renderGraphics.Style.ImageAlign.AlignVert = ImageAlignVertEnum.Center;
            return renderGraphics;
            return r;
        }
    

    Case 2: Please find the below snapshot when the solution provided by you :

                RenderImage Leftlogo = new RenderImage();
                RenderImage Centerlogo = new RenderImage();
                RenderImage Rightlogo = new RenderImage();
    
                if (ToolSettingsData.Instance.ConfigData.AppSettings.LogoData.LeftLogo)
                {
                    Leftlogo.Image = new Bitmap(System.Drawing.Image.FromFile(ToolSettingsData.Instance.ConfigData.AppSettings.LogoData.LeftLogoPath), 100, 50);
                }
                if (ToolSettingsData.Instance.ConfigData.AppSettings.LogoData.CenterLogo)
                {
                    Centerlogo.Image = new Bitmap(System.Drawing.Image.FromFile(ToolSettingsData.Instance.ConfigData.AppSettings.LogoData.CenterLogoPath), 100, 50);
                }
                if (ToolSettingsData.Instance.ConfigData.AppSettings.LogoData.RightLogo)
                {
                    Rightlogo.Image = new Bitmap(System.Drawing.Image.FromFile(ToolSettingsData.Instance.ConfigData.AppSettings.LogoData.RightLogoPath), 100, 50);
                }              
               
                headerTable.Width = Unit.Auto;
                headerTable.Cols[0].Width = new Unit(100, UnitTypeEnum.Point);
                headerTable.Cols[1].Width = "0%";
                headerTable.Cols[2].Width = new Unit(100, UnitTypeEnum.Point);
                headerTable.Cols[3].Width = "0%";
                headerTable.Cols[4].Width = new Unit(100, UnitTypeEnum.Point);
                headerTable.Rows[rowIndex].Height = new Unit(50, UnitTypeEnum.Point);
    
                headerTable.Cells[rowIndex, 0].RenderObject = Leftlogo;
                headerTable.Cells[rowIndex, 0].Style.ImageAlign.AlignHorz = ImageAlignHorzEnum.Left;
                headerTable.Cells[rowIndex, 0].Style.ImageAlign.AlignVert = ImageAlignVertEnum.Center;
                headerTable.Cells[rowIndex, 2].RenderObject = Centerlogo;
                headerTable.Cells[rowIndex, 2].Style.ImageAlign.AlignHorz = ImageAlignHorzEnum.Center;
                headerTable.Cells[rowIndex, 2].Style.ImageAlign.AlignVert = ImageAlignVertEnum.Center;
                headerTable.Cells[rowIndex, 4].RenderObject = Rightlogo;
                headerTable.Cells[rowIndex, 4].Style.ImageAlign.AlignHorz = ImageAlignHorzEnum.Right;
                headerTable.Cells[rowIndex, 4].Style.ImageAlign.AlignVert = ImageAlignVertEnum.Center;
    
                rowIndex = rowIndex + 1;
    
                //Seperator
                headerTable.Cells[rowIndex, 0].Text = "          ";
                headerTable.Cells[rowIndex, 0].SpanCols = 5;
                headerTable.Rows[rowIndex].Height = new Unit(5, UnitTypeEnum.Mm);
                rowIndex = rowIndex + 1;
    

    Is there any solution to get the same output?

  • Posted 20 March 2022, 11:29 pm EST

    Hi Utkarsha,

    Thanks for reaching out to us with your query.

    But we are unable to understand your requirement. After resizing image, the dimensions will be changed according to the given width and height.

    Could you please clarify your statement. So, that we can assist you accordingly.

    Best Regards,

    Nitin.

  • Posted 21 March 2022, 5:55 pm EST

    Hi Nitin,

    With the continuation of above query, we have 2 cases.

    case 1 : When we used RenderGraphics for loading image ResizeImage() method code is shared.

    case 2: When we used approach suggested by you i.e resize the image at the time of loading (using Bitmap)

    In above both cases size of the image on PDF is not same. Screenshots are shared above. We want output to be same even we changed approach.

  • Posted 21 March 2022, 10:50 pm EST - Updated 3 October 2022, 11:32 pm EST

    Hi Utkarsha,

    Sorry to inform you that we are unable to replicate this issue at our end. We have tried rendering image from RenderImage and RenderGraphics both results in same.

    See RenderImage snapshot.

    See Render Graphics snapshot.

    Please refer the attached sample for the same: PdfRenderObjectDemo_Mod3.zip

    Could you please provide a small sample replicating this behavior. So, that we can replicate this behavior at our end. You can also update in attached sample to replicate this behavior.

    Best Regards,

    Nitin.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels