本文整理汇总了Java中org.apache.pdfbox.io.IOUtils.copy方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java IOUtils.copy怎么用?Java IOUtils.copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.io.IOUtils
的用法示例。
在下文中一共展示了IOUtils.copy方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bigGeneratorTest
import org.apache.pdfbox.io.IOUtils; //导入方法依赖的package包/类
@Test
@Ignore("for generation and manual testing")
public void bigGeneratorTest() throws Exception {
SignatureImageParameters signatureImageParameters = createSignatureImageParameters();
for (SignatureImageParameters.VisualSignatureRotation rotation : SignatureImageParameters.VisualSignatureRotation.values()) {
for (SignatureImageParameters.VisualSignatureAlignmentHorizontal horizontal : SignatureImageParameters.VisualSignatureAlignmentHorizontal
.values()) {
for (SignatureImageParameters.VisualSignatureAlignmentVertical vertical : SignatureImageParameters.VisualSignatureAlignmentVertical.values()) {
signatureImageParameters.setRotation(rotation);
signatureImageParameters.setAlignmentHorizontal(horizontal);
signatureImageParameters.setAlignmentVertical(vertical);
String[] pdfs = new String[] { "normal", "90", "180", "270" };
for (String pdf : pdfs) {
DSSDocument document = sign(signablePdfs.get(pdf));
File checkPdfFile = new File(
"target/pdf/check_" + rotation.name() + "_" + pdf + "_" + horizontal.name() + "_" + vertical.name() + ".pdf");
checkPdfFile.getParentFile().mkdirs();
IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));
}
}
}
}
}
示例2: firstPageOf
import org.apache.pdfbox.io.IOUtils; //导入方法依赖的package包/类
@Ignore
@Test
public void firstPageOf() throws Exception {
URL resource = Resources.getResource(PdfManipulatorTest.class, "sample-invoice.pdf");
byte[] bytes = Resources.toByteArray(resource);
Stamp stamp = new Stamp(Arrays.asList(
"approved by: Joe Bloggs",
"approved on: 3-May-2017 14:15",
"doc barcode: 3013011234"
), Arrays.asList(
"debtor IBAN: FR12345678900000123",
"crdtor IBAN: FR99999912312399800",
"gross amt : 12345.99"
), "http://www.google.com");
final PdfManipulator pdfManipulator = new PdfManipulator();
pdfManipulator.pdfBoxService = new PdfBoxService();
//stamp = null;
byte[] firstPageBytes = pdfManipulator.extractAndStamp(bytes, new ExtractSpec(3,1), stamp);
IOUtils.copy(new ByteArrayInputStream(firstPageBytes), new FileOutputStream("x.pdf"));
}
示例3: registerFont
import org.apache.pdfbox.io.IOUtils; //导入方法依赖的package包/类
/**
* Register a font. If possible, try to use a font file, i.e.
* {@link #registerFont(String,File)}. This method will lead to the creation of
* a temporary file which stores the font data.
*
* @param fontName
* the name of the font to use. If null, the name is taken from the
* font.
* @param fontStream
* the input stream of the font. This file must be a ttf/otf file!
* You have to close the stream outside, this method will not close
* the stream.
*/
@SuppressWarnings("WeakerAccess")
public void registerFont(String fontName, InputStream fontStream) throws IOException {
File fontFile = File.createTempFile("pdfboxgfx2dfont", ".ttf");
FileOutputStream out = new FileOutputStream(fontFile);
try {
IOUtils.copy(fontStream, out);
} finally {
out.close();
}
fontFile.deleteOnExit();
tempFiles.add(fontFile);
registerFont(fontName, fontFile);
}
示例4: rotateTest
import org.apache.pdfbox.io.IOUtils; //导入方法依赖的package包/类
@Test
@Ignore("for generation and manual testing")
public void rotateTest() throws Exception {
SignatureImageParameters signatureImageParameters = createSignatureImageParameters();
signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC);
DSSDocument document = sign(signablePdfs.get("minoltaScan90"));
File checkPdfFile = new File("target/pdf/check.pdf");
checkPdfFile.getParentFile().mkdirs();
IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));
}
示例5: setUpBeforeClass
import org.apache.pdfbox.io.IOUtils; //导入方法依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
RESULT_FOLDER.mkdirs();
document = new File(RESULT_FOLDER, "Vanduc1102-test.pdf");
try ( InputStream documentIs = SignLikeDenisMP.class.getResourceAsStream("Vanduc1102-test.pdf");
OutputStream documentOs = new FileOutputStream(document))
{
IOUtils.copy(documentIs, documentOs);
}
keystore = KeyStore.getInstance("PKCS12");
keystore.load(new FileInputStream("keystores/demo-rsa2048.p12"), password);
}
示例6: setUpBeforeClass
import org.apache.pdfbox.io.IOUtils; //导入方法依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
RESULT_FOLDER.mkdirs();
document = new File(RESULT_FOLDER, "hhs-745.pdf");
try ( InputStream documentIs = SignLikeDenisMP.class.getResourceAsStream("hhs-745.pdf");
OutputStream documentOs = new FileOutputStream(document))
{
IOUtils.copy(documentIs, documentOs);
}
keystore = KeyStore.getInstance("PKCS12");
keystore.load(new FileInputStream("keystores/demo-rsa2048.p12"), password);
}
示例7: pdfStreamWorks
import org.apache.pdfbox.io.IOUtils; //导入方法依赖的package包/类
@Test
public void pdfStreamWorks() throws Exception {
InputStream file = getClass().getResourceAsStream("/pdf/packed4.pdf");
List<ExamPaper> examPapers = splitter.splitToExamPapersWithPDFStreams(file);
InputStream pdf = new ByteArrayInputStream(examPapers.get(0).getPdf());
ByteArrayOutputStream os = new ByteArrayOutputStream();
IOUtils.copy(pdf, os);
assertEquals(75077, os.toByteArray().length);
}
示例8: pdfStreamWorksMultipleTimes
import org.apache.pdfbox.io.IOUtils; //导入方法依赖的package包/类
@Test
public void pdfStreamWorksMultipleTimes() throws Exception {
InputStream file = getClass().getResourceAsStream("/pdf/packed4.pdf");
List<ExamPaper> examPapers = splitter.splitToExamPapersWithPDFStreams(file);
InputStream pdf = new ByteArrayInputStream(examPapers.get(0).getPdf());
ByteArrayOutputStream os = new ByteArrayOutputStream();
IOUtils.copy(pdf, os);
assertEquals(75077, os.toByteArray().length);
InputStream pdf2 = new ByteArrayInputStream(examPapers.get(0).getPdf());
ByteArrayOutputStream os2 = new ByteArrayOutputStream();
IOUtils.copy(pdf2, os2);
assertEquals(75077, os.toByteArray().length);
}
示例9: rotatePullRequest71Test
import org.apache.pdfbox.io.IOUtils; //导入方法依赖的package包/类
@Test
@Ignore("for pull request #71")
public void rotatePullRequest71Test() throws Exception {
Logger logger = LoggerFactory.getLogger(getClass());
/**
* minolta scanner normal(not rotated) pdf and rotation none.
*
* You can check the pdf rotation by this code:
* PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun.pdf"));
* System.out.println("rotation: " + inputPDF.getPage(0).getRotation());
*
* result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes line
*
* comment: this is the original working
*/
PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun.pdf"));
logger.info("rotation sun.pdf: " + inputPDF.getPage(0).getRotation());
SignatureImageParameters signatureImageParameters = createSignatureImageParameters();
signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.NONE);
DSSDocument document = sign(signablePdfs.get("minoltaScan"));
File checkPdfFile = new File("target/pdf/check_normal_none.pdf");
checkPdfFile.getParentFile().mkdirs();
IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));
/**
* minolta scanner rotated pdf and rotation none (in pdf view the rotated and normal pdf seem equal)
* you can check the pdf rotation by this code:
* PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun_90.pdf"));
* System.out.println("rotation: " + inputPDF.getPage(0).getRotation());
*
* result in pdf viewer: signature is top right corner and the sign image line is perpendicular with the sun
* eyes line
*
* comment: this is the original working
*/
inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun_90.pdf"));
logger.info("rotation sun_90.pdf: " + inputPDF.getPage(0).getRotation());
signatureImageParameters = createSignatureImageParameters();
signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.NONE);
document = sign(signablePdfs.get("minoltaScan90"));
checkPdfFile = new File("target/pdf/check_90_none.pdf");
checkPdfFile.getParentFile().mkdirs();
IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));
/**
* minolta scanner rotated pdf and rotation automatic (in pdf view the rotated and normal pdf seem equal)
*
* result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes
* line,
* it will be same as with sun.pdf (not rotated) and rotation none
*/
signatureImageParameters = createSignatureImageParameters();
signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC);
document = sign(signablePdfs.get("minoltaScan90"));
checkPdfFile = new File("target/pdf/check_90_automatic.pdf");
checkPdfFile.getParentFile().mkdirs();
IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));
/**
* minolta scanner normal(not rotated) pdf and rotation none.
*
* result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes
* line,
* it will be same as with sun.pdf (not rotated) and rotation none
*/
signatureImageParameters = createSignatureImageParameters();
signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC);
document = sign(signablePdfs.get("minoltaScan"));
checkPdfFile = new File("target/pdf/check_normal_automatic.pdf");
checkPdfFile.getParentFile().mkdirs();
IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));
}
示例10: signDetached
import org.apache.pdfbox.io.IOUtils; //导入方法依赖的package包/类
public void signDetached(String inputFilePath, String outputFilePath, String signatureImagePath/*, Sign signProperties*/) throws IOException, COSVisitorException, SignatureException {
OutputStream outputStream = null;
InputStream inputStream = null;
PDDocument document = null;
InputStream signImageStream = null;
try {
/*setTsaClient(null);*/
document = PDDocument.load(inputFilePath);
// create signature dictionary
PDSignature signature = new PDSignature();
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
signature.setName("VANDUC1102");
signature.setLocation(null);
String displayName = "Hello World, Document signed by VANDUC1102";
String reason = /*reasonText*/"REASON" + " " + displayName;
signature.setReason(reason);
// the signing date, needed for valid signature
signature.setSignDate(Calendar.getInstance());
int signatureInPage = /*signProperties.getPageNumber()*/0 + 1;
signImageStream = new FileInputStream(new File(signatureImagePath));
PDVisibleSignDesigner visibleSig = new PDVisibleSignDesigner(inputFilePath, signImageStream, signatureInPage);
float xAxis = convertPixel2Point(/*signProperties.getX()*/100) ;
float yAxis = convertPixel2Point(/*signProperties.getY()*/100);
float signImageHeight = convertPixel2Point(/*signImageHeight*/100);
float signImageWidth = convertPixel2Point(/*signImageWidth*/100);
visibleSig.xAxis(xAxis)
.yAxis(yAxis)
.zoom(0)
.signatureFieldName("Signature")
.height(signImageHeight)
.width(signImageWidth);
PDVisibleSigProperties signatureProperties = new PDVisibleSigProperties();
signatureProperties.signerName(/*eiUser.getName()*/ "eiUserName")
.signerLocation(null)
.signatureReason(reason)
.preferredSize(0)
.page(/*signProperties.getPageNumber()*/0)
.visualSignEnabled(true)
.setPdVisibleSignature(visibleSig)
.buildSignature();
// register signature dictionary and sign interface
SignatureOptions signatureOptions = new SignatureOptions();
signatureOptions.setVisualSignature(signatureProperties);
signatureOptions.setPage(signatureInPage);
document.addSignature(signature, this, signatureOptions);
File outputFile = new File(outputFilePath);
outputStream = new FileOutputStream(outputFile);
inputStream = new FileInputStream(inputFilePath);
IOUtils.copy(inputStream, outputStream);
// vvv FIX: InputStream parameter of document.saveIncremental
// vvv must cover the whole, enhanced document
if (fixed)
inputStream = new FileInputStream(outputFile);
// =========
document.saveIncremental(inputStream, outputStream);
outputStream.flush();
// } catch (COSVisitorException | SignatureException | IOException ex) {
// log.error("signDetached ", ex);
} finally {
org.apache.commons.io.IOUtils.closeQuietly(outputStream);
org.apache.commons.io.IOUtils.closeQuietly(inputStream);
org.apache.commons.io.IOUtils.closeQuietly(signImageStream);
document.close();
}
}
示例11: readAllBytes
import org.apache.pdfbox.io.IOUtils; //导入方法依赖的package包/类
private static byte[] readAllBytes(InputStream in) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
IOUtils.copy(in, buffer);
return buffer.toByteArray();
}