當前位置: 首頁>>代碼示例>>Java>>正文


Java PDDocument.writeTo方法代碼示例

本文整理匯總了Java中org.sejda.sambox.pdmodel.PDDocument.writeTo方法的典型用法代碼示例。如果您正苦於以下問題:Java PDDocument.writeTo方法的具體用法?Java PDDocument.writeTo怎麽用?Java PDDocument.writeTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.sejda.sambox.pdmodel.PDDocument的用法示例。


在下文中一共展示了PDDocument.writeTo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doWritePDF

import org.sejda.sambox.pdmodel.PDDocument; //導入方法依賴的package包/類
static void doWritePDF(PDDocument document, PDImageXObject ximage, File testResultsDir,
        String filename) throws IOException
{
    File pdfFile = new File(testResultsDir, filename);

    // This part isn't really needed because this test doesn't break
    // if the mask has the wrong colorspace (PDFBOX-2057), but it is still useful
    // if something goes wrong in the future and we want to have a PDF to open.

    PDPage page = new PDPage();
    document.addPage(page);
    PDPageContentStream contentStream = new PDPageContentStream(document, page,
            AppendMode.APPEND, false);
    contentStream.drawImage(ximage, 150, 300);
    contentStream.drawImage(ximage, 200, 350);
    contentStream.close();

    // check that the resource map is up-to-date
    assertEquals(1, count(document.getPage(0).getResources().getXObjectNames()));

    document.writeTo(pdfFile);
    document.close();

    try (PDDocument doc = PDFParser.parse(SeekableSources.seekableSourceFrom(pdfFile)))
    {
        assertEquals(1, count(doc.getPage(0).getResources().getXObjectNames()));
        new PDFRenderer(doc).renderImage(0);
    }

}
 
開發者ID:torakiki,項目名稱:sambox,代碼行數:31,代碼來源:ValidateXImage.java

示例2: validateCIDFontType2

import org.sejda.sambox.pdmodel.PDDocument; //導入方法依賴的package包/類
private void validateCIDFontType2(boolean useSubset) throws Exception
{
    PDDocument document = new PDDocument();
    PDPage page = new PDPage(PDRectangle.A4);
    document.addPage(page);

    InputStream input = TestFontEmbedding.class.getClassLoader().getResourceAsStream(
            "org/sejda/sambox/ttf/LiberationSans-Regular.ttf");
    PDType0Font font = PDType0Font.load(document, input, useSubset);

    PDPageContentStream stream = new PDPageContentStream(document, page);

    stream.beginText();
    stream.setFont(font, 12);

    String text = "Unicode русский язык Tiếng Việt";
    stream.newLineAtOffset(50, 600);
    stream.showText(text);

    stream.endText();
    stream.close();
    
    File file = new File(OUT_DIR, "CIDFontType2.pdf");
    document.writeTo(file);
    document.close();

    // check that the extracted text matches what we wrote
    try (PDDocument document2 = PDFParser.parse(SeekableSources.seekableSourceFrom(file)))
    {
        PDFTextStripper stripper = new PDFTextStripper();
        assertEquals(text, stripper.getText(document2).trim());
    }
}
 
開發者ID:torakiki,項目名稱:sambox,代碼行數:34,代碼來源:TestFontEmbedding.java


注:本文中的org.sejda.sambox.pdmodel.PDDocument.writeTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。