Example usage for com.itextpdf.text Document Document

List of usage examples for com.itextpdf.text Document Document

Introduction

In this page you can find the example usage for com.itextpdf.text Document Document.

Prototype


public Document() 

Source Link

Document

Constructs a new Document -object.

Usage

From source file:com.vectorprint.vectorprintreportgui.Controller.java

License:Open Source License

private void importStyle(ParsingProperties settings) throws DocumentException, VectorPrintException {
    clear(null);//from   w  w w  .  j  a  v a 2s .c o m
    Boolean preAndPost = settings.getBooleanProperty(true, DefaultStylerFactory.PREANDPOSTSTYLE);
    // set to false when importing to prevent all pre and post stylers to be added to regulerar style classes
    settings.put(DefaultStylerFactory.PREANDPOSTSTYLE, Boolean.FALSE.toString());
    DefaultStylerFactory sf = new DefaultStylerFactory();
    StylerFactoryHelper.SETTINGS_ANNOTATION_PROCESSOR.initSettings(sf, settings);
    Document d = new Document();
    PdfWriter w = PdfWriter.getInstance(d, new ByteArrayOutputStream(0));
    w.setPageEvent(new EventHelper());
    sf.setDocument(d, w);

    for (Map.Entry<String, String[]> e : settings.entrySet()) {
        commentsBefore.put(e.getKey(), settings.getCommentBeforeKey(e.getKey()));
        if (ReportConstants.DOCUMENTSETTINGS.equals(e.getKey())) {
            stylingConfig.put(e.getKey(), new ArrayList<>(1));
            stylingConfig.get(e.getKey()).add(sf.getDocumentStyler());
            pdf1a.setSelected(sf.getDocumentStyler().getValue(DocumentSettings.PDFA, Boolean.class));
            toc.setSelected(sf.getDocumentStyler().getValue(DocumentSettings.TOC, Boolean.class));
        } else if (ViewHelper.isStyler(e.getKey(), settings)) {
            stylingConfig.put(e.getKey(), new ArrayList<>(3));
            try {
                List<BaseStyler> l = sf.getStylers(e.getKey());
                stylingConfig.get(e.getKey()).addAll(l);
                getConditions(l);
                getDefaults(l, settings);
            } catch (VectorPrintException ex) {
                ViewHelper.toError(ex, error);
            }
        } else if (!ViewHelper.isCondition(e.getKey(), settings)) {
            if (DefaultStylerFactory.PREANDPOSTSTYLE.equals(e.getKey())) {
                prepost.setSelected(preAndPost);
                extraSettings.put(e.getKey(), preAndPost.toString());
            } else {
                if (ReportConstants.DEBUG.equals(e.getKey())) {
                    debug.setSelected(Boolean.valueOf(e.getValue()[0]));
                } else if (ReportConstants.PRINTFOOTER.equals(e.getKey())) {
                    footer.setSelected(Boolean.valueOf(e.getValue()[0]));
                }
                extraSettings.put(e.getKey(), e.getValue()[0]);
            }
        }
    }
    for (Iterator it = extraSettings.entrySet().iterator(); it.hasNext();) {
        Map.Entry<String, String> e = (Map.Entry<String, String>) it.next();
        if (processed.contains(e.getKey())) {
            it.remove();
        }
    }
    // check conditions not referenced
    settings.entrySet().stream().forEach((e) -> {
        if (ViewHelper.isCondition(e.getKey(), settings)) {
            Logger.getLogger(Controller.class.getName())
                    .warning(String.format("unreferenced conditions for key: %s", e.getKey()));
            List<StylingCondition> conditions;
            try {
                conditions = sf.getConditions(e.getKey());
            } catch (VectorPrintException ex) {
                throw new VectorPrintRuntimeException(ex);
            }
            stylingConfig.put(e.getKey(), new ArrayList<>(conditions.size()));
            stylingConfig.get(e.getKey()).addAll(conditions);
        }
    });
    commentsAfter.addAll(settings.getTrailingComment());
    ViewHelper.notify("ok", "import complete", "you can now adapt and (re)build your stylesheet");
}

From source file:com.verbox.PrintHtml.java

public static void RenderPDF_img_too(String inpHtml) throws FileNotFoundException, ParserConfigurationException,
        SAXException, IOException, DocumentException, PrinterException {
    try {/*from w  w w.  j a  va2  s  .c  o  m*/
        fullhtml = inpHtml;
        String replaceAll = fullhtml.replaceAll("../../image/", "");
        Document document = new Document();
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf.pdf"));
        // step 3
        document.open();
        // step 4
        XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
        InputStream is = new ByteArrayInputStream(replaceAll.getBytes(StandardCharsets.UTF_8));
        worker.parseXHtml(writer, document, is, Charset.forName("UTF-8"));
        // step 5
        document.close();
        PreImgPrint();

    } catch (DocumentException | IOException E) {
        JOptionPane.showMessageDialog(null, "Exeption on print or prepare image " + E);
    }
}