Advertisement
evanjs

SaveAsPdf - Syncfusion

Oct 14th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. public async void SaveAsPdf(Stream fs, Manga manga)
  2.         {
  3.             var m = manga;
  4.             var c = m.Content;
  5.  
  6.             if (fs.Length != 0) return;
  7.             var pdf = new PdfDocument();
  8.             var pages = await GetPages(m);
  9.             pdf.PageSettings.SetMargins(0);
  10.  
  11.  
  12.             pdf.FileStructure.IncrementalUpdate = true;
  13.             pdf.EnableMemoryOptimization = true;
  14.             pdf.Compression = PdfCompressionLevel.Best;
  15.  
  16.  
  17.             for (var pi = 0; pi < c.ContentPages; pi++)
  18.             {
  19.                 var section = pdf.Sections.Add();
  20.                 var mr = section.PageSettings.Margins = new PdfMargins();
  21.                 mr.All = 0;
  22.                 var page = section.Pages.Add();
  23.                 var g = page.Graphics;
  24.                 page.DefaultLayerIndex = 0;
  25.                 var pu = pages[pi];
  26.                 var client = new HttpClient();
  27.                 var im = await client.GetAsync(pu);
  28.                 var pdi = PdfImage.FromStream(im.Content.ReadAsStreamAsync().Result);
  29.  
  30.                 g.DrawImage(pdi, new PointF(0, 0), g.ClientSize);
  31.                 await pdf.SaveAsync(fs);
  32.             }
  33.             await pdf.SaveAsync(fs);
  34.             pdf.DocumentInformation.Title = c.ContentName;
  35.             pdf.DocumentInformation.Author += string.Join(", ", c.ContentArtists.Select(x => x.Attribute));
  36.             pdf.DocumentInformation.Keywords += string.Join(", ", c.ContentTags.Select(x => x.Attribute)).Replace("\"", string.Empty);
  37.             pdf.Save(fs);
  38.             pdf.Close(true);
  39.  
  40.             var toast = Notifications.NotifyMangaDownloaded(m);
  41.             ToastNotificationManager.CreateToastNotifier().Show(toast);
  42.             fs.Dispose();
  43.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement