• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PdfDocument类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.itextpdf.kernel.pdf.PdfDocument的典型用法代码示例。如果您正苦于以下问题:Java PdfDocument类的具体用法?Java PdfDocument怎么用?Java PdfDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PdfDocument类属于com.itextpdf.kernel.pdf包,在下文中一共展示了PdfDocument类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: extractAnnotations

import com.itextpdf.kernel.pdf.PdfDocument; //导入依赖的package包/类
/**
 * Extract annotations from given PDF document.
 * @param pdfDocument PDF document.
 * @return Extracted annotations.
 */
protected AnnotatedDocument extractAnnotations(PdfDocument pdfDocument) {
    AnnotatedDocument document = new AnnotatedDocument();
    PdfDocumentInfo pdfInfo = pdfDocument.getDocumentInfo();
    document.setTitle(pdfInfo.getTitle());
    document.setSubject(pdfInfo.getSubject());
    document.setAuthor(pdfInfo.getAuthor());
    List<String> keywords = convertToKeywords(pdfInfo.getKeywords());
    document.setKeywords(keywords);

    List<Annotation> annotations = new LinkedList<>();
    for (int i = 1; i <= pdfDocument.getNumberOfPages(); i++) {
        PdfPage page = pdfDocument.getPage(i);
        for (PdfAnnotation pdfAnnotation : page.getAnnotations()) {
            Annotation annotation = convertAnnotation(pdfAnnotation);
            if (annotation != null) {
                annotations.add(annotation);
            }
        } //
    } //
    document.setAnnotations(annotations);

    return document;
}
 
开发者ID:dimi2,项目名称:DyAnnotationExtractor,代码行数:29,代码来源:PdfAnnotationImporter.java


示例2: createPdf

import com.itextpdf.kernel.pdf.PdfDocument; //导入依赖的package包/类
public void createPdf(String dest) throws IOException {
    //Initialize PDF writer
    PdfWriter writer = new PdfWriter(dest);

    //Initialize PDF document
    PdfDocument pdf = new PdfDocument(writer);

    // Initialize document
    Document document = new Document(pdf);

    //Add paragraph to the document
    document.add(new Paragraph("Hello World!"));

    //Close document
    document.close();
}
 
开发者ID:daishicheng,项目名称:outcomes,代码行数:17,代码来源:PDFCreator.java


示例3: manipulatePdf

import com.itextpdf.kernel.pdf.PdfDocument; //导入依赖的package包/类
@Test
public void manipulatePdf() throws IOException {
    PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC));
    Rectangle rect = new Rectangle(36, 750, 523, 56);

    FontFilter fontFilter = new FontFilter(rect);
    FilteredEventListener listener = new FilteredEventListener();
    LocationTextExtractionStrategy extractionStrategy = listener.attachEventListener(new LocationTextExtractionStrategy(), fontFilter);
    new PdfCanvasProcessor(listener).processPageContent(pdfDoc.getFirstPage());

    String actualText = extractionStrategy.getResultantText();
    System.out.println(actualText);

    pdfDoc.close();


}
 
开发者ID:padeoe,项目名称:nju-lib-downloader,代码行数:18,代码来源:PDFReader.java


示例4: PDFRenderer

import com.itextpdf.kernel.pdf.PdfDocument; //导入依赖的package包/类
public PDFRenderer(Composite rootComponent, PageSize pageSize){
    super(rootComponent);
    this.pageSize = pageSize;
    this.outputStream = new ByteArrayOutputStream();
    this.pdfWriter = new PdfWriter(outputStream);
    this.pdfDocument = new PdfDocument(pdfWriter);
    this.document = new Document(pdfDocument, pageSize);
    this.document.setMargins(0, 0, 0, 0);
    this.renderStrategies = new LinkedHashMap<Class, Class>(){{
        put(Component.class, DefaultComponentRenderStrategy.class);
        put(PLImageBlock.class, ImageRenderStrategy.class);
        put(PLTextBlock.class, TextRenderStrategy.class);
        put(PLTableBlock.class, TableRenderStrategy.class);
        put(PLLineChartBlock.class, LineChartRenderStrategy.class);
        put(PLPieChartBlock.class, PieChartRenderStrategy.class);
        put(PLBarPlotBlock.class, BarPlotRenderStrategy.class);
    }};
    this.newPage();
}
 
