We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Showing images in a PdfLightTable cell

Hi,

Can you please tell me how to put an image in a cell of a PdfLightTable ?

table.Style.ShowHeader = true;
            table.BeginCellLayout += (object sender2, BeginCellLayoutEventArgs args) => {
            if ((args.RowIndex > -1) && (args.CellIndex == 2))
               args.Graphics.DrawImage(elements[args.RowIndex].signature, args.Bounds);
            };


elements.Add(new TableUnit() {name = "Name", value= "Value", signature = PdfImage.FromStream(ToStream("Signature.png"))});

public static Stream ToStream(string filePath) {
         var stream = new System.IO.MemoryStream();
         return new UIImage(filePath).AsJPEG().AsStream();
         stream.Position = 0;
         return stream;
         }


This did not work ... :/

Any clue ?

12 Replies

PH Praveenkumar H Syncfusion Team November 17, 2014 11:16 AM UTC



Hi Ali,


Thank you for using syncfusion products,


We have created the sample to draw the “Png” image in PdfLightTable cell and attached for your reference,


if (args.CellIndex % 2 == 0 && !string.IsNullOrEmpty(args.Value))


{


//Drawing the image


args.Skip = true;


PdfImage image = PdfImage.FromStream (ToStream("pdf.png"));


Syncfusion.Drawing.RectangleF rect = args.Bounds;


args.Graphics.DrawImage (image, new Syncfusion.Drawing.RectangleF (rect.X + 2, rect.Y + 2, rect.Width - 2, rect.Height - 2));


}


 


 


public Stream ToStream(string path)


{


Stream stream = new MemoryStream();


stream =  UIImage.FromBundle(path).AsJPEG().AsStream();


//stream.Position = 0;


return stream;


}


 


Please let us know if you need further assistance.


With Regards,


Praveen




Attachment: PdfLightTableTesting_634e57cc.zip


AB Ali Ben Zarrouk November 17, 2014 12:16 PM UTC

It works thanks !


AB Ali Ben Zarrouk November 17, 2014 03:16 PM UTC

Can you please assist me with something else :

Do I necessarily need Xamarin.Forms for operations like :
- Load PDF file
- Show PDF file
- Add pages to PDF file

Can I do these without Xamarin.Forms


PH Praveenkumar H Syncfusion Team November 18, 2014 12:21 PM UTC

Hi Ali,

Our Syncfusion xamarin pdf will work in following platforms.

  1. Xamarin.Android

  2. Xamarin.IOS

  3. Xmarin.WindowsPhone

  4. Xamarin.Forms.

So you can use the all PDF related operations in all other platform also there is no necessary to use only xamarin.Forms.

With Regards,

Praveen



PH Praveenkumar H Syncfusion Team November 18, 2014 12:37 PM UTC

Hi Ali,

A quick note on our previous update. Our Pdf library for Xamarin is a portable library and can be used in any kind of xamarin app. It doesnt require a Xamarin.Forms dependency.

Please let me know if there is any other concerns.

With Regards,

Praveen



AB Ali Ben Zarrouk November 18, 2014 01:54 PM UTC

Hi,

Thanks for the info.
Is it possible to customise a cell ? Like for example having a table of elements like in attached picture.



Attachment: custom_cell.png_6f600bda.zip


KC Karthikeyan Chandrasekar Syncfusion Team November 20, 2014 11:50 PM UTC

Hi Ali,

Thank you for your interest in Syncfusion Products.

 

We are analysing the feasibility of your requirement, we will provide you the details shortly.

 

Regards,

Karthikeyan.C



AB Ali Ben Zarrouk November 24, 2014 09:28 AM UTC

Hello,

Thanks for your responsiveness.
I personally do not need the custom cells no more as I'll work with your classic cells.

I would like to know something else please. How to load a PdfDocument from a path in Xamarin. Couldn't do it ! Is it because I have a trial version that I don't find those methods as I saw methods to load from filepath in your documentation.

Thanks !!!!




AB Ali Ben Zarrouk November 24, 2014 09:36 AM UTC

Sorry but should it be like this ?

PdfDocument doc = new PdfDocument();
            Stream file2 = new FileStream("sample.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);    
            // Load the stream
            PdfLoadedDocument loadedDoc = new PdfLoadedDocument(file2);
            doc.ImportPageRange(loadedDoc, 0, loadedDoc.PageCount - 1);



PH Praveenkumar H Syncfusion Team November 25, 2014 08:54 AM UTC

Hi Ali,

Thank you for your update,

Currently we do have support to load the pdf document from stream.

Please refer the following code snippet.

Stream PdfStream = typeof(DetailViewController).GetTypeInfo().Assembly.GetManifestResourceStream("PdfLightTableTesting.Products.pdf");

PdfLoadedDocument document = new PdfLoadedDocument(PdfStream);

Please let us know if you need further assistance.

With Regards,

Praveen



AB Ali Ben Zarrouk November 26, 2014 09:48 AM UTC

Hi,

Using assembly resources is not an option for me. I download PDf files during runtime and process them !

Is it the only option ?


PH Praveenkumar H Syncfusion Team November 27, 2014 06:27 AM UTC

Hi Ali,

Thank you for your update,

Currently we do support to load the documents only from the stream using PdfLoadedDocument class.

We can load the document from the application documents folder as follow, please refer the below code snippet.

var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

FileStream file = File.OpenRead(path + "/Invoice.pdf");

byte[] data = new byte[file.Length];

file.Read(data, 0, (int)file.Length);

MemoryStream stream = new MemoryStream(data);

PdfLoadedDocument document = new PdfLoadedDocument(stream);

MemoryStream save = new MemoryStream();

document.Save(save);

document.Close(true);

Save("table.pdf", "application/pdf", save);

Please ensure the requested file present in the MyDocuments folder before get the stream from the file.

Please let us know if you need further assistance.

With Regards,

Praveen


Loader.
Live Chat Icon For mobile
Up arrow icon