use of com.itextpdf.text.Rectangle in project gephi by gephi.
the class PDFExporter method execute.
@Override
public boolean execute() {
Progress.start(progress);
PreviewController controller = Lookup.getDefault().lookup(PreviewController.class);
controller.getModel(workspace).getProperties().putValue(PreviewProperty.VISIBILITY_RATIO, 1.0);
controller.refreshPreview(workspace);
PreviewProperties props = controller.getModel(workspace).getProperties();
Rectangle size = new Rectangle(pageSize);
if (landscape) {
size = new Rectangle(pageSize.rotate());
}
Color col = props.getColorValue(PreviewProperty.BACKGROUND_COLOR);
size.setBackgroundColor(new BaseColor(col.getRed(), col.getGreen(), col.getBlue()));
Document document = new Document(size);
PdfWriter pdfWriter = null;
try {
pdfWriter = PdfWriter.getInstance(document, stream);
pdfWriter.setPdfVersion(PdfWriter.PDF_VERSION_1_5);
pdfWriter.setFullCompression();
} catch (DocumentException ex) {
Exceptions.printStackTrace(ex);
}
document.open();
PdfContentByte cb = pdfWriter.getDirectContent();
cb.saveState();
props.putValue(PDFTarget.LANDSCAPE, landscape);
props.putValue(PDFTarget.PAGESIZE, size);
props.putValue(PDFTarget.MARGIN_TOP, new Float((float) marginTop));
props.putValue(PDFTarget.MARGIN_LEFT, new Float((float) marginLeft));
props.putValue(PDFTarget.MARGIN_BOTTOM, new Float((float) marginBottom));
props.putValue(PDFTarget.MARGIN_RIGHT, new Float((float) marginRight));
props.putValue(PDFTarget.PDF_CONTENT_BYTE, cb);
target = (PDFTarget) controller.getRenderTarget(RenderTarget.PDF_TARGET, workspace);
if (target instanceof LongTask) {
((LongTask) target).setProgressTicket(progress);
}
try {
controller.render(target, workspace);
} catch (Exception e) {
throw new RuntimeException(e);
}
cb.restoreState();
document.close();
Progress.finish(progress);
props.putValue(PDFTarget.PDF_CONTENT_BYTE, null);
props.putValue(PDFTarget.PAGESIZE, null);
return !cancel;
}
use of com.itextpdf.text.Rectangle in project gephi by gephi.
the class UIExporterPDFPanel method unsetup.
public void unsetup(PDFExporter pdfExporter) {
if (pageSizeCombo.getSelectedItem() == customSizeString) {
double width = pdfExporter.getPageSize().getWidth();
double height = pdfExporter.getPageSize().getHeight();
try {
width = sizeFormatter.parse(widthTextField.getText()).doubleValue();
} catch (ParseException ex) {
}
try {
height = sizeFormatter.parse(heightTextField.getText()).doubleValue();
} catch (ParseException ex) {
}
if (millimeter) {
width *= MM;
height *= MM;
} else {
width *= INCH;
height *= INCH;
}
float w = (float) width;
float h = (float) height;
Rectangle rect = new Rectangle(w, h);
pdfExporter.setPageSize(rect);
} else {
pdfExporter.setPageSize(((PageSizeItem) pageSizeCombo.getSelectedItem()).getPageSize());
}
pdfExporter.setLandscape(landscapeRadio.isSelected());
double top = pdfExporter.getMarginTop();
double bottom = pdfExporter.getMarginBottom();
double left = pdfExporter.getMarginLeft();
double right = pdfExporter.getMarginRight();
try {
top = marginFormatter.parse(topMarginTextField.getText()).doubleValue();
} catch (ParseException ex) {
}
try {
bottom = marginFormatter.parse(bottomMarginTextField.getText()).doubleValue();
} catch (ParseException ex) {
}
try {
left = marginFormatter.parse(leftMarginTextField.getText()).doubleValue();
} catch (ParseException ex) {
}
try {
right = marginFormatter.parse(rightMargintextField.getText()).doubleValue();
} catch (ParseException ex) {
}
if (millimeter) {
top *= MM;
bottom *= MM;
left *= MM;
right *= MM;
} else {
top *= INCH;
bottom *= INCH;
left *= INCH;
right *= INCH;
}
pdfExporter.setMarginTop((float) top);
pdfExporter.setMarginBottom((float) bottom);
pdfExporter.setMarginLeft((float) left);
pdfExporter.setMarginRight((float) right);
savePreferences();
}
Aggregations