当前位置: 首页>>代码示例>>Java>>正文


Java PdfImportedPage类代码示例

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


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

示例1: testRotateAndZoomUpperHalfPage

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/35374110/how-do-i-use-itext-to-have-a-landscaped-pdf-on-half-of-a-a4-back-to-portrait-and">
 * How do i use iText to have a landscaped PDF on half of a A4 back to portrait and full size on A4
 * </a>
 * <p>
 * This sample shows how to rotate and enlarge the upper half of an A4 page to fit into a new A4 page.
 * </p>
 */
@Test
public void testRotateAndZoomUpperHalfPage() throws IOException, DocumentException
{
    try (   InputStream resource = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/test.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "test-upperHalf.pdf"))   )
    {
        PdfReader reader = new PdfReader(resource);
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, result);
        document.open();

        double sqrt2 = Math.sqrt(2);
        Rectangle pageSize = reader.getPageSize(1);
        PdfImportedPage importedPage = writer.getImportedPage(reader, 1);
        writer.getDirectContent().addTemplate(importedPage, 0, sqrt2, -sqrt2, 0, pageSize.getTop() * sqrt2, -pageSize.getLeft() * sqrt2);
        
        document.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:28,代码来源:EnlargePagePart.java

示例2: split

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
public List<byte[]> split(byte[] input) throws IOException, DocumentException {
    PdfReader pdfReader = new PdfReader(input);
    List<byte[]> pdfFiles = new ArrayList<>();
    int pageCount = pdfReader.getNumberOfPages();
    int pageIndex = 0;
    while (++pageIndex <= pageCount) {
        Document document = new Document(pdfReader.getPageSizeWithRotation(pageIndex));
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        PdfCopy pdfCopy = new PdfSmartCopy(document, byteArrayOutputStream);
        pdfCopy.setFullCompression();
        PdfImportedPage pdfImportedPage = pdfCopy.getImportedPage(pdfReader, pageIndex);
        document.open();
        pdfCopy.addPage(pdfImportedPage);
        document.close();
        pdfCopy.close();
        pdfFiles.add(byteArrayOutputStream.toByteArray());
    }
    return pdfFiles;
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:20,代码来源:SplitSmart.java

示例3: createMultiUseIndirectTextPdf

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
static byte[] createMultiUseIndirectTextPdf() throws DocumentException, IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    document.open();
    PdfReader reader = new PdfReader(createSimpleTextPdf());
    PdfImportedPage template = writer.getImportedPage(reader, 1);
    Rectangle pageSize = reader.getPageSize(1);
    writer.getDirectContent().addTemplate(template, 0, .7f, -.7f, 0, pageSize.getRight(), (pageSize.getTop() + pageSize.getBottom()) / 2);
    writer.getDirectContent().addTemplate(template, 0, .7f, -.7f, 0, pageSize.getRight(), pageSize.getBottom());
    document.newPage();
    writer.getDirectContent().addTemplate(template, pageSize.getLeft(), pageSize.getBottom());
    document.close();

    return baos.toByteArray();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:19,代码来源:SimpleRedactionTest.java

示例4: getImageByFile

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
public ImageInstance getImageByFile( PdfContentByte cb , File file ) throws IOException, BadElementException{
	Image image = null;
	ImageInstance instance = null;
	if( file.getName().toLowerCase().endsWith( ".pdf")){	
		PdfReader reader = new PdfReader( file.getAbsolutePath() );
		PdfImportedPage p = cb.getPdfWriter().getImportedPage(reader, 1);
		image = Image.getInstance(p);
		instance = new ImageInstance(image, reader);
	}else{
		image = Image.getInstance( file.getAbsolutePath() );
		instance = new ImageInstance(image, null);
	}
	
	instances.add(instance);
	

	return instance;
}
 
开发者ID:Billes,项目名称:pdf-renderer,代码行数:19,代码来源:ImageFactory.java

示例5: split

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
void split(PdfReader reader, int page) throws IOException
{
    PdfImportedPage importedPage = writer.getImportedPage(reader, page);

    Rectangle pageSizeToImport = reader.getPageSize(page);
    Iterable<Rectangle> rectangles = determineSplitRectangles(reader, page);

    for (Rectangle rectangle : rectangles) {
        newPage(rectangle);
        PdfContentByte directContent = writer.getDirectContent();
        directContent.saveState();
        directContent.rectangle(rectangle.getLeft(), rectangle.getBottom(), rectangle.getWidth(), rectangle.getHeight());
        directContent.clip();
        directContent.newPath();

        writer.getDirectContent().addTemplate(importedPage, -pageSizeToImport.getLeft(), -pageSizeToImport.getBottom());

        directContent.restoreState();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:21,代码来源:Abstract2DPdfPageSplittingTool.java

示例6: merge

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
void merge(PdfReader reader, PdfReaderContentParser parser, int page) throws IOException
{
    TextMarginFinder finder = parser.processContent(page, new TextMarginFinder());
    Rectangle pageSizeToImport = reader.getPageSize(page);
    float heightToImport = finder.getHeight();
    float maxHeight = pageSize.getHeight() - topMargin - bottomMargin;
    if (heightToImport > maxHeight)
    {
        throw new IllegalArgumentException(String.format("Page %s content too large; height: %s, limit: %s.", page, heightToImport, maxHeight));
    }

    if (heightToImport > yPosition - pageSize.getBottom(bottomMargin))
    {
        newPage();
    }
    else if (!writer.isPageEmpty())
    {
        heightToImport += gap;
    }
    yPosition -= heightToImport;

    PdfImportedPage importedPage = writer.getImportedPage(reader, page);
    writer.getDirectContent().addTemplate(importedPage, 0, yPosition - (finder.getLly() - pageSizeToImport.getBottom()));
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:25,代码来源:PdfDenseMergeTool.java

示例7: ExtractPages

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
public static byte[] ExtractPages(String pdfDocument, int startPage, int endPage) throws IOException, DocumentException
{
    try (InputStream pdfDocumentStream = SmartMerging.class.getResourceAsStream(pdfDocument))
    {
        PdfReader reader = new PdfReader(pdfDocumentStream);
        int numberOfPages = reader.getNumberOfPages();
        int endPageResolved = endPage > 0 ? endPage : numberOfPages;
        if (startPage > numberOfPages || endPageResolved > numberOfPages)
            System.err.printf("Error: page indices (%s, %s) out of bounds. Document has {2} pages.", startPage, endPageResolved, numberOfPages);

        byte[] outputDocument;
        try (ByteArrayOutputStream msOut = new ByteArrayOutputStream())
        {
            Document doc = new Document();
            PdfCopy pdfCopyProvider = new PdfCopy(doc, msOut);
            doc.open();
            for (int i = startPage; i <= endPageResolved; i++)
            {
                PdfImportedPage page = pdfCopyProvider.getImportedPage(reader, i);
                pdfCopyProvider.addPage(page);
            }
            doc.close();
            reader.close();
            outputDocument = msOut.toByteArray();
        }

        return outputDocument;
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:30,代码来源:SmartMerging.java

示例8: createRotatedIndirectTextPdf

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
static byte[] createRotatedIndirectTextPdf() throws DocumentException, IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    document.open();
    PdfReader reader = new PdfReader(createSimpleTextPdf());
    PdfImportedPage template = writer.getImportedPage(reader, 1);
    Rectangle pageSize = reader.getPageSize(1);
    writer.getDirectContent().addTemplate(template, .7f, .7f, -.7f, .7f, 400, -200);
    document.newPage();
    writer.getDirectContent().addTemplate(template, pageSize.getLeft(), pageSize.getBottom());
    document.close();

    return baos.toByteArray();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:18,代码来源:SimpleRedactionTest.java

示例9: copyToMultiplePages

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
private static File copyToMultiplePages(CropJob cropJob) throws IOException, DocumentException {

		PdfReader reader = new PdfReader(cropJob.getSource().getAbsolutePath());
		Document document = new Document();

		File resultFile = File.createTempFile("cropped", ".pdf");
		PdfSmartCopy pdfCopy = new PdfSmartCopy(document, new FileOutputStream(resultFile));
		document.open();
		PdfImportedPage page;

		for (int pageNumber = 1; pageNumber <= cropJob.getSourcePageCount(); pageNumber++) {
			SingleCluster currentCluster = cropJob.getClusterCollection().getSingleCluster(pageNumber);
			page = pdfCopy.getImportedPage(reader, pageNumber);
			pdfCopy.addPage(page);
			for (int j = 1; j < currentCluster.getRatiosList().size(); j++) {
				pdfCopy.addPage(page);
			}
		}
		document.close();
		pdfCopy.close();
		reader.close();
		return resultFile;
	}
 
开发者ID:mbaeuerle,项目名称:Briss-2.0,代码行数:24,代码来源:CropManager.java

示例10: createPdf

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
public void createPdf(String filename) throws DocumentException, IOException {

		Document document = new Document(PageSize.LETTER);
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
		document.open();

		PdfPTable table = new PdfPTable(2);
		PdfReader reader = new PdfReader(T08_Chapter.RESULT);
		int n = reader.getNumberOfPages();
		for (int pageNumber = 1; pageNumber <= n; pageNumber++) {

			// TODO: import page as image
			PdfImportedPage page = writer.getImportedPage(reader, pageNumber);
			table.addCell(Image.getInstance(page));
		}
		document.add(table);

		document.close();
	}
 
开发者ID:kohmiho,项目名称:iTextTutorial,代码行数:20,代码来源:T12_ImportPages.java

示例11: add

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
public void add(byte[] pdfByteArray)
{
	try
	{
		PdfReader reader = new PdfReader(pdfByteArray);
		int numberOfPages = reader.getNumberOfPages();

		if (this.document == null)
		{
			this.document = new Document(reader.getPageSizeWithRotation(1));
			this.writer = new PdfCopy(this.document, this.getOutputStream());
			this.document.open();
		}
		PdfImportedPage page;
		for (int i = 0; i < numberOfPages;)
		{
			++i;
			page = this.writer.getImportedPage(reader, i);
			this.writer.addPage(page);
		}
		PRAcroForm acroForm = reader.getAcroForm();
		if (acroForm != null)
		{
			this.writer.copyAcroForm(reader);
		}
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
}
 
开发者ID:oopcell,项目名称:AvoinApotti,代码行数:32,代码来源:CatsReferralReportBuilder.java

示例12: split

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
void split(PdfReader reader, int page) throws IOException
{
    PdfImportedPage importedPage = writer.getImportedPage(reader, page);
    PdfContentByte directContent = writer.getDirectContent();
    yPosition = pageSize.getTop();

    Rectangle pageSizeToImport = reader.getPageSize(page);
    float[] borderPositions = determineSplitPositions(reader, page);
    if (borderPositions == null || borderPositions.length < 2)
        return;

    for (int borderIndex = 0; borderIndex + 1 < borderPositions.length; borderIndex++) {
        float height = borderPositions[borderIndex] - borderPositions[borderIndex + 1];
        if (height <= 0)
            continue;

        directContent.saveState();
        directContent.rectangle(0, yPosition - height, pageSizeToImport.getWidth(), height);
        directContent.clip();
        directContent.newPath();

        writer.getDirectContent().addTemplate(importedPage, 0, yPosition - (borderPositions[borderIndex] - pageSizeToImport.getBottom()));

        directContent.restoreState();
        newPage();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:28,代码来源:AbstractPdfPageSplittingTool.java

示例13: testWithWriter

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
@Test
public void testWithWriter() throws DocumentException, IOException
{
    InputStream resourceStream = getClass().getResourceAsStream("test.pdf");
    try
    {
        PdfReader reader = new PdfReader(resourceStream);
        Rectangle pageSize = reader.getPageSize(1);

        Rectangle rect = getOutputPageSize(pageSize, reader, 1);

        Document document = new Document(rect, 0, 0, 0, 0);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "test-trimmed-writer.pdf")));

        document.open();
        PdfImportedPage page;

        // Go through all pages
        int n = reader.getNumberOfPages();
        for (int i = 1; i <= n; i++)
        {
            document.newPage();
            page = writer.getImportedPage(reader, i);
            System.out.println("BBox:  "+ page.getBoundingBox().toString());
            Image instance = Image.getInstance(page);
            document.add(instance);
            Rectangle outputPageSize = document.getPageSize();
            System.out.println(outputPageSize.toString());
        }
        document.close();
    }
    finally
    {
        if (resourceStream != null)
            resourceStream.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:38,代码来源:TestTrimPdfPage.java

示例14: splitIntoHalfPages

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
/**
 * This methods creates a copy of the source document containing each page twice,
 * once with the cropbox limited to the left half page, once to the right one.
 */
void splitIntoHalfPages(InputStream source, File target) throws IOException, DocumentException
{
    final PdfReader reader = new PdfReader(source);
    
    try (   OutputStream targetStream = new FileOutputStream(target)    )
    {
        Document document = new Document();
        PdfCopy copy = new PdfCopy(document, targetStream);
        document.open();

        for (int page = 1; page <= reader.getNumberOfPages(); page++)
        {
            PdfDictionary pageN = reader.getPageN(page);
            Rectangle cropBox = reader.getCropBox(page);
            PdfArray leftBox = new PdfArray(new float[]{cropBox.getLeft(), cropBox.getBottom(), (cropBox.getLeft() + cropBox.getRight()) / 2.0f, cropBox.getTop()});
            PdfArray rightBox = new PdfArray(new float[]{(cropBox.getLeft() + cropBox.getRight()) / 2.0f, cropBox.getBottom(), cropBox.getRight(), cropBox.getTop()});

            PdfImportedPage importedPage = copy.getImportedPage(reader, page);
            pageN.put(PdfName.CROPBOX, leftBox);
            copy.addPage(importedPage);
            pageN.put(PdfName.CROPBOX, rightBox);
            copy.addPage(importedPage);
        }
        
        document.close();
    }
    finally
    {
        reader.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:36,代码来源:SplitIntoHalfPages.java

示例15: Merge

import com.itextpdf.text.pdf.PdfImportedPage; //导入依赖的package包/类
public static byte[] Merge(File[] documentPaths) throws IOException, DocumentException
{
    byte[] mergedDocument;

    try (ByteArrayOutputStream memoryStream = new ByteArrayOutputStream())
    {
        Document document = new Document();
        PdfSmartCopy pdfSmartCopy = new PdfSmartCopy(document, memoryStream);
        document.open();

        for (File docPath : documentPaths)
        {
            PdfReader reader = new PdfReader(docPath.toString());
            try
            {
                reader.consolidateNamedDestinations();
                int numberOfPages = reader.getNumberOfPages();
                for (int page = 0; page < numberOfPages;)
                {
                    PdfImportedPage pdfImportedPage = pdfSmartCopy.getImportedPage(reader, ++page);
                    pdfSmartCopy.addPage(pdfImportedPage);
                }
            }
            finally
            {
                reader.close();
            }
        }

        document.close();
        mergedDocument = memoryStream.toByteArray();
    }

    return mergedDocument;
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:36,代码来源:SmartMerging.java


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