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

Docs out of date for PDF control?

looks like the documentation you have in there for image handling and such for the PDF control are out of date:

PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");

graphics.DrawImage(image, 0, 0);

doc.Save("Output.pdf");



the PdfBithmap and doc.Save methods only take streams, not file names...

I'm having a bit of trouble producing an image from your chart control and stuffing the image into a PDF as part of a report... the PDF document has a nifty doc.Save that allows you to write it to a memory stream, unfortunately the chart control does not support that so it's turning into a multi step affair of saving to a platform specific location, converting that file into a tream, putting the stream into the PdfBitmap, putting that into the doc, saving it to a memory stream and saving THAT to a platform specific file location so you can then, finally, email it out and then delete those files...

seems like this should be easier.



14 Replies

JL Jeff Lindborg August 22, 2016 07:43 PM UTC

and related to this... it'd be nice if the sfChart control (aside from being able to save to a memory stream directly) had the SaveAsImage method return the absolute path to the file on whatever platform you're on.

sfChart
.SaveAsImage("ChartSample.jpg");


your docs talk about the 3 different locations where these get stored but that's not a lot of help trying to get the full path to them so
you can do something with them (i.e. email them then remove them) - ended up having to write a lot of tedious platform specific code to
finally figure out what the paths are on the different platforms so I could get hold of them...




YP Yuvaraj Palanisamy Syncfusion Team August 24, 2016 04:37 AM UTC

Hi Jeff,

  
Thank you for contacting Syncfusion support.

  
 
Query #1: Regarding PDF 
  

The PCL version of Essential PDF supports only stream as input to the PdfBitmap, because PCL has restriction to use file stream, the UG documentation covers most common platforms such as Windows form, WPF etc. We have added the xamarin specific documentation to load and save the PDF document in Xamarin platform, similarly we have to use stream to load the images, please find the below documentation link.  
 
  
Query #2: Regarding SaveAsImage() in SfChart   
   
We have created a support incident under your account to track the status of this query. Please log on to our support website to check for further updates.

https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents
   

   
Please let us know if you have any concern.

  
 
Regards,
Yuvaraj  
 



JL Jeff Lindborg August 24, 2016 01:21 PM UTC

yeah, I understand that and have seen that doc page - I get the fill issues with PCL.
However, given your graphing tools do not support saving to a memory stream it makes doing something simple like creating a chart and adding a picture of that chart to a PDF very difficult because it forces me to then handle files for those pictures - you'll find very quickly this is not trivial.

I'd encourage you guys to sit down and actually do an example - just create a very simple chart and add that chart to a PDF file as an image.  That's it.  Just walk through the steps necessary to do that in PCL on Android or iOS.  It's far more painful than it should be.  If the claim is these control work for Xamarin they need to have the functionality to make that happen with a reasonable amount of effort.


YP Yuvaraj Palanisamy Syncfusion Team August 25, 2016 03:05 PM UTC

Hi Jeff, 
 
We have prepared a sample as per your requirement using Dependency service. Please find the sample from the below location, 
  
Regards, 
Yuvaraj 



JL Jeff Lindborg August 25, 2016 06:01 PM UTC

Appreciate the sample!
That said, I'm not sure how many folks would have come up with the UIGraphics.BeginImageContext/EndImageContext, converting to a JPEG stream, converting to a PDF then saving as a file sequence there for iOS and such - that's pretty complex stuff requiring several file cleanups along the way (think of adding several graphs to a single report PDF) -

Sure would be a lot cleaner if the chart control natively supported a "save as stream" function directly - all that platform specific code could effectively go away (other than saving the PDF doc as a file in a public folder so it could be emailed) - would be quite a bit cleaner to document and develop and it would seem like all the controls were part of a suite form the same company intended for the mobile platform.  Feels a pinch hacky like this.

Anyway - I'll make this work for what I'm doing at the moment.

thanks


