I'm using PB x86 5.44 LTS Windows 10 64bits.
Code: Select all
Global sgPDF.s = "PureBasicSmall.pdf" ;https://www.purebasic.fr/documentation/PureBasicSmall.pdf
Global sgJPG.s = "imagem-005.jpg" ;http://kingofwallpapers.com/imagem/imagem-005.jpg
PrototypeC protoGetBlock(param, position, *buf, size)
Structure FPDF_FILEACCESS
FileLen.i
*GetBlock.protoGetBlock
param.i
file$
file_handle.i
EndStructure
ProcedureC GetBlockCallback(*param.FPDF_FILEACCESS, position, *buf, size)
If *param\file_handle = 0
If FileSize(*param\file$) > 0
*param\file_handle = ReadFile(#PB_Any,*param\file$)
EndIf
EndIf
If *param\file_handle
FileSeek(*param\file_handle, position)
ReadData(*param\file_handle, *buf, size)
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
Procedure Open_FileAccess(file$)
Protected *this.FPDF_FILEACCESS = AllocateStructure(FPDF_FILEACCESS)
*this\FileLen = FileSize(file$)
*this\GetBlock = @GetBlockCallback()
*this\param = *this
*this\file$ = file$
ProcedureReturn *this
EndProcedure
Procedure Close_FileAccess(*this.FPDF_FILEACCESS)
If *this And *this\file_handle
CloseFile(*this\file_handle)
*this\file_handle = 0
EndIf
EndProcedure
Prototype protoInitLibrary()
Prototype protoLoadDocument(documentpath.p-utf8, password.p-utf8)
Prototype protoImageObj_LoadJpegFile(pages, count, imgObject, fileObject)
Prototype protoGetPageCount(document)
Prototype protoRenderPage(hDC, page, start_x, start_y, size_x, size_y, rotate, flags)
Prototype protoLoadPage(document, page_index)
Prototype protoGetMediaBox(page, left, bottom, right, top)
Prototype protoInsertObject(pdfObject, newObject, insertAfter)
Prototype protoCloseDocument(document)
Prototype protoClosePage(page)
Prototype protoPage_InsertObject(page, page_obj)
Prototype protoPageObj_NewImgeObj(document)
Prototype protoImageObj_SetMatrix(page_obj, a.d, b.d, c.d, d.d, e.d, f.d)
Prototype protoPageObj_Transform(page_obj, a.d, b.d, c.d, d.d, e.d, f.d)
Prototype protoPage_GenerateContent(page)
Procedure Main(*win)
CanvasGadget(0, 0, 0, 800, 600)
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 Page_InsertObject.protoPage_InsertObject = GetFunction(pdf_dll,"_FPDFPage_InsertObject@8")
Protected RenderPage.protoRenderPage = GetFunction(pdf_dll,"_FPDF_RenderPage@32")
Protected LoadPage.protoLoadPage = GetFunction(pdf_dll,"_FPDF_LoadPage@8")
Protected GetMediaBox.protoGetMediaBox = GetFunction(pdf_dll,"_FPDFPage_GetMediaBox@20")
Protected CloseDocument.protoCloseDocument = GetFunction(pdf_dll,"_FPDF_CloseDocument@4")
Protected ClosePage.protoClosePage = GetFunction(pdf_dll,"_FPDF_ClosePage@4")
Protected ImageObj_LoadJpegFile.protoImageObj_LoadJpegFile = GetFunction(pdf_dll,"_FPDFImageObj_LoadJpegFile@16")
Protected PageObj_NewImgeObj.protoPageObj_NewImgeObj = GetFunction(pdf_dll,"_FPDFPageObj_NewImgeObj@4")
Protected ImageObj_SetMatrix.protoImageObj_SetMatrix = GetFunction(pdf_dll,"_FPDFImageObj_SetMatrix@52")
Protected PageObj_Transform.protoPageObj_Transform = GetFunction(pdf_dll,"_FPDFPageObj_Transform@52")
Protected Page_GenerateContent.protoPage_GenerateContent = GetFunction(pdf_dll,"_FPDFPage_GenerateContent@4")
InitLibrary()
Protected Dim pdf_pages(3)
Protected *jpg_read.FPDF_FILEACCESS = Open_FileAccess(sgJPG)
Protected pdf_doc = LoadDocument(sgPDF, "")
Protected i
For i = 0 To 2
pdf_pages(i) = LoadPage(pdf_doc, i)
Protected img_obj = PageObj_NewImgeObj(pdf_doc)
ImageObj_LoadJpegFile(@pdf_pages(0), i+1, img_obj, *jpg_read)
PageObj_Transform(img_obj, 500,0,0,500,0,0)
Page_InsertObject(pdf_pages(i), img_obj)
Page_GenerateContent(pdf_pages(i))
Next
Protected hDC = StartDrawing(CanvasOutput(0))
RenderPage(hDC, pdf_pages(2), 0, 0, 800, 600, 0, $100);
StopDrawing()
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
For i= 0 To 2
ClosePage(pdf_pages(i))
Next
CloseDocument(pdf_doc)
CloseLibrary(pdf_dll)
EndProcedure
Define iFlags.i = #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_SizeGadget
Main(OpenWindow(#PB_Any, 0, 0, 800, 600, "Pdfium", iFlags))