2014-10-30 3 views
0

Windows 8.1 용 Windows Store 응용 프로그램에서 작업 중이며 필요한 작업을 찾을 수 없습니다. 내 로컬 앱 데이터 저장소에 pdf 페이지의 이미지를 저장하려고합니다.PDF 파일로 저장

private async void GetFirstPage() 
    { 
     // Retrieve file from FutureAccessList 
     StorageFile file = await Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFileAsync(token); 

     // Truncate last 4 chars; ex: '.pdf' 
     FileName = file.Name.Substring(0, file.Name.Length - 4); 

     // Get access to pdf functionality from file 
     PdfDocument doc = await PdfDocument.LoadFromFileAsync(file); 

     // Get a copy of the first page 
     PdfPage page = doc.GetPage(0); 

     // Below could be used to tweak render options for optimizations later 
     //PdfPageRenderOptions options = new PdfPageRenderOptions(); 

     // Render the first page to the BitmapImage 
     InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream(); 
     await page.RenderToStreamAsync(stream); 

     // Common code 
     Cover.SetSource(stream); 

     // Convert the active BitmapImage Cover to a storage file to be stored locally 
     // ??? 

    } 

변수, 커버, 사용자에게 이미지를 표시하기 위해 XAML에서 바인딩 된 BitmapImage이다 : 나는 다음 있습니다. 이 이미지를 내 로컬 응용 프로그램 데이터에 저장하여 응용 프로그램이 열릴 때마다 PDF 라이브러리를 통해 다시 렌더링 할 필요가 없습니다! 문제는 내 지식 (Windows 용 파일 스트림 또는 파일 출력 스트림이 아님)에 텍스트가 아닌 한 스트림에서 Windows Store 앱에 저장할 수 없다는 것과 스트림의 소스 였기 때문에 Cover의 URI 소스가 null이라는 것입니다. 적절한 Windows Store 저장을 위해 Storage File에 BitmapImage, Cover를 가져 오는 것이 어렵습니다.

모든 것이 현재 저에게 효과적입니다. 저는 앱이 열릴 때마다 처음부터 pdf 페이지를 내 bitmap 이미지로 다시 렌더링하는 것에 대해 화가났습니다. 모든 입력에 미리 감사드립니다!

답변

0

BitmapImage에서 데이터를 가져올 수 없기 때문에 이미지를 PdmapPage에서 직접 저장하지 말고 BitmapImage에서 저장해야합니다. PdfPage.RenderToStreamAsync는 스트림을 비트 맵으로 이미 인코딩하므로 파일로 전송하는 것 이상으로 조작 할 필요가 없습니다. 이는 파일 기반 스트림을 제외하고 InMemoryRandomAccessStream에 저장하려는 작업과 본질적으로 동일합니다.

//We need a StorageFile to save into. 
StorageFile saveFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("safedPdf.png",CreationCollisionOption.GenerateUniqueName); 

using (var saveStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite)) 
{ 
    await page.RenderToStreamAsync(saveStream); 
} 
+0

이것은 매력적으로 작용했으며 현재 실제로 의미가 있습니다! 나는 치밀해야합니다.><정말 고마워요. :) – Proto