class PDFExporter implements ByteExporter, VectorExporter, LongTask {

    private ProgressTicket progress;
    private Workspace workspace;
    private OutputStream stream;
    private boolean cancel = false;
    private PDFTarget target;
    //Parameters
    private float marginTop = 18f;
    private float marginBottom = 18f;
    private float marginLeft = 18f;
    private float marginRight = 18f;
    private boolean landscape = false;
    private PDRectangle pageSize = PDRectangle.A4;
    private boolean transparentBackground = false;

    @Override
    public boolean execute() {<FILL_FUNCTION_BODY>}

    public boolean isLandscape() {
        return landscape;
    }

    public void setLandscape(boolean landscape) {
        this.landscape = landscape;
    }

    public float getMarginBottom() {
        return marginBottom;
    }

    public void setMarginBottom(float marginBottom) {
        this.marginBottom = marginBottom;
    }

    public float getMarginLeft() {
        return marginLeft;
    }

    public void setMarginLeft(float marginLeft) {
        this.marginLeft = marginLeft;
    }

    public float getMarginRight() {
        return marginRight;
    }

    public void setMarginRight(float marginRight) {
        this.marginRight = marginRight;
    }

    public float getMarginTop() {
        return marginTop;
    }

    public void setMarginTop(float marginTop) {
        this.marginTop = marginTop;
    }

    public PDRectangle getPageSize() {
        return pageSize;
    }

    public void setPageSize(PDRectangle pageSize) {
        this.pageSize = pageSize;
    }

    public boolean isTransparentBackground() {
        return transparentBackground;
    }

    public void setTransparentBackground(boolean transparentBackground) {
        this.transparentBackground = transparentBackground;
    }

    @Override
    public void setOutputStream(OutputStream stream) {
        this.stream = stream;
    }

    @Override
    public Workspace getWorkspace() {
        return workspace;
    }

    @Override
    public void setWorkspace(Workspace workspace) {
        this.workspace = workspace;
    }

    @Override
    public boolean cancel() {
        this.cancel = true;
        if (target instanceof LongTask) {
            ((LongTask) target).cancel();
        }
        return true;
    }

    @Override
    public void setProgressTicket(ProgressTicket progressTicket) {
        this.progress = progressTicket;
    }
}

        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();

        try (PDDocument doc = new PDDocument()) {
            doc.setVersion(1.5f);

            PDRectangle size = landscape ? new PDRectangle(pageSize.getHeight(), pageSize.getWidth()) : pageSize;
            PDPage page = new PDPage(size);
            doc.addPage(page);

            try (PDPageContentStream contentStream = new PDPageContentStream(doc, page)) {
                props.putValue(PDFTarget.LANDSCAPE, landscape);
                props.putValue(PDFTarget.PAGESIZE, size);
                props.putValue(PDFTarget.MARGIN_TOP, marginTop);
                props.putValue(PDFTarget.MARGIN_LEFT, marginLeft);
                props.putValue(PDFTarget.MARGIN_BOTTOM, marginBottom);
                props.putValue(PDFTarget.MARGIN_RIGHT, marginRight);
                props.putValue(PDFTarget.PDF_CONTENT_BYTE, contentStream);
                props.putValue(PDFTarget.PDF_DOCUMENT, doc);
                props.putValue(PDFTarget.TRANSPARENT_BACKGROUND, transparentBackground);
                target = (PDFTarget) controller.getRenderTarget(RenderTarget.PDF_TARGET, workspace);
                if (target instanceof LongTask) {
                    ((LongTask) target).setProgressTicket(progress);
                }

                controller.render(target, workspace);
            }
            doc.save(stream);
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        } finally {
            Progress.finish(progress);

            props.putValue(PDFTarget.PDF_CONTENT_BYTE, null);
            props.putValue(PDFTarget.PAGESIZE, null);
            props.putValue(PDFTarget.PDF_DOCUMENT, null);
        }
        return !cancel;
    
<no_super_class>