开发者ID:Amine-H,项目名称:PDFLego,代码行数:20,代码来源:PDFRenderer.java


示例5: readAnnotations

import com.itextpdf.kernel.pdf.PdfDocument; //导入依赖的package包/类
public AnnotatedDocument readAnnotations(String fileName) {
    // Check the file existence.
    File file = new File(fileName).getAbsoluteFile();
    if (!file.isFile()) {
        String message = String.format("File '%s' does not exist", file.getName());
        throw new IllegalArgumentException(message);
    }

    // Extract the annotations.
    PdfDocument pdfDocument = readDocument(file);
    return extractAnnotations(pdfDocument);
}
 
开发者ID:dimi2,项目名称:DyAnnotationExtractor,代码行数:13,代码来源:PdfAnnotationImporter.java


示例6: generatePDFFromImage

import com.itextpdf.kernel.pdf.PdfDocument; //导入依赖的package包/类
/**
 * 将图片合成为一个PDF
 * @param inputImage 图片,格式为图片格式
 * @param outputPDF 输出文件
 * @throws FileNotFoundException
 * @throws MalformedURLException
 */
public static void generatePDFFromImage(File[] inputImage,File outputPDF) throws FileNotFoundException, MalformedURLException {
    List<Image>images=new LinkedList<>();
    for(File file:inputImage){
        images.add(new Image(ImageDataFactory.create(file.getPath())));
    }
    PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outputPDF.getPath()));

    images.forEach(image -> pdfDoc.addNewPage(new PageSize(new Rectangle(image.getImageScaledWidth(), image.getImageScaledHeight()))));
    BackgroundEventHandler handler = new BackgroundEventHandler(images);
    pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE, handler);
    pdfDoc.close();
}
 
开发者ID:padeoe,项目名称:nju-lib-downloader,代码行数:20,代码来源:PDFTool.java


示例7: handleEvent

import com.itextpdf.kernel.pdf.PdfDocument; //导入依赖的package包/类
@Override
public void handleEvent(Event event) {
    PdfDocumentEvent docEvent = (PdfDocumentEvent) event;
    PdfDocument pdfDoc = docEvent.getDocument();
    PdfPage page = docEvent.getPage();
    PdfCanvas canvas = new PdfCanvas(page.newContentStreamBefore(),
            page.getResources(), pdfDoc);
    Rectangle area = page.getPageSize();
    new Canvas(canvas, pdfDoc, area)
            .add(images.get(offset));
    offset++;
}
 
开发者ID:padeoe,项目名称:nju-lib-downloader,代码行数:13,代码来源:PDFTool.java


示例8: manipulatePdf

import com.itextpdf.kernel.pdf.PdfDocument; //导入依赖的package包/类
protected void manipulatePdf(String dest) throws Exception {
    PdfDocument pdfDoc = new PdfDocument(new PdfWriter(DEST));
    Document doc = new Document(pdfDoc);
    pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE, new TextFooterEventHandler(doc));
    for (int i = 0; i < 3; ) {
        i++;
        doc.add(new Paragraph("Test " + i));
        if (3 != i) {
            doc.add(new AreaBreak());
        }
    }
    doc.close();
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:14,代码来源:TextFooter.java


示例9: generateInvoice