YP Yuvaraj Palanisamy Syncfusion Team August 26, 2016 09:37 AM UTC

Hi Jeff,   
  
Thanks for your feedback.  
  
Currently we don’t have the support for “Return the Stream of Image in SaveAsImage() method". We have added it to our feature management system.   
    
This feature is estimated to be available in any of our upcoming release.    
   
Regards,   
Yuvaraj  



JL Jeff Lindborg August 29, 2016 01:53 AM UTC

well, finally got around to trying to plug this into my application - unfortunately the bit of magic getting the "native object" is returning null on Android:

var nativechart = (Com.Syncfusion.Charts.SfChart)SfChartRenderer.GetNativeObject(typeof(SfChart), formChart);

no error is thrown but this always returns null regardless of what chart instance I pass in - I have all the same NuGet libraries installed as you do and I'm using your implementation of the interface for Android - I can't find anything different in my application setup than yours and since I don't really know what the GetNativeObject is doing here I don't know how to debug it. Any theories as to why it's returning null?


JL Jeff Lindborg August 29, 2016 02:12 AM UTC

I see what's different - I'm creating several charts and wanting to put the jpg of the view into the PDF - you guys are showing a single graph on the app - if I just create the chart in your sample app but don't add it to the Content Page then the call to SfChartRenderer.GetNativeObject returns null as well - presumably that requires the chart be displayed on a content page to be able to get the bitmap to in turn get the stream to finally add it to the PDF.

Since I'm wanting to add 7 or 8 charts (think diabetes management type charts here) displaying them all on a content page in the process doesn't make a lot of sense... I really just need the "SaveAsImage" to work in a reasonable way to interact with the PDF library here...


JL Jeff Lindborg August 29, 2016 02:28 AM UTC

continuing to bang heads with this - the SaveAsImage doesn't seem to work if the chart is not currently drawn on a content page either - passing in a unique file name that file is not actually created anywhere I can find - doubly frustrating because you can't pass in a path and it doesn't return a path so the vague notes in the docs about where it goes are all you have to go on - finally just searched all of the Android file system for it and no file is there.  No error is thrown it's just not created.  Really a headache working with these libraries... 


YP Yuvaraj Palanisamy Syncfusion Team August 30, 2016 02:46 PM UTC

Hi Jeff,  
 
We have prepared a sample as per your requirement. Please find the sample from the below location. 
 
  
Note: For Android, we will update within two business days. 
 
Regards, 
Yuvaraj


JL Jeff Lindborg August 30, 2016 03:36 PM UTC

hmmm... iOS and Android project did not implement the GetImageStream or ViewPDF methods in your IChartDependencyService so it wont build/run

Did you bundle the wrong project maybe?


YP Yuvaraj Palanisamy Syncfusion Team August 31, 2016 02:41 PM UTC

Hi Jeff,  
 
Sorry for the inconvenience caused. 
 
We can reproduce the reported issue in Android, so we have attached the modified sample for your reference but the provided sample in the last update is working fine in iOS platform. Please find the sample from the below location. 
 
  
Please check and let us know if you are still facing the issue. 
 
Thanks 
Yuvaraj 



JL Jeff Lindborg August 31, 2016 05:12 PM UTC

well - it builds now but the Android version looks to be stubbed out - in the ChartDependencyService.cs file for the Android project the GetImageStream and ViewPDF are not actually implemented and so the button doesn't actually create a PDF with an image embedded.

 public Stream GetImageStream(SfChart formsChart)
        {
            return null;
        }

        public void ViewPDF(MemoryStream stream, string filename)
        {
        }

the iOS version looks to be implemented and is working correctly.


YP Yuvaraj Palanisamy Syncfusion Team September 2, 2016 12:56 PM UTC

Hi Jeff,

We have created a support incident under your account to track the status of this query. Please log on to our support website to check for further updates.

https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents  

Please let us know if you require any further assistance.

Thanks,
Yuvaraj. 
  


Loader.
Up arrow icon