C# to Delphi code translation for Amyuni HTML to PDF sample

Posted on 2012-08-16
Last Modified: 2012-08-19
I have downloaded free Amyuni WebkitPDF from here:

The example that comes with it is written in C# and I need to translate it to Delphi 7.

As the minimum, I need a working code in Delphi 7 that will:

1. Open URL or local HTML file
2. Save it to a PDF file.

or using the dll calls:

1. WKPDFInitialize
3. WKPDFSaveToFile
4. WKPDFTerminate
Question by:graga
    LVL 25

    Accepted Solution

    Try this:

    function WKPDFInitialize(license: WideString; key: WideString): Integer; stdcall external 'WebKit.dll';
    function WKPDFTerminate(): Integer; stdcall external 'WebKit.dll';
    function WKPDFOpenURL(url: WideString; var context: Pointer; pageRenderingOptions: Integer; isJavaScriptEnabled: Boolean): Integer; stdcall external 'WebKit.dll';
    function WKPDFSaveToFile(fileName: WideString; context: Pointer): Integer; stdcall external 'WebKit.dll';
    function WKPDFCloseContext(context: Pointer): Integer; stdcall external 'WebKit.dll';
    ptr: Pointer;
    if WKPDFInitialize('', '')<>0 then Exit;
    ptr := nil;
    if WKPDFOpenURL('', ptr, 0, False)<>0 then Exit;
    if ptr<>nil then
       WKPDFSaveToFile('c:\eee.pdf', ptr);

    Open in new window


    Author Comment

    Thanks for the solution. It works fine on web pages, but I can't make it work on local files, like  'file:\\\c:\test.html'. The C# example works fine for local files. Can you look into it as well?

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
    Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now