Page 2 of 2 FirstFirst 12
Results 41 to 66 of 66

Thread: PDF Reader ActiveX Control

  1. #41

    Thread Starter
    Lively Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    106

    Re: PDF Reader ActiveX Control

    Quote Originally Posted by KFrosty View Post
    can't make an executable file out of it. Says the .vbp is not a compatible binary file. Anyone else have this problem ?
    This issue occurs because the ocx has not been compiled and the interpreted test project is only linked to the uncompiled component.

    To fix this:


    • Load the PDFReader.vbg project group, close all code and design Windows
    • Compile the OrdoPDFReader ocx for the first time
    • Then modify the PDF_Reader project properties: Component tab: Version Compatibility: Binary Compatibility: Choose OrdoPDFReader.ocx
    • Compile OrdoPDFReader.ocx again for a 2nd time
    • SAVE the project group
    • Quit VB6 and restart it, load the PDFReader.vbg project group
    • It should be possible to compile the TestPDFReader Test project!


    I hope this will solve your problem
    Best Regards
    François

  2. #42
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,045

    Re: PDF Reader ActiveX Control

    Microsoft has plans to scrap the Windows 7 operating system. In conjunction with Intel, the new CPU does not offer Win7 graphics drivers.
    In terms of software and many other aspects, we should actively shut down many excellent software projects or operating systems.
    It's like every time the Apple system is updated or forced to push. It is hoped that the old users will feel that the mobile phone is very slow, and then they have to buy a new mobile phone.
    There is a programmer in China who can even recompile the XP ie source code into a very small single DLL file.
    Just like the tool you use to display PDF pages.
    In the past, a web browser kernel was only 3 to 10 MB in size, but now new browsers have reached 500 MB-1gb

    Lots of great open source UI components or something like libcurl, lIBMysql. DLL.
    Because of the incompatibility of various systems, there may be fewer functions or abnormal operation.

    So we also need a good package manager. There are also a large number of various third-party component DLLs.
    It needs to show compatibility with various operating systems.
    Perhaps this requires that twinbasic provide the server and technology. Realize NPM. Exe and nuget. Exe for VB6 users.
    Last edited by xiaoyao; Oct 8th, 2024 at 08:57 AM.

  3. #43
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,764

    Re: PDF Reader ActiveX Control

    This is not really a thread about different OS. If people want to stick with older operating systems, that is up to them, but they do get to contend with the consequences of doing so. That's also up to them, and a good topic for a different thread.
    My usual boring signature: Nothing

  4. #44

    Thread Starter
    Lively Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    106

    Re: PDF Reader ActiveX Control

    @Xiaoyao

    Your off-topic posts that are polluting the discussion threads are becoming unbearable!
    You're completely discrediting yourself, and like many others, I've come to ignore all of your contributions (I was forced to read this one since I started this thread!)

    Our moderators are very kind and magnanimous!
    Please follow their advice and create new threads when an idea comes to mind.

  5. #45
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,045

    Re: PDF Reader ActiveX Control

    sorry A little off topic.
    I hope that some source codes developed can indicate whether they support 64-bit VBA/TWINBASC,32 and 32-bit systems, and whether they support XP, Win 10 and Win 11.
    It would be better if 64-bit and 32-bit DLLs could be provided at the same time. For example, the COM static editing package of SQLIT3 is only available in 32-bit version at present.

  6. #46
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,045

    Re: PDF Reader ActiveX Control

    Quote Originally Posted by Nouyana View Post
    Thank you, saturnian!
    So I need someone who can rebuild the project and remove the dependencies on "ieshims.dll" and "wer.dll". It seems too complicated task for me.

    ieshims.dll is an artefact of Vista/7 where a shim DLL is used to proxy certain calls (such as CreateProcess) to handle protected mode IE, which doesn't exist on XP, so it is unnecessary. wer.dll is related to Windows Error Reporting and again is probably unused on Windows XP which has a slightly different error reporting system than Vista and above.
    VeryPDF PDFView OCX v2.1.0.1

    http://www.verydoc.com/pdf-viewer-ocx.html

    VeryDOC PDF Viewer OCX Control (ActiveX) is a PDF file viewer component. PDF Viewer OCX Control provides a standalone embeddable PDF Viewer for windows application developers. Using Visual Basic, VC, Delphi, C#, HTML (Internet Explorer) or any other programming languages or tools been able to handle ActiveX controls, developers can build a customer interface for viewing PDF documents. PDF documents can be loaded from disk files easily. PDF Viewer OCX Control is usually used to quickly display PDF files created by any PDF creation software. If you need to embed a PDF viewer into your application without depend on Adobe Reader, VeryDOC PDF Viewer OCX control will be your best choice.

    Features:
    View PDF Documents quickly, without depend on Adobe Reader
    Provide the developer with full control over the PDF viewer, you can add PDF viewing capability to your applications easily
    Search a PDF document for a specific text
    Jump to an outline object destination
    Display document outlines
    Scroll/Zoom the viewer window (Actual Page, Fit Page, Fit Width, ..)
    View PDF pages in different layout modes (Single Page, Facing, Continuous, Continuous Facing)
    Select text on the PDF pages, copy text to clipboard
    Support for PDF hyperlinks
    Region highlighting for text search
    Work with Visual Basic, Delphi, Internet Explorer, and any other ActiveX-compatible development environment
    Support all version of Acrobat PDF files
    Support 2000/XP/Vista, 32bit and 64bit, Windows platforms

  7. #47
    Addicted Member
    Join Date
    May 2022
    Posts
    137

    Re: PDF Reader ActiveX Control

    @saturnian, do you think it's so complicated to create a Merge/ split pdf function ?

    i'm trying to do it but.. :-(

    Edit: and.. updating to a new pdfium.dll (https://github.com/bblanchon/pdfium-binaries/releases) will be hard to do i think, isn't it ?
    Last edited by Calcu; Dec 6th, 2024 at 01:49 PM.

  8. #48

    Thread Starter
    Lively Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    106

    Re: PDF Reader ActiveX Control

    Quote Originally Posted by Calcu View Post
    @saturnian, do you think it's so complicated to create a Merge/ split pdf function ?

    i'm trying to do it but.. :-(

    Edit: and.. updating to a new pdfium.dll (https://github.com/bblanchon/pdfium-binaries/releases) will be hard to do i think, isn't it ?
    I will try to take a look at this as soon as I have a free moment.

  9. #49
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,856

    Re: PDF Reader ActiveX Control

    Quote Originally Posted by Calcu View Post
    @saturnian, do you think it's so complicated to create a Merge/ split pdf function ?

    i'm trying to do it but.. :-(

    Edit: and.. updating to a new pdfium.dll (https://github.com/bblanchon/pdfium-binaries/releases) will be hard to do i think, isn't it ?
    I made such a program in twinBASIC. The most recent version uses newer bblanchon pdfium builds; then if you get the old version it uses the 8 year old outdated pvginkel builds which the only advantage is using stdcall, however to do this in VB6 instead you'd need The trick's VBCdeclFix anyway even with the older pdfium builds because the write callback must be CDecl. All the more reason to just use tB ...or at very least the new pdfium builds since you can't avoid _cdecl if you're going to use the FPDF_SaveAsCopy function.


    [twinBASIC] gPdfMerge - A GUI-based PDF merger

    https://github.com/fafalone/gPdfMerge

    As mentioned, the first version of the project, which doesn't have the search for pages function and a couple other enhancements, uses the same pvginkel builds as this project: https://github.com/fafalone/gPdfMerg...a3a92fea52361f

    --

    I've been meaning to port saturnian's wonderful project here to tB/64bit too but haven't had time yet.
    Last edited by fafalone; Dec 7th, 2024 at 12:29 PM.

  10. #50
    Addicted Member
    Join Date
    May 2022
    Posts
    137

    Re: PDF Reader ActiveX Control

    I tried to do by myself, but my knowlegde is not enough.

    I didn't knew about trick's VBCdeclFix, let's see if i can implement it.

    I will take a look at twinbasic too, just downloaded it and executed... seems pretty "VB6" to me xD, i hope the learning curve will be easy for me

  11. #51
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,856

    Re: PDF Reader ActiveX Control

    twinBASIC is meant to be fully backwards compatible with VB6. Essentially a real VB7. That's why I answer with code from it or links to projects for it; it's the same language, and usually backporting to VB6 when new features are used is very simple .

    VBCDeclFix is an addin for VB6 that lets you use CDecl in API declares and functions. All you have to do is enable it and then you can use the CDecl keyword in VB6, e.g. Private Declare Function FPDF_SaveAsCopy CDecl Lib "pdfium" ... and Private Function WriteBlock CDecl(.... In twinBASIC no addin is needed; that's supported natively with the same syntax.

  12. #52
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,856

    Re: PDF Reader ActiveX Control

    Hey so I've been working on a 64-bit compatible twinBASIC port, which also uses the newer pdfium builds from https://github.com/bblanchon/pdfium-binaries/releases

    I'm actually having a bit of trouble getting the VB6 version to work for comparison; I was wondering if someone could provide some feedback about glitches so I know if they're tB bugs or general rendering bugs...

    https://github.com/fafalone/OrdoPdfReader64


    The test project ports in the win32 and win64 folders will need to remove the old control/reference and re-place it if you use them; I set everything to be an entirely new control before posting (this means it won't interfere with the original if you have it).

  13. #53

    Thread Starter
    Lively Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    106

    Re: PDF Reader ActiveX Control

    I made a new version of PDF Reader that uses the new compilations of Pdfium by Benoit Blanchon.
    This version includes the improvement of the printing of post 29 and the display by bitblt proposed by jtw400 post 35
    For this to work, it is imperative to load in the VB6 IDE the complement of "The Trick" VBCdeclFix
    The source is downloadable here

    I will try to take the example of Fafalone's TwinBasic gPdfMerge code to integrate a MergePDF function.
    I need to install TwinBasic to try to understand the problems that Fafalone encounters during his porting test.

    Best wishes to all!
    François

    NB: The first post has been updated with these new features.
    Last edited by saturnian; Dec 20th, 2024 at 08:11 AM.

  14. #54
    Addicted Member
    Join Date
    May 2022
    Posts
    137

    Re: PDF Reader ActiveX Control

    Thanks both
    i will try to use the new version and try to beta-test the fafalone version ! (this way i will begin with TB)

  15. #55
    New Member
    Join Date
    Mar 2025
    Posts
    1

    Re: PDF Reader ActiveX Control

    Hi everyone! This PDF project is really great, and when I integrated into my own program, it basically works well... except for one thing. The PrintPDFWithDialog function brings up the print dialog, I select the printer and then press "Print" but nothing happens. What could be the reason for this? The regular PrintPDF prints just fine.

    Another question/idea: Would it be possible to add options for duplex printing and color/b&w selection to the PrintPDF function?

    And one more thing: The PrintPDFWithDialog function mentioned above is not documented in the Help section here: https://freeware.ordoconcept.net/help/OrdoPDFReader3/

  16. #56

    Thread Starter
    Lively Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    106

    Re: PDF Reader ActiveX Control

    Quote Originally Posted by DTZlevelei View Post
    Hi everyone! This PDF project is really great, and when I integrated into my own program, it basically works well... except for one thing. The PrintPDFWithDialog function brings up the print dialog, I select the printer and then press "Print" but nothing happens. What could be the reason for this? The regular PrintPDF prints just fine.
    I can't reproduce this issue on Windows 10. What printer do you select and on what OS? What version of OrdoPDFReader are you using?

    Another question/idea: Would it be possible to add options for duplex printing and color/b&w selection to the PrintPDF function?
    In the next version a PrintPDFEx method will allow you to select duplex mode and monochrome or color printing in addition to the already available settings

    Best regards
    François

  17. #57
    Addicted Member
    Join Date
    May 2022
    Posts
    137

    Re: PDF Reader ActiveX Control

    Hi!
    Found some time finally to test the new version, i couldn't compile it, and neither execute it.

    Then i created a new project from scratch, added your usercontrol, all the classes and bas modules and it worked like a charm. I compiled this project and worked too.

    BUT

    i tried to use the new usercontrol in my big project (the one that was using your previous version) and .... in IDE it works perfect, but when i compile it, it fails doing FPDF_InitLibrary

    any idea why it works in a new project, but no in an old one (that was using your last version of the usercontrol) ?

    Thanks for everything!


    Ah.. is this a mistake? i can see:

    Private Declare Sub FPDF_DestroyLibary CDecl Lib "pdfium.dll" ()

    Maybe it has to be FPDP_DestroyLibRary ?
    Last edited by Calcu; Mar 6th, 2025 at 11:31 AM.

  18. #58

    Thread Starter
    Lively Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    106

    Re: PDF Reader ActiveX Control

    Quote Originally Posted by Calcu View Post
    Hi!
    Found some time finally to test the new version, i couldn't compile it, and neither execute it.

    Then i created a new project from scratch, added your usercontrol, all the classes and bas modules and it worked like a charm. I compiled this project and worked too.

    BUT

    i tried to use the new usercontrol in my big project (the one that was using your previous version) and .... in IDE it works perfect, but when i compile it, it fails doing FPDF_InitLibrary

    any idea why it works in a new project, but no in an old one (that was using your last version of the usercontrol) ?

    Thanks for everything!
    Hi Calcu,
    Are you sure which version of pdfium.dll you are loading in your old updated project? To avoid confusion I renamed the new dlll Pdfium_X86.dll, which allows you to have both versions on the same system without any risk of confusion.
    Is the VB6 CDeclFix add-in from The Trick active in your IDE when you use the code of the new version?

    Ah.. is this a mistake? i can see:

    Private Declare Sub FPDF_DestroyLibary CDecl Lib "pdfium.dll" ()

    Maybe it has to be FPDP_DestroyLibRary ?
    That's a typo, indeed.

    Best regards
    François

  19. #59
    Addicted Member
    Join Date
    May 2022
    Posts
    137

    Re: PDF Reader ActiveX Control

    Hi!

    Tried everything and found the problem/solution!

    I was compiling to P-Code, just changed to Native code, optimized to fast code, and now it works !

    It was a nonsense if it was working on IDE, but not compiled...

    Waiting for your merge function xD

  20. #60
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,856

    Re: PDF Reader ActiveX Control

    I've posted an updated x64 compatible tB version with the new changes merged in. The BitBlt rendering got rid of the glitches I noticed last time, but consider this a BETA for testing only while I try to figure out an issue I'm having with MouseDown; it's making Windows UI freak out; causing flashing/redrawing of all windows while the mouse lags. Unknown if the VB6 version does this to and it's a me issue, but I won't get a chance to investigate til tomorrow and wanted to go ahead and post it.

    https://github.com/fafalone/OrdoPdfReader64

    OrdoPDFReader64v2.twinproj

    NOTE: It's configured to compile as an entirely separate control; it doesn't interfere with the VB6 version or my previous tB version. If you want to change this behavior, you'll have to put back the project and class names, project guid, typelib version, and class id/interface id/event interface id to the old one. I left the old file up.

  21. #61

    Thread Starter
    Lively Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    106

    Re: PDF Reader ActiveX Control

    Quote Originally Posted by Calcu View Post
    ...
    Waiting for your merge function xD
    Hi,
    Just ask !
    Using Pdfium.dll to merge PDF files is not possible in VB6, as Fafalone stated.
    However, I was largely inspired by Fafalone's TwinBasic code to create a 32-bit ActiveX DLL in TwinBasic, which can be referenced in VB6 and adds a function to merge PDF files.
    You can find this DLL here: https://freeware.ordoconcept.net/dow...oPDFsMerge.zip

    Best regards,
    François

  22. #62
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,856

    Re: PDF Reader ActiveX Control

    Quote Originally Posted by saturnian View Post
    Hi,
    Just ask !
    Using Pdfium.dll to merge PDF files is not possible in VB6, as Fafalone stated.
    However, I was largely inspired by Fafalone's TwinBasic code to create a 32-bit ActiveX DLL in TwinBasic, which can be referenced in VB6 and adds a function to merge PDF files.
    You can find this DLL here: https://freeware.ordoconcept.net/dow...oPDFsMerge.zip


    Best regards,
    François
    It's possible in VB6 with The trick's VBCDeclFix addin; his addin also allows creating the required CDecl callback function, you just add the CDecl keyword like the tB version, and change the Return syntax:
    Code:
    Private Function WriteBlock CDecl(ByVal pThis As LongPtr, ByVal pData As LongPtr, ByVal size As Long) As Long
            If hFileOut Then
                Dim cbRet As Long
                WriteBlock = WriteFile(hFileOut, ByVal pData, size, cbRet, vbNullPtr)
            End If
        End Function
    Last edited by fafalone; Mar 7th, 2025 at 03:02 PM.

  23. #63
    Addicted Member
    Join Date
    May 2022
    Posts
    137

    Re: PDF Reader ActiveX Control

    HI all, i tried to implement the function merge in Vb6, but it's not working fine :-(

    I put the code here just to see if someone (@saturnian xD) can help me, and implement it in this magnific usercontrol.

    I call it this way:

    Code:
     Dim TT(1) As String
     Dim sMergePages(1) As String
        
        TT(0) = "c:\temp\Tarifa_080103030.pdf"
        TT(1) = "c:\temp\63.pdf"
         
        ' Asumimos que queremos fusionar todas las páginas de los PDFs
        sMergePages(0) = ""
        sMergePages(1) = ""
    
        PDFReader1.MergePdfs "C:\temp\prueba5.pdf", TT, sMergePages

    Inside your usercontrol, I declared this:
    Code:
    Private Type FPDF_FILEWRITE
        version As Long
        WriteBlock As Long ' Almacena el puntero a la función callback
    End Type
    
    Private Type tPdfFile
        sFullPath As String
        sName As String
        sMergePages As String
    End Type
    
    Private Declare Function FPDF_CreateNewDocument CDecl Lib "PDFium.dll" () As Long
    Private Declare Function FPDF_ImportPages CDecl Lib "PDFium.dll" (ByVal dest_doc As Long, ByVal src_doc As Long, ByVal pagerange As String, ByVal index As Long) As Long
    Private Declare Function FPDF_SaveAsCopy CDecl Lib "PDFium.dll" (ByVal document As Long, ByRef pFileWrite As FPDF_FILEWRITE, ByVal flags As PdfiumSaveCopyFlags) As Long
    Private Declare Function FPDF_GetLastError CDecl Lib "PDFium.dll" () As Long
    
    Private Declare Function CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef dest As Any, ByRef src As Any, ByVal cb As Long) As Long
    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long
    Private Declare Sub SHChangeNotify Lib "shell32.dll" (ByVal wEventId As Long, ByVal uFlags As Long, ByVal dwItem1 As Long, ByVal dwItem2 As Long)
    Private Declare Function VirtualAlloc Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
    Private Declare Function VirtualFree Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
        
    ' Constantes necesarias
    Private mInit As Boolean
    Private hFileOut As Long
    Private Const S_OK As Long = 0
    Private Const E_INVALIDARG As Long = &H80070057
    Private Const GENERIC_READ As Long = &H80000000
    Private Const GENERIC_WRITE As Long = &H40000000
    Private Const FILE_SHARE_READ As Long = &H1
    Private Const CREATE_ALWAYS As Long = 2
    Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80
    Private Const FILE_FLAG_WRITE_THROUGH As Long = &H80000000
    Private Const INVALID_HANDLE_VALUE As Long = -1
    and the functions:

    Code:
    Public Function WriteBlock(ByVal pThis As Long, ByVal pData As Long, ByVal size As Long) As Long
            If hFileOut Then
                Dim cbRet As Long
                WriteBlock = WriteFile(hFileOut, ByVal pData, size, cbRet, vbNull)
            End If
    End Function
    And the main function:

    Code:
    Public Function MergePdfs(sFileOut As String, tFilesIn() As String, sMergePages() As String) As Long
            
           ' Dim tFilesIn() As tPdfFile
            'tFilesIn = xtFilesIn
            
            If PDFLib = 0 Then 'If the PDFium library is not loaded, we load it and initialize it
                PDFLib = LoadLibraryW(StrPtr(App.Path & "\PDFium.dll"))
                FPDF_InitLibrary
                Set FormHook = New clsTrickSubclass2
                FormHook.Hook Me.hWnd
            End If
                    
            If UBound(tFilesIn) < 1 Then
                MsgBox "Error: Two or more files must be selected to merge."
                MergePdfs = E_INVALIDARG
                Exit Function
            End If
    
        '    hFileOut = CreateFile(sFileOut, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL Or FILE_FLAG_WRITE_THROUGH, 0)
        '    If hFileOut = INVALID_HANDLE_VALUE Then
        '        MsgBox "Error creating output file."
        '        MergePdfs = Err.LastDllError
        '        Exit Function
        '    End If
    
            Dim hDocNew As Long
            Dim hDocIn As Long
            Dim nPages As Long, nMerged As Long
            Dim lRet As Long, hr As Long
            Dim nInsIdx As Long
            Dim pFile() As Byte
            Dim i As Long
    
            hDocNew = FPDF_CreateNewDocument()
            For i = 0 To UBound(tFilesIn)
                
                Dim file_length As Long
                Dim fnum As Integer
                Dim bytes() As Byte
                Dim B() As Byte
                NbPage = 0
                file_length = FileLen(tFilesIn(i))
                fnum = FreeFile
                ReDim B(1 To file_length + 1)
                Open tFilesIn(i) For Binary As #fnum
                Get #fnum, 1, B
                Close fnum
                'we assign the PDF to PDFium
                SetPDFByteContent B
                'we recover the number of pages
                NbPage = PageCount
                    
                If NbPage > 0 Then
                        lRet = FPDF_ImportPages(hDocNew, hDoc, sMergePages(i), nMerged)
                        If lRet <> 0 Then
                            nMerged = nMerged + NbPage
                        Else
                            lRet = FPDF_GetLastError()
                            MsgBox "Error merging pages."
                        End If
                    FPDF_CloseDocument hDocIn
                End If
            Next i
    
            Dim pFunc As Long
            Dim tWrite As FPDF_FILEWRITE
            
            If nMerged > 0 Then
                tWrite.version = 1
                pFunc = GetAddressOfWriteBlock()
                CopyMemory tWrite.WriteBlock, pFunc, 4
                
                hFileOut = CreateFile(sFileOut, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL Or FILE_FLAG_WRITE_THROUGH, 0)
                If hFileOut = INVALID_HANDLE_VALUE Then
                    MsgBox "Error creating output file."
                    MergePdfs = Err.LastDllError
                    Exit Function
                End If
                g_hFileOut = hFileOut
                
               ' lRet = FPDF_SaveAsCopy(hDocNew, ByVal VarPtr(tWrite), 2)
                lRet = FPDF_SaveAsCopy(hDocNew, tWrite, 0)
                            
                If lRet <> 0 Then
                    MsgBox "Successfully saved merged document."
                    MergePdfs = S_OK
                Else
                    lRet = FPDF_GetLastError()
                    MsgBox "Error saving output file."
                End If
            Else
                MergePdfs = -1
            End If
    
            FPDF_CloseDocument hDocNew
            CloseHandle hFileOut
    End Function
    Ando to solve the AdressOf problem, in a BAS module, created this:

    Code:
    Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, ByVal lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long
    Public g_hFileOut As Long ' Variable global para el archivo de salida del mergepdf
    
    Public Function WriteBlockCallback(ByVal pThis As Long, ByVal pBuffer As Long, ByVal size As Long) As Long
    'funcion para el mergepdf
    
        'usamos esto como nuevo
         Dim written As Long
    
        ' Usar la variable global en lugar de pThis
        If WriteFile(g_hFileOut, ByVal pBuffer, size, written, ByVal 0&) = 0 Then
            WriteBlockCallback = 0 ' Error
        Else
            WriteBlockCallback = written ' Devuelve los bytes escritos
        End If
        
        
    End Function
    
    Public Function GetAddressOfWriteBlock() As Long
    'funcion para el mergepdf
        GetAddressOfWriteBlock = FuncPtr(AddressOf WriteBlockCallback)
    End Function
    Public Function FuncPtr(ByVal lpFunction As Long) As Long
    'funcion para el mergepdf
        FuncPtr = lpFunction
    End Function

    The problem is at the Saveascopy line: lRet = FPDF_SaveAsCopy(hDocNew, tWrite, 0)

    the ide hangs and it only saves 32 bytes...

    Any idea ?

    If it works, please add to your usercontrol xD

    Thanks!


    Edit: I have to clean some declarations, (i made a lot of tests... ), but i will do it when it works xD
    And of course it's 100% based on the fafalone twinbasic project !
    Last edited by Calcu; Mar 12th, 2025 at 02:04 PM.

  24. #64
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,856

    Re: PDF Reader ActiveX Control

    Well first as mentioned the callback must be CDecl...

    Public Function WriteBlockCallback CDecl(ByVal pThis As Long, ByVal pData As Long, ByVal size As Long) As Long

    And it shouldn't matter but you've got a lot of extras...

    tWrite.WriteBlock = FuncPtr(AddressOf WriteBlockCallback) is fine.
    Last edited by fafalone; Mar 12th, 2025 at 03:26 PM.

  25. #65
    Addicted Member
    Join Date
    May 2022
    Posts
    137

    Re: PDF Reader ActiveX Control

    Oh my god....

    Thanks a ton!

    I must be blind... i read your post, i was pretty sure i used Cdecl.....

    i just wrote cdecl and.. it's working perfectly ...

    THANKS again

    Edit: i will try to clean the code, and delete all the extras xD

    tomorrow the recap.

  26. #66
    Lively Member
    Join Date
    Aug 2023
    Posts
    119

    Re: PDF Reader ActiveX Control

    Also would be fine to be able to split a PDF, I mean, extract one page from the main PDF and save it as individual PDF.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width