Use SaveViewerOptimized to save to a stream/buffer instead of path in C# .net

Product: PDFTron.Net.64
Product Version: 9.4

Please give a brief summary of your issue:
Is there any way to use SaveViewerOptimized to save to a stream/buffer using PDFTron SDK in .Net C# like the method used in node-js SaveViewerOptimizedBuffer? Or are there any workarounds to avoid using the filesystem? The SaveViewerOptimized() method only accepts a file path as output.

Hi Mihai,

Our documentation allows the SaveViewerOptimized to be used to save a to stream or buffer. Please view the documentation below as it describes both the use case for saving to a file path and saving to a buffer:

1 Like

@kmirsalehi Thanks. Can you give me a quick example of how to use it on a doc?
I forgot to mention I’m using .net 6.
I will add a sample code I’m testing on maybe there is something I missed.
I was thinking that it works the same way as the Save method returning a byte[].
Ex: byte[] saveBuf = doc.Save(SDFDoc.SaveOptions.e_linearized);
But in the sample below I only have the void method accessible with 2 parameters : a path and ViewerOptimizedOptions but nothing that returns a byte[] when I try to invoke only with 1 argument the opts.

    using (PDFDoc doc = new PDFDoc(inputStream))
        var optimizerOptions = new ViewerOptimizedOptions();
        // A number from 0 (include all thumbnails) to 100
        // (include only the first thumbnail). The default value is 50.
        // The maximum allowed length for the thumbnail's height/width.
        // The default thumbnail size is 1024.

        byte[] buf = doc.SaveViewerOptimized(optimizerOptions);
        linearizedOutputStream = new MemoryStream(buf);

I found out that in the dotnetcore documentation, I’m using in .net 6, there isn’t option to save to a stream/buffer, only on the filesystem using SaveViewerOptimized().
Is there any other way to avoid using the filesystem? Or are there any plans to implement the option in the future? Thanks