Giter Club home page Giter Club logo

Comments (3)

galkahana avatar galkahana commented on July 4, 2024

I found the general help from Android documentation to be helpful:
https://developer.android.com/studio/projects/add-native-code

Since PDFWriter is a Cmake project it can be easily incorporated into a new or existing application.
there's several ways to go about this, but i find the simplest is to add a new native C++ library to your project, which will involve having a new CMakeList.txt file and some native code. In that CMakeLists.txt refer to pdf-writer, and then write code in the native library to do whatever you want with pdf-writer.

So for example if one uses the "Native C++" project template you can add the following steps and have pdf-writer available for you:

1. Edit the CMakeLists.txt to fetch PDF-Writer from github

In the CMakeLists.txt file of the native-lib add the following statement to fetch pdf-writer:

# hummus dependency
include(FetchContent)
FetchContent_Declare(
        PDFHummus
        GIT_REPOSITORY https://github.com/galkahana/PDF-Writer.git
        GIT_TAG        v4.5.7
)
FetchContent_MakeAvailable(PDFHummus)

2. Add pdf-writer dependency to your native library

Still in the CMakeLists.txt file of the native-lib add this statement to link pdf-writer to your library and make includes and links available:

target_link_libraries (mynativeapplication PDFHummus::PDFWriter)

(change mynativeapplication to the name used in add_library).

3. Add code in the exported function(s) to use PDF-Writer

for example, in the native app template i added the code in the native-lib.cpp.

here's the full code example, it creates an empty file:

#include <jni.h>
#include <string>

#include "PDFWriter.h"
#include "PDFPage.h"
#include "PDFRectangle.h"

#include <iostream>

using namespace std;
using namespace PDFHummus;

extern "C" JNIEXPORT jstring JNICALL
Java_com_example_mynativeapplication_MainActivity_stringFromJNI(
        JNIEnv* env,
        jobject /* this */) {

    // build me an empty PDF
    PDFWriter pdfWriter;
    EStatusCode status;

    do
    {
        status = pdfWriter.StartPDF("./EmptyPages.pdf",ePDFVersion14);
        if(status != PDFHummus::eSuccess)
        {
            cout<<"failed to start PDF\n";
            break;
        }


        PDFPage* page = new PDFPage();
        page->SetMediaBox(PDFRectangle(0,0,595,842));

        for(int i=0;i<4 && PDFHummus::eSuccess == status;++i)
        {
            status = pdfWriter.WritePage(page);
            if(status != PDFHummus::eSuccess)
                cout<<"failed to write page "<<i<<"\n";
        }
        delete page;

        status = pdfWriter.EndPDF();
        if(status != PDFHummus::eSuccess)
        {
            cout<<"failed in end PDF\n";
            break;
        }
    }while(false);



    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

This should create a file...somewhere (i guess pointing to a clear place in the device would be better...but it's just an example, so i allowed it).
I'm guessing similar thing can be done for other usages.

Having said that

I'm kinda positive there are Java PDF libraries, no? nothing that can be used instead that might make this simpler? though i guess it doesn't look very complicated. I hear PDFBox is quite good, if you are interested in looking for an alternative.

from pdf-writer.

ffreality avatar ffreality commented on July 4, 2024

Can be helpful but noy exactly because my goal is developing a crossplatform Unreal Engine plugin. So, there is no Android Studio project at all. I need a gradlew assembleRelease like solution to give me .so files

from pdf-writer.

galkahana avatar galkahana commented on July 4, 2024

I see. I think this is covered by adding and externalNativeBuild statement to your gradle:
https://developer.android.com/studio/projects/gradle-external-native-builds#configure-gradle

The studio just makes it easy in creating a local cmake project for you that you can tie to pdf-,writer. The end result is an so library.

But yeah im no android/gradle expert so maybe it doesn't help

from pdf-writer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.