Hi,
I don't know if I modified the sample project well,
I receive the following error in the compilation:
A tip is welcome, which is wrong in the code
I don't know if I modified the sample project well,
I receive the following error in the compilation:
B4J Version: 10.00
Code parsing. (0.00s)
Java version: 8
Building Folders Structure. (0.02s)
Code compilation. (0.00s)
Obfuscatormap.txt file created in the Objects folder.
Compilation of the system code. (0.00s)
Organizing libraries. (0.00s)
Compilation of the generated Java code. Error
B4J LINE: 12
End sub
Javac 1.8.0_441
SRC \ B4J \ Example \ Main.java: 126: Error: <Identifier> Expected
Public Void Class Saveimagesinpdf EXTENDS PDFSTReameNGINE
^
1 error
A tip is welcome, which is wrong in the code
Example::
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
#AdditionalJar: pdfbox-app-2.0.26
' download https://www.apache.org/dyn/closer.lua/pdfbox/2.0.26/pdfbox-app-2.0.26.jar
Sub Process_Globals
Private jo As JavaObject
End Sub
Sub AppStart (Args() As String)
jo = Me
' Dim pathPDF As String = "D:\\TMP\\UE.pdf"
' jo.RunMethod("SaveImagesInPdf", Array As Object(pathPDF))
jo.RunMethod("SaveImagesInPdf", Null)
End Sub
#if java
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.graphics.PDXObject;
import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.contentstream.operator.Operator;
import org.apache.pdfbox.contentstream.PDFStreamEngine;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.imageio.ImageIO;
/**
* This is an example on how to extract images from pdf.
*/
public void class SaveImagesInPdf extends PDFStreamEngine
{
/**
* Default constructor.
*
* @throws IOException If there is an error loading text stripper properties.
*/
public SaveImagesInPdf() throws IOException
{
}
public int imageNumber = 1;
/**
* @param args The command line arguments.
*
* @throws IOException If there is an error parsing the document.
*/
public void main( String[] args ) throws IOException
{
PDDocument document = null;
String fileName = "D:\\TMP\\UE.pdf";
try
{
document = PDDocument.load( new File(fileName) );
SaveImagesInPdf printer = new SaveImagesInPdf();
int pageNum = 0;
for( PDPage page : document.getPages() )
{
pageNum++;
System.out.println( "Processing page: " + pageNum );
printer.processPage(page);
}
}
finally
{
if( document != null )
{
document.close();
}
}
}
/**
* @param operator The operation to perform.
* @param operands The list of arguments.
*
* @throws IOException If there is an error processing the operation.
*/
@Override
protected void processOperator( Operator operator, List<COSBase> operands) throws IOException
{
String operation = operator.getName();
if( "Do".equals(operation) )
{
COSName objectName = (COSName) operands.get( 0 );
PDXObject xobject = getResources().getXObject( objectName );
if( xobject instanceof PDImageXObject)
{
PDImageXObject image = (PDImageXObject)xobject;
// same image to local
BufferedImage bImage = image.getImage();
ImageIO.write(bImage,"PNG",new File("image_"+imageNumber+".png"));
System.out.println("Image saved.");
imageNumber++;
}
else if(xobject instanceof PDFormXObject)
{
PDFormXObject form = (PDFormXObject)xobject;
showForm(form);
}
}
else
{
super.processOperator(operator, operands);
}
}
}
#End If
Attachments
Last edited: