Page 1 of 4
How to get Pdfium to work (done)
Posted: Sun May 22, 2016 4:42 pm
by Hadrianus
See also this topic in general discussion (
http://www.purebasic.fr/english/viewtop ... =7&t=65733).
Due to lack of help-files I use information from
https://pdfium.patagames.com/help/html/ ... 3d257a.htm. Patagames use this library too, for their .net application. Only their pdfium.dll is different than the free one I downloaded from:
https://github.com/pvginkel/PdfiumViewer
I tried this:
Code: Select all
Enumeration
#PDFlib
EndEnumeration
Prototype InitLibrary(licencekey.s,path.s)
Prototype LoadDocuments(documentpath.s,password.s)
Prototype GetPageCounts(HandleToDocument.i)
If OpenLibrary(#PDFlib,"pdfium.dll")
ExamineLibraryFunctions(#PDFlib)
Debug IsLibrary(#PDFlib) ; Just for testing. Value should be above zero.
Debug LibraryID(#PDFlib) ; Just for testing. Value should be above zero.
Debug CountLibraryFunctions(#PDFlib)
For i = 1 To CountLibraryFunctions(#PDFlib)
Debug i
NextLibraryFunction()
Debug LibraryFunctionName()
Next
Debug GetFunctionEntry(#PDFlib,128) ; Just for testing. Value should be above zero.
Debug GetFunction(#PDFlib,"_FPDF_InitLibrary@0") ; Just for testing. Value should be above zero.
Debug GetFunctionEntry(#PDFlib,131) ; Just for testing. Value should be above zero.
Debug GetFunction(#PDFlib,"_FPDF_LoadDocument@8") ; Just for testing. Value should be above zero.
Debug GetFunctionEntry(#PDFlib,122) ; Just for testing. Value should be above zero.
Debug GetFunction(#PDFlib,"_FPDF_GetPageCount@4") ; Just for testing. Value should be above zero.
Init.InitLibrary = GetFunction(#PDFlib,"_FPDF_InitLibrary@0") ; Call this function first before all other functions.
Debug Init("",GetCurrentDirectory()+"pdfium.dll")
LoadDocument.LoadDocuments = GetFunction(#PDFlib,"_FPDF_LoadDocument@8")
Handle.i = LoadDocument(GetCurrentDirectory()+"name_of_document.pdf","")
Debug Handle
GetPageCount.GetPageCounts = GetFunction(#PDFlib,"_FPDF_GetPageCount@4")
Debug GetPageCount(Handle)
CloseLibrary(#PDFlib)
EndIf
Everything according to PB-manual, but no success. Perhaps an expert can have a look.
Re: How to get Pdfium to work
Posted: Sun May 22, 2016 6:15 pm
by acreis
This worked here:
Code: Select all
Prototype protoInitLibrary()
Prototype protoLoadDocument(documentpath.p-utf8,password.p-utf8)
Prototype protoGetPageCount(HandleToDocument.i)
Procedure Main()
Protected pdfdll =OpenLibrary(#PB_Any, "pdfium.dll")
Debug pdfdll
Protected InitLibrary.protoInitLibrary = GetFunction(pdfdll,"_FPDF_InitLibrary@0")
Protected GetPageCount.protoGetPageCount = GetFunction(pdfdll,"_FPDF_GetPageCount@4")
Protected LoadDocument.protoLoadDocument = GetFunction(pdfdll,"_FPDF_LoadDocument@8")
InitLibrary()
Protected pdf = LoadDocument("mypdf2.pdf", "")
Debug GetPageCount(pdf)
CloseLibrary(pdfdll)
EndProcedure
Main()
Re: How to get Pdfium to work
Posted: Sun May 22, 2016 6:48 pm
by acreis
This works too ...
Code: Select all
Prototype protoInitLibrary()
Prototype protoLoadDocument(documentpath.p-utf8,password.p-utf8)
Prototype protoGetPageCount(document)
Prototype protoRenderPage(hDC, page, start_x, start_y, size_x, size_y, rotate, flags);As "_FPDF_RenderPage@32
Prototype protoLoadPage(document, page_index) ;"_FPDF_LoadPage@8"
Procedure Main(*win)
Protected pdf_dll =OpenLibrary(#PB_Any, "pdfium.dll")
Protected InitLibrary.protoInitLibrary = GetFunction(pdf_dll,"_FPDF_InitLibrary@0")
Protected GetPageCount.protoGetPageCount = GetFunction(pdf_dll,"_FPDF_GetPageCount@4")
Protected LoadDocument.protoLoadDocument = GetFunction(pdf_dll,"_FPDF_LoadDocument@8")
Protected RenderPage.protoRenderPage = GetFunction(pdf_dll,"_FPDF_RenderPage@32")
Protected LoadPage.protoLoadPage = GetFunction(pdf_dll,"_FPDF_LoadPage@8")
InitLibrary()
Protected pdf_doc = LoadDocument("mypdf2.pdf", "")
Protected pdf_page = LoadPage(pdf_doc, 0)
RenderPage(GetDC_(WindowID(*win)), pdf_page, 0, 0, WindowWidth(*win), WindowHeight(*win), 0, $100);
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
CloseLibrary(pdf_dll)
EndProcedure
Main(OpenWindow(#PB_Any, 0, 0, 800, 640, "Pdfium", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget))
Re: How to get Pdfium to work
Posted: Sun May 22, 2016 7:40 pm
by Hadrianus
Thanks a lot Acreis.
I guess my biggest mistake is not putting p-utf8 in documentpath (althrough I do not understand why it's necessary) and I did not use InitLibrary() as it should. Are you familiar with Pdfium and all the function-arguments?
I can continue my research now.
Re: How to get Pdfium to work
Posted: Sun May 22, 2016 9:29 pm
by acreis
Hi Hadrianus,
I'm very interested in pdf rendering, bud I don't know anything about pdfium.
I have done just some guesses.
Re: How to get Pdfium to work
Posted: Sun May 22, 2016 11:27 pm
by IdeasVacuum
Certainly sounds interesting because it appears not to be using Ghost and it is covered by the very generous Apache Licenses v2.0. The file management looks a bit complicated.
Re: How to get Pdfium to work
Posted: Sat Jun 04, 2016 2:38 am
by Mohawk70
acreis wrote:This works too ...
Code: Select all
Prototype protoInitLibrary()
Prototype protoLoadDocument(documentpath.p-utf8,password.p-utf8)
Prototype protoGetPageCount(document)
Prototype protoRenderPage(hDC, page, start_x, start_y, size_x, size_y, rotate, flags);As "_FPDF_RenderPage@32
Prototype protoLoadPage(document, page_index) ;"_FPDF_LoadPage@8"
Procedure Main(*win)
Protected pdf_dll =OpenLibrary(#PB_Any, "pdfium.dll")
Protected InitLibrary.protoInitLibrary = GetFunction(pdf_dll,"_FPDF_InitLibrary@0")
Protected GetPageCount.protoGetPageCount = GetFunction(pdf_dll,"_FPDF_GetPageCount@4")
Protected LoadDocument.protoLoadDocument = GetFunction(pdf_dll,"_FPDF_LoadDocument@8")
Protected RenderPage.protoRenderPage = GetFunction(pdf_dll,"_FPDF_RenderPage@32")
Protected LoadPage.protoLoadPage = GetFunction(pdf_dll,"_FPDF_LoadPage@8")
InitLibrary()
Protected pdf_doc = LoadDocument("mypdf2.pdf", "")
Protected pdf_page = LoadPage(pdf_doc, 0)
RenderPage(GetDC_(WindowID(*win)), pdf_page, 0, 0, WindowWidth(*win), WindowHeight(*win), 0, $100);
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
CloseLibrary(pdf_dll)
EndProcedure
Main(OpenWindow(#PB_Any, 0, 0, 800, 640, "Pdfium", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget))
I downloaded from
https://github.com/pvginkel/PdfiumViewer ( both 32 and 64 bit versions) and it doesn't work using either version of your code , with either dll. I get an error message stating ...
H:\DEV\pb\542\64\PDFium\x64\pdfium.dll is either not designed to run on Windows or it contains an error. Try installing the program againusing the original installation media or contact your system administrator or the software vendor for support. The only parts of your code I have modified is using the full path to the DLL and the pdf file I'm attempting to view. Nothing is wrong with the pdf as I can view it with all other viewers. Can you post the version of the dll you have somewhere that I can download it? I am using Win 7 64 , PB 5.42 64 and tried with both the 32 and 64 bit versions of the dll.
Re: How to get Pdfium to work
Posted: Sat Jun 04, 2016 10:32 pm
by acreis
I downloaded it some minutes ago and it's working
The path is
Code: Select all
\PdfiumViewer-master\Libraries\Pdfium\x86\pdfium.dll
Re: How to get Pdfium to work
Posted: Sat Jun 04, 2016 11:43 pm
by Hadrianus
I confirm it's working just fine. This library is no problem for PB !
Re: How to get Pdfium to work
Posted: Thu Jun 09, 2016 3:46 pm
by IdeasVacuum
Where are you getting the function parameters from? I'm particularly interested in these:
Code: Select all
Prototype protoGetFirstPageNum()
Prototype protoGetRotation()
Prototype protoGetText()
Prototype protoGetPageHeight()
Prototype protoGetPageWidth()
Protected GetFirstPageNum.protoGetFirstPageNum = GetFunction(pdf_dll, "_FPDFAvail_GetFirstPageNum@4")
Protected GetRotation.protoGetRotation = GetFunction(pdf_dll, "_FPDFPage_GetRotation@4")
Protected GetText.protoGetText = GetFunction(pdf_dll, "_FPDFText_GetText@16")
Protected GetPageHeight.protoGetPageHeight = GetFunction(pdf_dll, "_FPDF_GetPageHeight@4")
Protected GetPageWidth.protoGetPageWidth = GetFunction(pdf_dll, "_FPDF_GetPageWidth@4")
Re: How to get Pdfium to work
Posted: Thu Jun 09, 2016 10:19 pm
by Hadrianus
I get them from:
https://pdfium.patagames.com/help/html/ ... 3d257a.htm
Be aware that their commercial dll seems to be bigger than the free one from
https://github.com/pvginkel/PdfiumViewer
This free dll, made from open source google/foxit with Apache2 license, has less functions inside, but still enough in order to make something nice.
By the way: if you want to do something with zooming and moving the pdf, you need the function GetMediaBox and not GetPageWidth and GetPageHeight.
Re: How to get Pdfium to work
Posted: Thu Jun 09, 2016 10:54 pm
by IdeasVacuum
Thanks Hadrianus. I wasn't thinking of zooming the page (though no doubt useful), but to render it onto a canvas instead of the client area of the window. The canvas is on a ScrollAreaGadget(). No luck so far but that is because I don't know what I'm doing:
Code: Select all
Procedure PfPdfPage(iGadget, iPageNum.i)
;#--------------------------------------
Protected pdf_page = LoadPage(igPdfDoc, iPageNum)
Protected dc = CreateCompatibleDC_(GadgetID(iGadget))
RenderPage(dc, pdf_page, 0, 0, igWpix, igHpix, 0, $100)
EndProcedure
Re: How to get Pdfium to work
Posted: Thu Jun 09, 2016 11:37 pm
by acreis
Hi Ideas
Please post a minimum working or not working program so we can help you with little effort.
Re: How to get Pdfium to work
Posted: Fri Jun 10, 2016 1:38 pm
by IdeasVacuum
Hello acreis
I put a snippet there but since I do not know how to retrieve a handle to a device context for a CanvasGadget, any amount of sample code from me will not make matters better
I tried
Code: Select all
dc = CreateCompatibleDC_(GadgetID(#MyCanvas))
I have also tried other examples on the forum, but they are not really similar to this requirement.
Re: How to get Pdfium to work
Posted: Fri Jun 10, 2016 4:23 pm
by acreis
Hi Ideas,
I'll try investigate the issue as soon as possible.
The smallest compilable non working code would help.
Please try
Code: Select all
hdc = StartDrawing(CanvasOutput(#canvas))