- Home
- Forum
- Xamarin.Forms
- Showing images in a PdfLightTable cell
Showing images in a PdfLightTable cell
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 ?
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
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
Hi Ali,
Our Syncfusion xamarin pdf will work in following platforms.
Xamarin.Android
Xamarin.IOS
Xmarin.WindowsPhone
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
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
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
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
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 !!!!
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);
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
Using assembly resources is not an option for me. I download PDf files during runtime and process them !
Is it the only option ?
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
- 12 Replies
- 3 Participants
-
AB Ali Ben Zarrouk
- Nov 14, 2014 04:05 PM UTC
- Nov 27, 2014 06:27 AM UTC