B4J Question Merge PDF (SOLVED)

LGS

Member
Licensed User
Longtime User
Hello everyone
I'm looking to merge 2 pdf files and found this on the forum
https://www.b4x.com/android/forum/threads/looking-to-merge-pdf.124916/post-780020

I have tried to do what they indicate here:
https://www.tutorialspoint.com/pdfbox/pdfbox_merging_multiple_pdf_documents.htm

But some PDFBox functions are deprecated
So I am using PDFBox 3.0.1 (requires Java 8)
https://pdfbox.apache.org/download.html

But I couldn't even compile the example
I am attaching an example of what I am trying to compile, it is probably something simple, but I can't see it.

Thanks in advance
 

Attachments

  • MergePdf.zip
    1.1 KB · Views: 24
Solution
Hello everyone
I'm looking to merge 2 pdf files and found this on the forum
https://www.b4x.com/android/forum/threads/looking-to-merge-pdf.124916/post-780020

I have tried to do what they indicate here:
https://www.tutorialspoint.com/pdfbox/pdfbox_merging_multiple_pdf_documents.htm

But some PDFBox functions are deprecated
So I am using PDFBox 3.0.1 (requires Java 8)
https://pdfbox.apache.org/download.html

But I couldn't even compile the example
I am attaching an example of what I am trying to compile, it is probably something simple, but I can't see it.

Thanks in advance
Try this code. it works in PDFBox 3.0.1
B4X:
Sub AppStart (Args() As String)
    Log("PDFBox")
    Me.as(JavaObject).RunMethod("mulFile2One"...

teddybear

Well-Known Member
Licensed User
Hello everyone
I'm looking to merge 2 pdf files and found this on the forum
https://www.b4x.com/android/forum/threads/looking-to-merge-pdf.124916/post-780020

I have tried to do what they indicate here:
https://www.tutorialspoint.com/pdfbox/pdfbox_merging_multiple_pdf_documents.htm

But some PDFBox functions are deprecated
So I am using PDFBox 3.0.1 (requires Java 8)
https://pdfbox.apache.org/download.html

But I couldn't even compile the example
I am attaching an example of what I am trying to compile, it is probably something simple, but I can't see it.

Thanks in advance
Try this code. it works in PDFBox 3.0.1
B4X:
Sub AppStart (Args() As String)
    Log("PDFBox")
    Me.as(JavaObject).RunMethod("mulFile2One", Null)
End Sub
#if java
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.multipdf.PDFMergerUtility;
import org.apache.pdfbox.io.RandomAccessStreamCache;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public static void mulFile2One() throws IOException{
        PDFMergerUtility mergePdf = new PDFMergerUtility();
        mergePdf.addSource(new File("D:\\test\\f1.pdf"));
        mergePdf.addSource(new File("D:\\test\\f2.pdf"));
        mergePdf.setDestinationFileName("D:\\test\\mul2one.pdf");
        RandomAccessStreamCache.StreamCacheCreateFunction streamCache
        = IOUtils.createMemoryOnlyStreamCache();
        mergePdf.mergeDocuments(streamCache);
    }
#End If
 
Upvote 0
Solution

LGS

Member
Licensed User
Longtime User
Dear teddybear
Once again, thank you for your time and for sharing your knowledge with this community.

Blessings šŸ™
 
Upvote 0
Top