org.jpedal.examples.viewer.commands.Images Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of OpenViewerFX Show documentation
Show all versions of OpenViewerFX Show documentation
Open Source (LGPL) JavaFX PDF Viewer
/*
* ===========================================
* Java Pdf Extraction Decoding Access Library
* ===========================================
*
* Project Info: http://www.idrsolutions.com
* Help section for developers at http://www.idrsolutions.com/support/
*
* (C) Copyright 1997-2017 IDRsolutions and Contributors.
*
* This file is part of JPedal/JPDF2HTML5
*
@LICENSE@
*
* ---------------
* Images.java
* ---------------
*/
package org.jpedal.examples.viewer.commands;
import org.jpedal.PdfDecoderInt;
import org.jpedal.display.GUIThumbnailPanel;
import org.jpedal.examples.viewer.Values;
import org.jpedal.gui.GUIFactory;
import org.jpedal.objects.GraphicsState;
import org.jpedal.objects.PdfPageData;
import org.jpedal.render.DynamicVectorRenderer;
import org.jpedal.utils.LogWriter;
import org.jpedal.utils.Messages;
/**
* Extract/Save Images
*/
public class Images {
/**
* used to display non-PDF files
*/
public static void addImage(final PdfDecoderInt decode_pdf, final Values commonValues) {
final GraphicsState gs = new GraphicsState();
gs.CTM[0][0] = commonValues.getBufferedImg().getWidth();
gs.CTM[1][1] = commonValues.getBufferedImg().getHeight();
decode_pdf.getDynamicRenderer().drawImage(1, commonValues.getBufferedImg(), gs, false, "image", -1);
//Set size for the given page as each page can be a different size
if (commonValues.isMultiTiff()) {
if (commonValues.getBufferedImg() != null) {
decode_pdf.getPdfPageData().setMediaBox(new float[]{0, 0, commonValues.getBufferedImg().getWidth(), commonValues.getBufferedImg().getHeight()});
}
decode_pdf.getPdfPageData().checkSizeSet(1);
}
}
/**
* called by any functions to decode next page
*/
public static void decodeImage(final PdfDecoderInt decode_pdf, final GUIFactory currentGUI, final GUIThumbnailPanel thumbnails, final Values commonValues) {
//remove any search highlight
decode_pdf.getTextLines().clearHighlights();
//decode_pdf.addHighlights(null, false);
//decode_pdf.setMouseHighlightAreas(null); now a duplicate of above
//stop user changing scaling while decode in progress
currentGUI.resetComboBoxes(false);
currentGUI.getButtons().setPageLayoutButtonsEnabled(false);
/*
* flush any previous pages
*/
decode_pdf.getDynamicRenderer().writeCustom(DynamicVectorRenderer.FLUSH, null);
decode_pdf.getPages().refreshDisplay();
/*
* if running terminate first
*/
thumbnails.terminateDrawing();
Values.setProcessing(true);
final org.jpedal.utils.SwingWorker worker = new org.jpedal.utils.SwingWorker() {
@Override
public Object construct() {
try {
currentGUI.updateStatusMessage(Messages.getMessage("PdfViewerDecoding.page"));
if (commonValues.getBufferedImg() != null) {
addImage(decode_pdf, commonValues);
}
final PdfPageData page_data = decode_pdf.getPdfPageData();
if (commonValues.getBufferedImg() != null) {
page_data.setMediaBox(new float[]{0, 0, commonValues.getBufferedImg().getWidth(), commonValues.getBufferedImg().getHeight()});
}
page_data.checkSizeSet(1);
currentGUI.resetRotationBox();
/*
* make sure screen fits display nicely
*/
if (thumbnails.isShownOnscreen()) {
currentGUI.scaleAndRotate();
}
if (Thread.interrupted()) {
throw new InterruptedException();
}
currentGUI.setPageNumber();
currentGUI.setViewerTitle(null); // restore title
currentGUI.getButtons().hideRedundentNavButtons(currentGUI);
} catch (final Exception e) {
LogWriter.writeLog("Exception in handling title " + e);
currentGUI.setViewerTitle(null); //restore title
Values.setProcessing(false);
}
currentGUI.setStatusProgress(100);
//reanable user changing scaling
currentGUI.resetComboBoxes(true);
//ensure drawn
decode_pdf.repaint();
Values.setOpeningTransferedFile(false);
Values.setProcessing(false);
return null;
}
};
worker.start();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy