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


Java COSVisitorException类代码示例

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


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

示例1: test

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
@Test
public void test() throws IOException, COSVisitorException {

	PDDocument doc = new PDDocument();
	PDPage page = new PDPage();
	doc.addPage(page);
	PDPageContentStream contentStream = new PDPageContentStream(doc, page);

	String[][] content = { { "Team", "Captain" },
			{ "Hull City", "Robert Koren" },
			{ "Aston Villa", "Ron Vlaar" },
			{ "Manchester United", "Nemanja Vidic" },
			{ "Manchester City", "Vincent Kompany" } };

	drawTable(page, contentStream, 700, 100, content);

	contentStream.close();
	Path outputFilePath = Files.createTempFile("Test-CaptainTeam-Table", ".pdf");
	doc.save(outputFilePath.toFile());
	logger.info("test# "+ outputFilePath.toAbsolutePath().toString());

}
 
开发者ID:rmohta,项目名称:pdfboxExamples,代码行数:23,代码来源:PdfTable.java

示例2: createTestDocument

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
byte[] createTestDocument() throws IOException, COSVisitorException
{
    try (   ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PDDocument doc = new PDDocument()   )
    {
        PDPage page = new PDPage(new PDRectangle(792, 612));
        doc.addPage(page);
        
        PDFont font = PDType1Font.COURIER;

        PDPageContentStream contents = new PDPageContentStream(doc, page);
        contents.beginText();
        contents.setFont(font, 9);
        contents.moveTextPositionByAmount(100, 500);
        contents.drawString("             2                                                                  Netto        5,00 EUR 3,00");
        contents.moveTextPositionByAmount(0, 0);
        contents.drawString("                2882892  ENERGIZE LR6 Industrial                     2,50 EUR 1");
        contents.endText();
        contents.close();
        
        doc.save(baos);
        
        return baos.toByteArray();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:26,代码来源:ExtractWithoutExtraSpaces.java

示例3: splitToExamPapersWithPDFStreams

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
/**
 * Splits a PDF-document into exam papers.
 *
 * @param pdfStream PDF-file as InputStream
 * @return A List of ExamPapers.
 * @throws IOException If InputStream can not be read or stream doesn't
 * contain a PDF-format file.
 * @throws DocumentException If document contains odd number of pages.
 * @throws PdfException If a document is not in the right format or error
 * occurs while loading or splitting or document has an odd number of pages.
 * @throws COSVisitorException if something goes wrong when visiting a PDF
 * object.
 */
public List<ExamPaper> splitToExamPapersWithPDFStreams(InputStream pdfStream) throws IOException, DocumentException, PdfException, COSVisitorException {
    PDDocument allPdfDocument = PDDocument.load(pdfStream);
    if (allPdfDocument.getNumberOfPages() % 2 != 0) {
        throw new DocumentException("Odd number of pages");
    }
    Splitter splitter = new Splitter();
    splitter.setSplitAtPage(2);
    List<PDDocument> pdfDocuments = splitter.split(allPdfDocument);
    ArrayList<ExamPaper> examPapers = new ArrayList<>();
    for (PDDocument pdfDocument : pdfDocuments) {
        ExamPaper paper = new ExamPaper();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        pdfDocument.save(out);
        byte[] data = out.toByteArray();
        paper.setPdf(data);
        examPapers.add(paper);
        pdfDocument.close();
    }
    allPdfDocument.close();
    return examPapers;
}
 
开发者ID:ohtuprojekti,项目名称:OKKoPa,代码行数:35,代码来源:PDFSplitter.java

示例4: saveDocument

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
@Override
public void saveDocument(List<Page> pages, File file) throws IOException {
	if (pages.size() == 0) {
		throw new IOException("Empty document.");
	}
	
	PDDocument outDoc = new PDDocument();
	
	Map<File,PDDocument> docs = new HashMap<File,PDDocument>();
	try {
		for (Page page : pages) {
			PDDocument pageDoc = docs.get(page.getFile());
			if (pageDoc == null) {
				pageDoc = PDDocument.load(page.getFile());
				docs.put(page.getFile(), pageDoc);
			}
			
			outDoc.addPage((PDPage)pageDoc.getPrintable(page.getIndex()));
		}
		
		try {
			outDoc.save(file.toString());
		}
		catch (COSVisitorException e) {
			throw new IOException(e);
		}
	}
	finally {
		outDoc.close();
		for (PDDocument doc : docs.values()) {
			doc.close();
		}
	}
}
 
开发者ID:mgropp,项目名称:pdfjumbler,代码行数:35,代码来源:PdfEditor.java

示例5: main

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, COSVisitorException {
String filename = args[0];
File f = new File(filename);
String outname = f.getName() + ".pdf";
Optional<Packlist> packlist = Packlist.from(new FileInputStream(f));
if (packlist.isPresent()) {
	//Initialize Document
       PDDocument doc = new PDDocument();	           
       ZebraTable table = createTable(doc, packlist.get());
       table.draw();
	
       //Close Stream and save pdf
       File file = new File(outname);
       System.out.println("Sample file saved at : " + file.getAbsolutePath());
       Files.createParentDirs(file);
       doc.save(file);
       doc.close();
}
  }
 
开发者ID:sorcut3141,项目名称:FBAPacklistPrinter,代码行数:20,代码来源:LabelTest.java

示例6: main

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, GeneralSecurityException, SignatureException, COSVisitorException {
    char[] password = "123456".toCharArray();

    KeyStore keystore = KeyStore.getInstance("PKCS12");
    keystore.load(new FileInputStream("/home/user/Desktop/keystore.p12"), password);

    Enumeration<String> aliases = keystore.aliases();
    String alias;
    if (aliases.hasMoreElements()) {
        alias = aliases.nextElement();
    } else {
        throw new KeyStoreException("Keystore is empty");
    }
    privateKey = (PrivateKey) keystore.getKey(alias, password);
    Certificate[] certificateChain = keystore.getCertificateChain(alias);
    certificate = certificateChain[0];

    File inFile = new File("/home/user/Desktop/sign.pdf");
    File outFile = new File("/home/user/Desktop/sign_signed.pdf");
    new CreateSignature().signPdf(inFile, outFile);
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:22,代码来源:CreateSignature.java

示例7: main

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
public static void main(String[] args) throws COSVisitorException, IOException
{
    InputStream sourceStream = new FileInputStream("src/test/resources/mkl/testarea/pdfbox1/assembly/pdf-test.pdf");
    InputStream overlayStream = new FileInputStream("src/test/resources/mkl/testarea/pdfbox1/assembly/draft1.pdf");
    try {
        final PDDocument document = PDDocument.load(sourceStream);
        final PDDocument overlay = PDDocument.load(overlayStream);

        overlayWithDarkenBlendMode(document, overlay);

        document.save(new File(RESULT_FOLDER, "da-draft-5.pdf").toString());
        document.close();
    }
    finally {
        sourceStream.close();
        overlayStream.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:19,代码来源:OverlayWithEffect.java

示例8: createRollover

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
void createRollover(PDAnnotation annotation, String filename) throws IOException, COSVisitorException
{
    PDDocument document = new PDDocument();
    PDPage page = new PDPage();
    document.addPage(page);
    List<PDAnnotation> annotations = page.getAnnotations();

    float x = 100;
    float y = 500;
    String text = "PDFBox";
    PDFont font = PDType1Font.HELVETICA_BOLD;
    float textWidth = font.getStringWidth(text) / 1000 * 18;

    PDPageContentStream contents = new PDPageContentStream(document, page);
    contents.beginText();
    contents.setFont(font, 18);
    contents.moveTextPositionByAmount(x, y);
    contents.drawString(text);
    contents.endText();
    contents.close();

    PDAppearanceDictionary appearanceDictionary = new PDAppearanceDictionary();
    PDAppearanceStream normal = createAppearanceStream(document, textWidth, font, "0.5 0.5 0.5 rg");
    PDAppearanceStream rollover = createAppearanceStream(document, textWidth, font, "1 0.7 0.5 rg");
    PDAppearanceStream down = createAppearanceStream(document, textWidth, font, "0 0 0 rg");
    appearanceDictionary.setNormalAppearance(normal);
    appearanceDictionary.setRolloverAppearance(rollover);
    appearanceDictionary.setDownAppearance(down);
    annotation.setAppearance(appearanceDictionary);

    PDRectangle position = new PDRectangle();
    position.setLowerLeftX(x);
    position.setLowerLeftY(y - 5);
    position.setUpperRightX(x + textWidth);
    position.setUpperRightY(y + 20);
    annotation.setRectangle(position);

    annotations.add(annotation);
    document.save(new File(RESULT_FOLDER, filename));
    document.close();
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:42,代码来源:RolloverAnnotation.java

示例9: createVisibleSignature

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
void createVisibleSignature(File document, File ksFile, char[] pin, InputStream image, String signatureFieldName) throws IOException, COSVisitorException, SignatureException, GeneralSecurityException
{
    KeyStore keystore = KeyStore.getInstance("PKCS12", provider);
    keystore.load(new FileInputStream(ksFile), pin);

    CreateVisibleSignature signing = new CreateVisibleSignature(keystore, pin.clone());

    PDVisibleSignDesigner visibleSig = new PDVisibleSignDesigner(document.getAbsolutePath(), image, 1);
    visibleSig.xAxis(0).yAxis(0).zoom(-50).signatureFieldName(signatureFieldName);

    PDVisibleSigProperties signatureProperties = new PDVisibleSigProperties();

    signatureProperties.signerName("name").signerLocation("location").signatureReason("Security").preferredSize(0)
        .page(1).visualSignEnabled(true).setPdVisibleSignature(visibleSig).buildSignature();

    signing.signPDF(document, signatureProperties);
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:18,代码来源:SignLikePdfboxExample.java

示例10: testOriginalA

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
@Test
public void testOriginalA() throws IOException, COSVisitorException, SignatureException
{
    CreateVisibleSignature signing = new CreateVisibleSignature(
            keystore, password.clone());
    InputStream image = getClass().getResourceAsStream("Willi-1.jpg");
    PDVisibleSignDesigner visibleSig = new PDVisibleSignDesigner(
            document.toString(), image, 1);
    visibleSig.xAxis(0).yAxis(0).zoom(-75)
            .signatureFieldName("ApplicantSignature"); // ("topmostSubform[0].Page3[0].SignatureField1[0]")
    PDVisibleSigProperties signatureProperties = new PDVisibleSigProperties();
    signatureProperties.signerName("name").signerLocation("location")
            .signatureReason("Security").preferredSize(0).page(3)
            .visualSignEnabled(true).setPdVisibleSignature(visibleSig)
            .buildSignature();
    signing.signPDF(document, signatureProperties);
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:18,代码来源:SignLikeDenisMP.java

示例11: testDummySignInMemory

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/29123436/how-to-sign-an-inputstream-from-a-pdf-file-with-pdfbox-2-0-0">
 * How to sign an InputStream from a PDF file with PDFBox 2.0.0
 * </a>
 * 
 * Test the equivalent for PDFBox 1.8.8. Works alright.
 */
@Test
public void testDummySignInMemory() throws IOException, COSVisitorException, SignatureException
{
    try (   InputStream sourceStream = getClass().getResourceAsStream("/mkl/testarea/pdfbox1/assembly/document1.pdf");
            OutputStream output = new FileOutputStream(new File(RESULT_FOLDER, "document1-with-dummy-sig.pdf")))
    {
        byte[] input = IOUtils.toByteArray(sourceStream);
        output.write(input);
        signDetached(input, output, new SignatureInterface()
                {
                    @Override
                    public byte[] sign(InputStream content) throws SignatureException, IOException
                    {
                        return "Test".getBytes();
                    }
                });
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:26,代码来源:SignInMemory.java

示例12: signDetached

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
void signDetached(byte[] pdf, OutputStream output, SignatureInterface signatureInterface)throws IOException, SignatureException, COSVisitorException
{
    PDDocument document = PDDocument.load(new ByteArrayInputStream(pdf));
    // create signature dictionary
    PDSignature signature = new PDSignature();
    signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
    signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
    signature.setName("Example User");
    signature.setLocation("Los Angeles, CA");
    signature.setReason("Testing");
    // TODO extract the above details from the signing certificate? Reason as a parameter?

    // the signing date, needed for valid signature
    signature.setSignDate(Calendar.getInstance());

    // register signature dictionary and sign interface
    document.addSignature(signature, signatureInterface);

    // write incremental (only for signing purpose)
    document.saveIncremental(new ByteArrayInputStream(pdf), output);
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:22,代码来源:SignInMemory.java

示例13: test

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
void test(String resourceName, File resultFile) throws IOException, COSVisitorException, CertificateEncodingException
{
    try (   InputStream source = getClass().getResourceAsStream(resourceName);
            FileOutputStream fos = new FileOutputStream(resultFile);
            FileInputStream fis = new FileInputStream(resultFile);
            )
    {
        List<byte[]> certificates = new ArrayList<byte[]>();
        for (int i = 0; i < cert.length; i++)
            certificates.add(cert[i].getEncoded());
        COSDictionary dss = createDssDictionary(certificates, null, null);

        byte inputBytes[] = IOUtils.toByteArray(source);

        PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(inputBytes));
        PDDocumentCatalog catalog = pdDocument.getDocumentCatalog();
        catalog.getCOSObject().setNeedToBeUpdate(true);
        catalog.getCOSDictionary().setItem(COSName.getPDFName("DSS"), dss);

        fos.write(inputBytes);
        pdDocument.saveIncremental(fis, fos);
        pdDocument.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:25,代码来源:AddValidationRelatedInformation.java

示例14: testDrunkenFistSample

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
/**
 * Applying the code to the OP's sample file from a former question.
 * 
 * @throws IOException
 * @throws CryptographyException
 * @throws COSVisitorException
 */
@Test
public void testDrunkenFistSample() throws IOException, CryptographyException, COSVisitorException
{
    try (   InputStream resource = getClass().getResourceAsStream("sample.pdf");
            InputStream left = getClass().getResourceAsStream("left.png");
            InputStream right = getClass().getResourceAsStream("right.png");
            PDDocument document = PDDocument.load(resource) )
    {
        if (document.isEncrypted())
        {
            document.decrypt("");
        }
        
        PDJpeg leftImage = new PDJpeg(document, ImageIO.read(left));
        PDJpeg rightImage = new PDJpeg(document, ImageIO.read(right));

        ImageLocator locator = new ImageLocator();
        List<?> allPages = document.getDocumentCatalog().getAllPages();
        for (int i = 0; i < allPages.size(); i++)
        {
            PDPage page = (PDPage) allPages.get(i);
            locator.processStream(page, page.findResources(), page.getContents().getStream());
        }

        for (ImageLocation location : locator.getLocations())
        {
            PDRectangle cropBox = location.getPage().findCropBox();
            float center = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2.0f;
            PDJpeg image = location.getMatrix().getXPosition() < center ? leftImage : rightImage;
            AffineTransform transform = location.getMatrix().createAffineTransform();

            PDPageContentStream content = new PDPageContentStream(document, location.getPage(), true, false, true);
            content.drawXObject(image, transform);
            content.close();
        }

        document.save(new File(RESULT_FOLDER, "sample-changed.pdf"));
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:47,代码来源:OverwriteImage.java

示例15: testDrawEuro

import org.apache.pdfbox.exceptions.COSVisitorException; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/22260344/pdfbox-encode-symbol-currency-euro">
 * PdfBox encode symbol currency euro
 * </a>
 * <p>
 * Three ways of trying to draw a '�' symbol, the first one fails.
 * </p>
 */
@Test
public void testDrawEuro() throws IOException, COSVisitorException
{
    PDDocument document = new PDDocument();
    PDPage page = new PDPage();
    document.addPage(page);
    PDPageContentStream contents = new PDPageContentStream(document, page);
    PDFont font = PDType1Font.HELVETICA_BOLD;
    contents.beginText();
    contents.setFont(font, 18);
    contents.moveTextPositionByAmount(30, 600);
    contents.drawString("�");
    contents.moveTextPositionByAmount(0, -30);
    contents.drawString(String.valueOf(Character.toChars(EncodingManager.INSTANCE.getEncoding(COSName.WIN_ANSI_ENCODING).getCode("Euro"))));
    contents.moveTextPositionByAmount(0, -30);
    byte[] commands = "(x) Tj ".getBytes();
    commands[1] = (byte) 128;
    contents.appendRawCommands(commands);
    contents.endText();
    contents.close();
    document.save(new File(RESULT_FOLDER, "Euro.pdf"));
    document.close();
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:32,代码来源:DrawSpecialCharacters.java


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