Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Windows 8.1, 10, WindowsPhone, Windows UWP

TOPIC:

WACK issue 7 years 4 months ago #11549

  • kumar88
  • kumar88's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 18
  • Thank you received: 0
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.

Please Log in or Create an account to join the conversation.

WACK issue 7 years 4 months ago #11550

  • kumar88
  • kumar88's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 18
  • Thank you received: 0
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

Please Log in or Create an account to join the conversation.

WACK issue 7 years 4 months ago #11557

  • nermeen
  • nermeen's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 962
  • Thank you received: 87
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.

Please Log in or Create an account to join the conversation.

WACK issue 7 years 3 months ago #11713

  • kumar88
  • kumar88's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 18
  • Thank you received: 0
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();

Please Log in or Create an account to join the conversation.

WACK issue 7 years 2 months ago #11760

  • nermeen
  • nermeen's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 962
  • Thank you received: 87
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.
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();
 }

Please Log in or Create an account to join the conversation.

Last edit: by nermeen.

WACK issue 7 years 2 months ago #11761

  • kumar88
  • kumar88's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 18
  • Thank you received: 0
Thanks for the information,
i shall try this snippet & let you know the result.

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum