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

Error en Stream.readout y stram.writeout

Hola lo que pasa es que sigo la documentacion de syncfusion y no tenia probleas hasta ahora al tratar de hacer un archivo pdf con su documentacion me sale el erros de stream que el read y write estan null y no puedo avanzar no se por que no se puede si copi los archivos correctamente de la documentacion de pdf xamarin
//Load the file as stream
Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Sample.pdf");
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
//Create booklet with two sides
PdfDocument document = PdfBookletCreator.CreateBooklet(loadedDocument, new SizeF(1000, 700), true);
MemoryStream memoryStream = new MemoryStream();
//Save the document into memory stream
document.Save(memoryStream);
//close the documents
document.Close(true);
loadedDocument.Close(true);
//Save the stream into pdf file
Xamarin.Forms.DependencyService.Get().Save("sample.pdf", "application/pdf", memoryStream);
public interface ISave
{
Task Save(string filename, string contentType, MemoryStream stream);
}
class SaveWindowsPhone: ISave
{
public async Task Save(string filename, string contentType, MemoryStream stream)
{
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile outFile = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
using (Stream outStream = await outFile.OpenStreamForWriteAsync())
{
outStream.Write(stream.ToArray(), 0, (int)stream.Length);
}
await Windows.System.Launcher.LaunchFileAsync(outFile);
}
}

11 Replies

KC Karthikeyan Chandrasekar Syncfusion Team December 19, 2018 03:59 AM

Hi Jonathan, 
Greetings from Syncfusion. 
We have tried with the code snippet which you provided from our UG documentation, but it is working fine as expected. We have attached the sample and UG link for your reference. 
 
Could you please modify the sample to reproduce your issue, so that we could further analyze in it and provide you the exact fix. 
Regards, 
Karthikeyan 



JE Jonathan Estrada Gonzalez December 19, 2018 02:27 PM

Pues ya copie el codigo tal y como esta y me sale un error no se por que sea este es mi codigo de erros 

System.ArgumentNullException
  HResult=0x80004003
  Mensaje = Value cannot be null.
  Origen = Syncfusion.Pdf.Portable
  Seguimiento de la pila:
   en Syncfusion.Pdf.Parsing.PdfLoadedDocument..ctor(Stream file)
   en Control.Pages.Catalogos.Archivos.BtnExport_Clicked(Object sender, EventArgs e) en C:\Users\LICONSA\source\repos\Control\Control\Control\Pages\Catalogos\Archivos.xaml.cs: línea 99
   en Xamarin.Forms.MenuItem.OnClicked()
   en Xamarin.Forms.MenuItem.Activate()
   en Xamarin.Forms.Platform.UWP.MenuItemCommand.Execute(Object parameter)
   en System.Runtime.InteropServices.WindowsRuntime.ICommandToWinRTAdapter.Execute(Object parameter)





KC Karthikeyan Chandrasekar Syncfusion Team December 20, 2018 06:34 AM

Hi Jonathan, 
Thank you for your update. 
The stack trace of the exception seems to be steam is null. Could you please confirm that the stream is valid. When we are retrieving the stream from the PDF document , the PDF document build action should be embedded.  
Please refer the screenshot below for your reference. 

 


Kindly check the sample, which we are provided in the last update. If the issue occurs specific to the document, kindly share the document or  sample which you are checking. It will be helpful for us to provide the solution earlier. 

Regards, 
Karthikeyan 



JE Jonathan Estrada Gonzalez January 21, 2019 01:01 PM

La Aplicacion me Corre perfectamente en UWP pero en android me sale este error al parecer es al abrir el archivo guardado en el telefono 


KC Karthikeyan Chandrasekar Syncfusion Team January 22, 2019 06:48 AM

Hi Jonathan, 

Starting from Android version (8.0, Marshmallow)  every android app need to request runtime permission when the application is deployed for the first time. This might be the cause of the exception  you get while saving the PDF document to the device. 

More detail on how to request runtime permission in Xamarin forms Android can be found in the link below: 

Also the sample for the same has been updated in Xamarin developer website which can be found in below link: 

Please note for saving the PDF in the mobile device “READ_EXTERNAL_STORAGE”  and “WRITE_EXTERNAL_STORAGE” permission needs to be enabled. 

Let us know if you need any further information in this. 

Regards, 
Karthikeyan 



JE Jonathan Estrada Gonzalez January 22, 2019 11:21 AM

De echo los permisos se los di desde que implemente el código de guardar el pdf pero me sigue saliendo lo mismo por eso preguntaba por que los permisos ya fueron asignado aquí les dejo una foto de los permisos y de mi código de android






Y pues estuve investigando y me dice que el android.net.uri ya no es compatible con el api despues de 23 y que tengo que usar un provider en vez de un file
no se que tan cierto sea esto



KC Karthikeyan Chandrasekar Syncfusion Team January 23, 2019 04:55 AM

Hi Jonathan, 
 
To resolve the permission exception when deploying application in Android Marshmallow and above target, it is need to grant permission for the application to access storage. We have done the changes in MainActivity.cs to grant permission when opening the application. 

 

Sample can be found in the link below: 

Let us know if you need any further information. 
Regards, 
Karthikeyan  



JE Jonathan Estrada Gonzalez January 23, 2019 10:15 AM

Hola Muchisimas Gracias por estar checando Mi Problema Ya lo solucione el dia de ayer poniendo un Provider con un content en mi codigo pero probare este codigo y vere igual la solucion muchisimas gracias 


KC Karthikeyan Chandrasekar Syncfusion Team January 24, 2019 01:44 AM

Hi Jonathan, 
Happy to know that your issue is resolved. Get back to us if you need any assistance in the future. 

Regards, 
Karthikeyan  



CM Carlos Mochón replied to Jonathan Estrada Gonzalez April 14, 2020 09:26 AM

Hola Muchisimas Gracias por estar checando Mi Problema Ya lo solucione el dia de ayer poniendo un Provider con un content en mi codigo pero probare este codigo y vere igual la solucion muchisimas gracias 

Hola Jonathan, llevo unos días con el mismo problema que tu planteas en este foro, he realizado los cambios que plantea Syncfusion, pero no son válidos.
Podrías compartir como lo solucionaste? indicas que "a lo solucione el dia de ayer poniendo un Provider con un content en mi codigo ", pero no consigo saber cómo realizarlo.

Muchas Gracias


SL Sowmiya Loganathan Syncfusion Team April 15, 2020 08:02 AM

Hi Carlos,    
   
We suspect that the issue occurs due to requiring runtime permission in the android app when the application is deployed for the first time. Kindly try the step by step process mentioned in the below KB to overcome this issue,    
  
If you still facing the issue, kindly revert us with the below information. So that we will analyze further and provide a better solution on this,    
 
  • Sample (facing the issue)
  • Android version
  • Product version
   
Please let us know If you have any concerns about this.    
   
Regards, 
Sowmiya Loganathan 


Loader.
Live Chat Icon For mobile
Up arrow icon