Page 1 of 1

Possible to read a PDF file directly from memory?

Posted: Mon Oct 14, 2024 10:35 pm
by flashbob
Is it possible to read/open PDF-Content directly from memory instead from file ?

I would like to save the pdf file into a database an then load it directly into memory in order to open it with default pdf reader.
At the moment I save the PDF file to a temporary file before opening it with RunProgram(...).

Perhaps the same procedure could also be used to display images...

Thx in advance.

Re: Possible to read a PDF file directly from memory

Posted: Tue Oct 15, 2024 8:28 am
by Fred
If you need an external tool to open your pdf, you need to write it to a file, unless I misunderstood your question.

Re: Possible to read a PDF file directly from memory?

Posted: Tue Oct 15, 2024 10:15 am
by acreis
If you use pdfium to render the document, then you can use:

Code: Select all

                                                                    ;// Function: FPDF_LoadMemDocument
                                                                    ;//          Open and load a PDF document from memory.
                                                                    ;// Parameters:
                                                                    ;//          data_buf    -   Pointer to a buffer containing the PDF document.
                                                                    ;//          size        -   Number of bytes in the PDF document.
                                                                    ;//          password    -   A string used as the password for the PDF file.
                                                                    ;//                          If no password is needed, empty or NULL can be used.
                                                                    ;// Return value:
                                                                    ;//          A handle to the loaded document, or NULL on failure.
                                                                    ;// Comments:
                                                                    ;//          The memory buffer must remain valid when the document is open.
                                                                    ;//          The loaded document can be closed by FPDF_CloseDocument.
                                                                    ;//          If this function fails, you can use FPDF_GetLastError() to retrieve
                                                                    ;//          the reason why it failed.
  Prototype FPDF_LoadMemDocument(*data_buf, size, password.p-unicode);

Re: Possible to read a PDF file directly from memory?

Posted: Wed Oct 16, 2024 8:13 pm
by flashbob
Thanks for the info, but I don't want to use additional libs at the moment...