How to convert PDF to XOD in memory.

53 views
Skip to first unread message

Ryan

unread,
May 10, 2019, 6:38:28 PM5/10/19
to PDFTron PDFNet SDK
Question:
We have our source files encrypted. The unencrypted version needs to be in memory only.

How do I generate a XOD from this in memory PDF file?

Answer:
The following code shows how to do in memory PDF to XOD. Note the code below reads and writes to disk, but that is just for testing/demo purposes.

// Debug: load bytes into memory
var pdfBytes = File.ReadAllBytes(pathToPdf);
// disable PDFNet disk caching, so caching is done in memory instead
pdftron
.PDFNet.SetDefaultDiskCachingEnabled(false);
// create in memory PDF
var pdfDocument = new PDFDoc(pdfBytes, pdfBytes.Length);
pdfDocument
.InitSecurityHandler();
// convert to xod
var xodOptions = new pdftron.PDF.Convert.XODOutputOptions();
var filter = pdftron.PDF.Convert.ToXod(pdfDocument, xodOptions);
var filterReader = new FilterReader(filter);
var xodStream = new MemoryStream();
var buffer = new byte[81920];
var returned = filterReader.Read(buffer);
while (returned > 0)
{
    xodStream
.Write(buffer, 0, returned);
    returned
= filterReader.Read(buffer);
}
xodStream
.Seek(0, SeekOrigin.Begin);
// Debug: write to disk
var fs = File.Create(outPutPath);
xodStream
.WriteTo(fs);
xodStream
.Flush();
fs
.Flush();

Reply all
Reply to author
Forward
0 new messages