After setting color for a character while exporting I am not able to get required result.
import com.abbyy.FREngine.*;
import java.nio.file.*;
import java.io.*
;public class Highlight {
public static void main( String[] args ) {
try {
Highlight application = new Highlight();
application.Run();
} catch( Exception ex ) {
displayMessage( ex.getMessage() );
}
}
public void Run() throws Exception {
// Load ABBYY FineReader Engine
loadEngine();
try {
// Process with ABBYY FineReader Engine
processWithEngine();
} finally {
// Unload ABBYY FineReader Engine
unloadEngine();
}
}
private void loadEngine() throws Exception {
displayMessage( "Initializing Engine..." );
engine = Engine.GetEngineObject( SamplesConfig.GetDllFolder(), SamplesConfig.GetDeveloperSN() );
}
private void processWithEngine() {
try {
setupFREngine();
processImage();
} catch( Exception ex ) {
displayMessage( ex.getMessage() );
}
}
private void setupFREngine() {
engine.LoadPredefinedProfile( "TextExtraction_Accuracy" );
// Possible profile names are:
// "DocumentConversion_Accuracy", "DocumentConversion_Speed",
// "DocumentArchiving_Accuracy", "DocumentArchiving_Speed",
// "BookArchiving_Accuracy", "BookArchiving_Speed",
// "TextExtraction_Accuracy", "TextExtraction_Speed",
// "FieldLevelRecognition",
// "BarcodeRecognition_Accuracy", "BarcodeRecognition_Speed",
// "HighCompressedImageOnlyPdf",
// "BusinessCardsProcessing",
// "EngineeringDrawingsProcessing",
// "Version9Compatibility",
// "Default"
}
private void processImage() {
String imagePath = "D:\\DD-94-2040866\\Input_DD-94-2040866.pdf";
try {
// Don't recognize PDF file with a textual content, just copy it
/* if( engine.IsPdfWithTextualContent( imagePath, null ) ) {
displayMessage( "Copy results..." );
String resultPath ="C:\\Users\\100979\\Downloads\\demo.pdf";
Files.copy( Paths.get( imagePath ), Paths.get( resultPath ), StandardCopyOption.REPLACE_EXISTING );
return;
} */
// Create document
IFRDocument document = engine.CreateFRDocument();
try {
// Add image file to document
displayMessage( "Loading image..." );
document.AddImageFile( imagePath, null, null );
IDocumentProcessingParams docProc=engine.CreateDocumentProcessingParams();
docProc.setPerformSynthesis(true);
document.Process(docProc);
IFRPages frPages = document.getPages();
/*IWord word=frPages.Item(0).getLayout().getBlocks().Item(0).GetAsTextBlock().getText().getParagraphs().Item(0).getWords().Item(0);
System.out.println(word.getText());*/
System.out.println("Total Pages : " + frPages.getCount());
for(int i = 0; i<frPages.getCount(); i++) {
System.out.println("Processing Page : " + i);
System.out.println("---------------------------------------------------------------------------");
ILayout layout = frPages.Item(i).getLayout();
for(int j = 0; j < layout.getBlocks().getCount(); j++)
{
IBlock block = layout.getBlocks().Item(j);
ITextBlock tblock = block.GetAsTextBlock();
IParagraphs paras = tblock.getText().getParagraphs();
String paragraph = null;
String searchString = "REQUESTED";
for(int k = 0; k < paras.getCount(); k++)
{
paragraph = paras.Item(k).getText();
if (null != paragraph && paragraph.toLowerCase().contains(searchString.toLowerCase()))
{
System.out.println("----\n" + paragraph + "\n");
IWords words=paras.Item(k).getWords();
String word=null;
for(int l=0;l< words.getCount();l++)
{
word=words.Item(l).getText();
if(null!=word && word.toLowerCase().contains(searchString.toLowerCase()))
{
int x=255+(256*192)+(65536*203);
ICharParams charParams=engine.CreateCharParams();
paras.Item(k).GetCharParams(0, charParams);
charParams.setColor(8850120);
paras.Item(k).SetCharParams(words.Item(l).getFirstSymbolPosition(), 3,charParams, 0x00010000, 0x400000);
}
}
//paras.Item(k).GetCharParams(p, arg1);
}
/*if (k == 0 ) {
System.out.println(paras.Item(k).getLines().getElement(0).);
}*/
}
}
}
String pdfExportPath ="D:\\DD-94-2040866\\Output-highlighted4_DD-94-2040866.pdf";
ISynthesisParamsForPage sPage=engine.CreateSynthesisParamsForPage();
sPage.setDetectBackgroundColor(ThreeStatePropertyValueEnum.TSPV_Yes);
document.Recognize(sPage,null);
document.Synthesize(null);
displayMessage( "Saving image..." );
document.Export( pdfExportPath, FileExportFormatEnum.FEF_PDF,null);
}
finally {
// Close document
document.Close();
}
} catch( Exception ex ) {
displayMessage( ex.getMessage() );
}
}
private void unloadEngine() throws Exception {
displayMessage( "Deinitializing Engine..." );
engine = null;
Engine.DeinitializeEngine();
}
private static void displayMessage( String message ) {
System.out.println( message );
}
private IEngine engine = null;
}
コメント
3件のコメント
Hi, Ankir
You should restrain from using Synthesize method before saving the result of your work. The thing is this method reads the document and synthesizes it again. During this process performed changes are lost. To save result of your work you do not need to synthesize or recognize document again. Try commenting these lines, or placing them before you change background colour:
ISynthesisParamsForPage sPage=engine.CreateSynthesisParamsForPage();
sPage.setDetectBackgroundColor(ThreeStatePropertyValueEnum.TSPV_Yes);
document.Recognize(sPage,null);
document.Synthesize(null);
If it doesn’t help, please send image examples to SDK_Support@abbyy.com.
Thanks for your reply. I tried your solution but still getting the same resuslt. Shall I change any other parameter.
Hi again!
I am really sorry, that I missed one more change I did, for your code to work properly. In this line:
SetCharParams(words.Item(l).getFirstSymbolPosition(), 3,charParams, 0x00010000, 0x400000);
The last two parameters define to which font and style features of the character you want to apply changes. 0x00010000 states, that you want to copy only LanguageID property from charParams object. 0x400000 states that you want to copy only BaseLineRise property from charParams object. To also copy text color you would have to change your line to look like that:
SetCharParams(words.Item(l).getFirstSymbolPosition(), 3,charParams, 0x00010000, 0x100000 | 0x400000);
If this still won’t solve your issue, please send us examples of your images to SDK_Support@abbyy.com.
サインインしてコメントを残してください。