import com.itextpdf.kernel.pdf.PdfDocument; //导入依赖的package包/类
@Override
@Transactional(readOnly = true)
public File generateInvoice(List<String> billingRecordUids) {
    try {
        PdfReader pdfReader = new PdfReader(folderPath + "/invoice_template.pdf");// Source File

        File tempStorage = File.createTempFile("invoice","pdf");
        tempStorage.deleteOnExit();

        PdfDocument myDocument = new PdfDocument(pdfReader,new PdfWriter(tempStorage.getAbsolutePath()));
        PdfAcroForm pdfAcroForm = PdfAcroForm.getAcroForm(myDocument,true);

        Map<String,PdfFormField> pdfFormFieldMap = pdfAcroForm.getFormFields();

        List<AccountBillingRecord> records = billingRepository.findByUidIn(billingRecordUids);
        records.sort(Comparator.reverseOrder());

        AccountBillingRecord latest = records.get(0);
        AccountBillingRecord earliest = records.get(records.size() - 1);

        Account account = latest.getAccount();
        Instant priorPeriodStart = earliest.getBilledPeriodStart().minus(1, ChronoUnit.DAYS); // since the prior statement might have been a day or two earlier

        if (latest.getStatementDateTime() == null) {
            throw new IllegalArgumentException("Errror! Latest bill must be a statement generating record");
        }

        List<AccountBillingRecord> priorPaidBills = billingRepository.findAll(Specifications.where(forAccount(account))
                .and(createdBetween(priorPeriodStart, earliest.getBilledPeriodStart(), false))
                .and(isPaid(true)));

        if (priorPaidBills != null && !priorPaidBills.isEmpty()) {
            priorPaidBills.sort(Comparator.reverseOrder());
            AccountBillingRecord priorRecord = priorPaidBills.get(0);

            pdfFormFieldMap.get("lastBilledAmountDescription").setValue(String.format("Last invoice for R%s, dated %s",
                    amountFormat.format((double) priorRecord.getTotalAmountToPay() / 100), formatAtSAST(priorRecord.getCreatedDateTime(), dateHeader)));

            pdfFormFieldMap.get("lastBilledAmount").setValue(amountFormat.format((double) priorRecord.getTotalAmountToPay() / 100));
            if (priorRecord.getPaid() && priorRecord.getPaidAmount() != null) {
                pdfFormFieldMap.get("lastPaymentAmountReceived").setValue(String.format("Payment received by credit card on %s, " +
                        "thank you", formatAtSAST(priorRecord.getPaidDate(), dateHeader)));
                pdfFormFieldMap.get("lastPaidAmount").setValue(amountFormat.format((double) priorRecord.getPaidAmount() / 100));
            }
        }

        pdfFormFieldMap.get("invoiceNumber").setValue("INVOICE NO " + latest.getId());
        pdfFormFieldMap.get("invoiceDate").setValue(formatAtSAST(latest.getStatementDateTime(), dateHeader));
        pdfFormFieldMap.get("billedUserName").setValue(latest.getAccount().getBillingUser().getDisplayName());
        pdfFormFieldMap.get("emailAddress").setValue(String.format("Email: %s", account.getBillingUser().getEmailAddress()));
        pdfFormFieldMap.get("priorBalance").setValue(amountFormat.format((double) latest.getOpeningBalance() / 100));
        pdfFormFieldMap.get("thisBillItems1").setValue(String.format("Monthly subscription for '%s' account",
                latest.getAccount().getType().name().toLowerCase()));

        pdfFormFieldMap.get("billedAmount1").setValue(amountFormat
                .format((double) latest.getAmountBilledThisPeriod() / 100));

        pdfFormFieldMap.get("totalAmountToPay").setValue(amountFormat
                .format((double) latest.getTotalAmountToPay() / 100));

        // todo: reintroduce these fields if needed
        //pdfFormFieldMap.get("footerTextPaymentDate").setValue(String.format("The amount due will be automatically charged to " +
                //"your card on %s", formatAtSAST(latest.getNextPaymentDate(), dateHeader)));
        //fields.setField("footerTextPaymentDate", String.format("The amount due will be automatically charged to " +
                //"your card on %s", formatAtSAST(latest.getNextPaymentDate(), dateHeader)));

        pdfAcroForm.flattenFields();
        myDocument.close();
        pdfReader.close();

        logger.info("Invoice PDF generated, returning ... ");
        return tempStorage;

    } catch (IOException e) {
        logger.warn("Could not find template path! Input: {}", folderPath);
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:grassrootza,项目名称:grassroot-platform,代码行数:80,代码来源:PdfGeneratingServiceImpl.java



注:本文中的com.itextpdf.kernel.pdf.PdfDocument类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Node类代码示例发布时间:2022-05-23
下一篇:
Java VertxMetrics类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap