Click here to Skip to main content
15,035,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to create a pdf of the current xamarin form. I used pdf sharp and itext7 to implement it but unable to do it.
but below code only capture the text of xamarin, not the image. i just want to save currently viewed xamarin form to pdf.
I am struggling with this for a few weeks.

What I have tried:

var pdf = PDFManager.GeneratePDFFromView(ss);
       string localFilename = Guid.NewGuid().ToString() + ".pdf";
       string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + localFilename;
       DependencyService.Get<IPdfSave>().Save(pdf, localFilename);
       await Launcher.OpenAsync(new OpenFileRequest
       {
           File = new ReadOnlyFile(path)
       });
Posted
Comments
Gerry Schmitz 15-Jul-21 1:02am
   
I guess it depends on what "ss" is pointing to. Or that you're not using Path.Combine. Or you're writing to a different file than reading. Or not.
Member 14192879 15-Jul-21 2:06am
   
ss is the stacklayout's name
Member 14192879 15-Jul-21 2:08am
   
my code is working well when I have the only labels but I add an image, it doesn't add an image to pdf and only convert text to pdf
Gerry Schmitz 17-Jul-21 13:13pm
   
The layout of the visuals has to be in the "updated state" for actual Height and Width when capturing. Can't tell what state the visuals are in.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900