- Posts: 18
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Windows 8.1, 10, WindowsPhone, Windows UWP
WACK issue
9 years 3 months ago #11549
by kumar88
Replied by kumar88 on topic WACK issue
Thanks for the information, your method is working fine on some pdf docs , often times I need to scroll to see the changes, is there a way to save the changed stream of pdf doc ? , I also tried refreshing canvas & clearing canvas items to redraw but no use, as you said the save method is directly saving the changes to disk .(which I am not looking for)
Thanks.
Thanks.
9 years 3 months ago #11550
by kumar88
Replied by kumar88 on topic WACK issue
Thanks for the information, your method is working fine on some pdf docs , often times I need to scroll to see the changes, is there a way to save the changed stream of pdf doc ? , I also tried refreshing canvas & clearing canvas items to redraw but no use, as you said the save method is directly saving the changes to disk .(which I am not looking for), also could you please tell me is there a way to export a pdf doc to stream (memory stream or something similar) ??
Thanks
Thanks
9 years 3 months ago #11557
by nermeen
Replied by nermeen on topic WACK issue
No, A modification that manipulates the PDF (add page, remove page, move page...) has deep impact on its structure and internal references; to reflect these changes the document must be saved, closed and then reopened..
So it cannot be exported to a stream.
So it cannot be exported to a stream.
9 years 2 months ago #11713
by kumar88
Replied by kumar88 on topic WACK issue
Hi,
i have tried below code to store the stream as file but failed, if there is atleast a work around to save the modified pdf as another file using stream i can't do anything useful , any alternate solution would be greatly appreciated!
m_doc.MovePage(1, 0);
m_doc.Save();
uint buffersize = 4096;
//save
var saver = new Windows.Storage.Pickers.FileSavePicker();
saver.FileTypeChoices.Add("pdf", new List<string>() { ".pdf" });
var file = await saver.PickSaveFileAsync();
var writestream = await file.OpenAsync(FileAccessMode.ReadWrite);
var outputstream = writestream.GetOutputStreamAt(0);
var datawriter = new DataWriter(m_stream);
var buffer = new Windows.Storage.Streams.Buffer(buffersize);
while (m_stream.Position < m_stream.Size)
{
await m_stream.ReadAsync(buffer, buffersize, InputStreamOptions.None);
datawriter.WriteBuffer(buffer);
}
datawriter.StoreAsync().AsTask().Wait();
outputstream.FlushAsync().AsTask().Wait();
outputstream.Dispose();
writestream.Dispose();
i have tried below code to store the stream as file but failed, if there is atleast a work around to save the modified pdf as another file using stream i can't do anything useful , any alternate solution would be greatly appreciated!
m_doc.MovePage(1, 0);
m_doc.Save();
uint buffersize = 4096;
//save
var saver = new Windows.Storage.Pickers.FileSavePicker();
saver.FileTypeChoices.Add("pdf", new List<string>() { ".pdf" });
var file = await saver.PickSaveFileAsync();
var writestream = await file.OpenAsync(FileAccessMode.ReadWrite);
var outputstream = writestream.GetOutputStreamAt(0);
var datawriter = new DataWriter(m_stream);
var buffer = new Windows.Storage.Streams.Buffer(buffersize);
while (m_stream.Position < m_stream.Size)
{
await m_stream.ReadAsync(buffer, buffersize, InputStreamOptions.None);
datawriter.WriteBuffer(buffer);
}
datawriter.StoreAsync().AsTask().Wait();
outputstream.FlushAsync().AsTask().Wait();
outputstream.Dispose();
writestream.Dispose();
9 years 1 month ago - 9 years 1 month ago #11760
by nermeen
Replied by nermeen on topic WACK issue
Sorry for the late reply.
The following code, will save the modified pdf to another file (sample.pdf), you can change the destination file name and path according to your requirements.
The following code, will save the modified pdf to another file (sample.pdf), you can change the destination file name and path according to your requirements.
Code:
doc.MovePage(1, 0);
doc.Save();
doc.Close();
stream.Dispose();
stream = await file.OpenAsync(FileAccessMode.ReadWrite);
using (var inputStream = stream.GetInputStreamAt(0))
{
using (var dataReader = new Windows.Storage.Streams.DataReader(inputStream))
{
uint bytesAvailable = await dataReader.LoadAsync((uint)stream.Size);
byte[] byArray = new byte[bytesAvailable];
dataReader.ReadBytes(byArray);
Windows.Storage.StorageFolder storageFolder =
Windows.Storage.ApplicationData.Current.LocalFolder;
Windows.Storage.StorageFile sampleFile =
await storageFolder.CreateFileAsync("sample.pdf", Windows.Storage.CreationCollisionOption.ReplaceExisting);
var destStream = await sampleFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
using (var outputStream = destStream.GetOutputStreamAt(0))
{
using (var dataWriter = new Windows.Storage.Streams.DataWriter(outputStream))
{
dataWriter.WriteBytes(byArray);
await dataWriter.StoreAsync();
await outputStream.FlushAsync();
}
}
destStream.Dispose();
}
stream.Dispose();
}
Last edit: 9 years 1 month ago by nermeen.
Time to create page: 0.433 seconds