//this is a tutrila can help you with simple text private async void Button_Click1(object sender, RoutedEventArgs e) { var file = await ApplicationData.Current.LocalFolder.CreateFileAsync("a.pdf", CreationCollisionOption.ReplaceExisting); using (Stream stream = await WindowsRuntimeStorageExtensions.OpenStreamForWriteAsync(file)) { PdfFixedDocument document = new PdfFixedDocument(); PdfPage page = document.Pages.Add(); // Create a standard font with Helvetica face and 24 point size PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 24); // Create a solid RGB red brush. PdfBrush brush = new PdfBrush(PdfRgbColor.Red); // Draw the text on the page. string cha = "title"; page.Graphics.DrawString(cha, helvetica, brush, 250, 50); // Draw the text on the page. max tableau 50 string ch = "azj aeiajiahfioe foiehfioehfiehfie feifjaepfjaepofjaepo fpaejfpeafjaefaefhevpzevje vjepzvihzev zep"; page.Graphics.DrawString(ch, helvetica, brush, 10, 100); document.Save(stream); } await Launcher.LaunchFileAsync(file); //FileStream input = File.OpenRead("optionalcontent-src.pdf"); //PdfFile file = new PdfFile(input); }
//this is a tutrila can help you with paragraph block private async void Button_Click2(object sender, RoutedEventArgs e) { var file = await ApplicationData.Current.LocalFolder.CreateFileAsync("a.pdf", CreationCollisionOption.ReplaceExisting); using (Stream stream = await WindowsRuntimeStorageExtensions.OpenStreamForWriteAsync(file)) { string paragraph2Block1Text = "The development style is based on fixed document model, where each page is created as needed " + "and content is placed at fixed position using a grid based layout.\r\n" + "This gives you access to all PDF features, whether you want to create a simple file " + "or you want to create a transparency knockout group at COS level, and lets you build more complex models on top of the library."; PdfStandardFont textFont = new PdfStandardFont(PdfStandardFontFace.TimesRoman, 12); PdfFormattedParagraph paragraph2 = new PdfFormattedParagraph(); paragraph2.SpacingAfter = 3; paragraph2.FirstLineIndent = 10; paragraph2.HorizontalAlign = PdfStringHorizontalAlign.Justified; paragraph2.LineSpacingMode = PdfFormattedParagraphLineSpacing.Multiple; paragraph2.LineSpacing = 1.2; paragraph2.Blocks.Add(new PdfFormattedTextBlock(paragraph2Block1Text, textFont)); PdfFormattedContent formattedContent = new PdfFormattedContent(); formattedContent.Paragraphs.Add(paragraph2); PdfFixedDocument document = new PdfFixedDocument(); PdfPage page = document.Pages.Add(); page.Graphics.DrawFormattedContent(formattedContent, 50, 50, 500, 700); page.Graphics.CompressAndClose(); document.Save(stream); } await Launcher.LaunchFileAsync(file); }
/// <summary> /// Saves the current play queue to a file. /// </summary> /// <param name="f">the file to save to</param> /// <returns>true if it managed to save OK</returns> public async Task <bool> SavePlayQueue(StorageFile f) { try { List <string> paths = new List <string>(); foreach (PlayableItem play in (Collection <PlayableItem>) this.PlayQueue) { PlayableItem i = play; paths.Add(i.storage.Path); } using (Stream fr1 = await WindowsRuntimeStorageExtensions.OpenStreamForWriteAsync((IStorageFile)f)) { using (StreamWriter tr = new StreamWriter(fr1)) { foreach (string str in paths) { string s = str; tr.WriteLine(s); // the file holds one file path per line } } } return(true); } catch (Exception) { return(false); } }
/// <summary> /// Loads a list of playable items (storage files) from a file, and puts them onto the bottom of the play queue. /// </summary> /// <param name="f">The file to read the items from</param> /// <returns>true if the operation succeeded</returns> public async Task <bool> LoadPlayQueue(StorageFile f) { try { using (Stream fr1 = await WindowsRuntimeStorageExtensions.OpenStreamForReadAsync((IStorageFile)f)) { using (TextReader tr1 = new StreamReader(fr1)) { string path; while ((path = tr1.ReadLine()) != null) // the file holds one file path per line { try { StorageFile trackFile = await StorageFile.GetFileFromPathAsync(path); this.PlayQueue.Add(new PlayableItem(trackFile)); } catch (Exception) { } } } } return(true); } catch (Exception) { return(false); } }
public async Task Load(StorageFile storageFile) { Stream fileStream = await WindowsRuntimeStorageExtensions.OpenStreamForReadAsync(storageFile); var file = TagLib.File.Create(new StreamFileAbstraction(storageFile.Name, fileStream, fileStream)); await ReadTags(file); }
private async Task CompleteTask(int ID, ObservableCollection <Tasks> _Tasks) { if (!_Tasks[ID].Dates.Contains(DateTime.Today)) { _Tasks[ID].Dates.Add(DateTime.Today); } IStorageFile StorageFile = await GetStream(); await SaveTasks(await WindowsRuntimeStorageExtensions.OpenStreamForReadAsync(StorageFile), _Tasks); }
/** * ファイルのダウンロードを開始 */ private void Download() { lock (mLock) { if (null != mDownloadTask) { return; } mFile = null; var client = new HttpClient(); mDownloadTask = client.GetAsync(mUri, HttpCompletionOption.ResponseContentRead); mDownloadTask.Completed += async(info, status) => { lock (mLock) { mDownloadTask = null; } try { switch (status) { case AsyncStatus.Completed: using (var response = info.GetResults()) using (var input = (await response.Content.ReadAsInputStreamAsync()).AsStreamForRead()) using (var output = await WindowsRuntimeStorageExtensions.OpenStreamForWriteAsync(WvvCacheManager.Instance.CacheFolder.Folder, mKey, CreationCollisionOption.ReplaceExisting)) { await input.CopyToAsync(output); output.Flush(); } onDownloadCompleted(await WvvCacheManager.Instance.CacheFolder.Folder.GetFileAsync(mKey)); break; case AsyncStatus.Error: onDownloadError(info.ErrorCode); break; case AsyncStatus.Canceled: default: onDownloadError(new OperationCanceledException("Download operation cancelled.")); break; } } catch (Exception e) { onDownloadError(e); } finally { client.Dispose(); } }; } }
public static Stream GetOutputStream(string path, FileOperationMode mode) { StorageFile file = StorageUtility.GetFile(path, mode); Task <Stream> task = WindowsRuntimeStorageExtensions.OpenStreamForWriteAsync(file); task.Wait(); Stream result = task.Result; if (mode == FileOperationMode.Append) { result.Seek(0L, SeekOrigin.End); } return(result); }
public async Task LoadFileAsync(StorageFile file) { if (file == null) { throw new ArgumentNullException(nameof(file)); } using (var stream = await WindowsRuntimeStorageExtensions.OpenStreamForReadAsync(file)) using (var reader = new StreamReader(stream)) { var xml = new XmlDocument(); xml.LoadXml(reader.ReadToEnd(), new XmlLoadSettings { ProhibitDtd = false }); var svgDocument = SvgDocument.Parse(xml); this.Content = svgDocument; } }
public static async Task BackgroundTask(bool NotifyUser = true) { var StorageFileTasks = await ApplicationData.Current.LocalFolder.GetFileAsync("Tasks.xml"); var IStorageFileTasks = (IStorageFile)StorageFileTasks; var TaskItems = GetTasks(await WindowsRuntimeStorageExtensions.OpenStreamForReadAsync(IStorageFileTasks), 0); int NotifyQueue = 0; ObservableCollection <Tasks> Queue = new ObservableCollection <Tasks>(); foreach (var TaskItem in TaskItems) { bool Notify = false; int CorrectionOfMinuteRange; CorrectionOfMinuteRange = (TaskItem.WhenNotify.Minute - 10 < 0) ? 0 : TaskItem.WhenNotify.Minute - 10; if ((TaskItem.WhenNotify.Hour == DateTime.Now.Hour) && (Enumerable.Range(CorrectionOfMinuteRange, 20).Contains(DateTime.Now.Minute))) { Notify = true; } #region OldVersionCheckHour /* * bool CheckAnotherHour = false; * int Minute = -1; * * if ((TaskItem.WhenNotify.Minute >= 50) || (TaskItem.WhenNotify.Minute <= 10)) * { * Minute = 60 - TaskItem.WhenNotify.Minute; * CheckAnotherHour = true; * } * * if (CheckAnotherHour) * { */ #endregion if (((TaskItem.WhenNotify.Minute >= 50) && (TaskItem.WhenNotify.Hour + 1 == DateTime.Now.Hour) && (Enumerable.Range(0, 60 - TaskItem.WhenNotify.Minute).Contains(DateTime.Now.Minute))) || ((TaskItem.WhenNotify.Minute <= 10) && (TaskItem.WhenNotify.Hour - 1 == DateTime.Now.Hour) && (Enumerable.Range(50, 60 - TaskItem.WhenNotify.Minute).Contains(DateTime.Now.Minute)))) { Notify = true; } if ((!TaskItem.Dates.Contains(DateTime.Today)) && ((TaskItem.End >= DateTime.Today) && (TaskItem.Start <= DateTime.Today)) && Notify && TaskItem.Notify && TaskItem.NotifyDays.Contains(DateTime.Today.DayOfWeek)) { if (NotifyUser) { Notifications.SendNotification(new string[2] { "Uncompleted task", $"Task {TaskItem.Name} isn't completed." }, ToastTemplateType.ToastText02); } if (NotifyQueue <= 5) { NotifyQueue++; Queue.Add(TaskItem); } } } SendLiveTiles(TaskItems, Queue); }
private async Task <ObservableCollection <Tasks> > GetListOfTasks() { IStorageFile IStorageFileTasks = await GetStream(); return(GetTasks(await WindowsRuntimeStorageExtensions.OpenStreamForReadAsync(IStorageFileTasks))); }