Using the PDFDocument.ToData method to open an unsaved PDF

According to a recent Xojo blog by Javier Menendez, the release of Xojo 2021r1 offers additional support for PDFDocument. The blog indicates that it is now possible to retrieve the full PDF data from the document as a MemoryBlock using the ToData method. Using this method a PDF can be opened without the need to save the PDF document to a file.

The Xojo “PDFDocument.ToData” documentation does not include an example.

I have attempted, without successs, to use the new method:

Var mb As MemoryBlock = MyPDF.ToData
Var f As FolderItem = FolderItem(mb)
f.Open

This code does not work. Does anyone have any ideas?

FolderItem doesn’t accept MemoryBlock in it’s constructor.
https://documentation.xojo.com/api/files/folderitem.html

I see what you’re trying to do, but I don’t think it’s possible in simple Xojo code.

You could write that to a file using binarystream class.

Hi @John_Keidel

The ToData method gives to you the “rendered” document of the PDF, so you can find a way to display it in a web app without saving it before to a file (I still prefer to save it to a file using the PDFDocument.Save method anyway…)