use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class TestCOSName method PDFBox4076.
/**
* PDFBOX-4076: Check that characters outside of US_ASCII are not replaced with "?".
*
* @throws IOException
*/
@Test
public void PDFBox4076() throws IOException {
String special = "中国你好!";
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
document.getDocumentCatalog().getCOSObject().setString(COSName.getPDFName(special), special);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
document.save(baos);
document.close();
document = PDDocument.load(baos.toByteArray());
COSDictionary catalogDict = document.getDocumentCatalog().getCOSObject();
Assert.assertTrue(catalogDict.containsKey(special));
Assert.assertEquals(special, catalogDict.getString(special));
document.close();
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class TestPDFParser method testPDFBox3208.
/**
* Test whether /Info dictionary is retrieved correctly when rebuilding the trailer of a corrupt
* file. An incorrect algorithm would result in an outline dictionary being mistaken for an
* /Info.
*
* @throws IOException
*/
// TODO: PdfBox-Android - provide test file
@Test
public void testPDFBox3208() throws IOException {
File testPdf = new File(TARGETPDFDIR, "PDFBOX-3208-L33MUTT2SVCWGCS6UIYL5TH3PNPXHIS6.pdf");
assumeTrue(testPdf.exists());
PDDocument doc = PDDocument.load(testPdf);
PDDocumentInformation di = doc.getDocumentInformation();
assertEquals("Liquent Enterprise Services", di.getAuthor());
assertEquals("Liquent services server", di.getCreator());
assertEquals("Amyuni PDF Converter version 4.0.0.9", di.getProducer());
assertEquals("", di.getKeywords());
assertEquals("", di.getSubject());
assertEquals("892B77DE781B4E71A1BEFB81A51A5ABC_20140326022424.docx", di.getTitle());
assertEquals(DateConverter.toCalendar("D:20140326142505-02'00'"), di.getCreationDate());
assertEquals(DateConverter.toCalendar("20140326172513Z"), di.getModificationDate());
doc.close();
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class TestPDFParser method testPDFBox3940.
/**
* Test whether the /Info is retrieved correctly when rebuilding the trailer of a corrupt file,
* despite the /Info dictionary not having a modification date.
*
* @throws IOException
*/
// TODO: PdfBox-Android - provide test file
@Test
public void testPDFBox3940() throws IOException {
File testPdf = new File(TARGETPDFDIR, "PDFBOX-3940-079977.pdf");
assumeTrue(testPdf.exists());
PDDocument doc = PDDocument.load(testPdf);
PDDocumentInformation di = doc.getDocumentInformation();
assertEquals("Unknown", di.getAuthor());
assertEquals("C:REGULA~1IREGSFR_EQ_EM.WP", di.getCreator());
assertEquals("Acrobat PDFWriter 3.02 for Windows", di.getProducer());
assertEquals("", di.getKeywords());
assertEquals("", di.getSubject());
assertEquals("C:REGULA~1IREGSFR_EQ_EM.PDF", di.getTitle());
assertEquals(DateConverter.toCalendar("Tuesday, July 28, 1998 4:00:09 PM"), di.getCreationDate());
doc.close();
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class COSWriterTest method testPDFBox4241.
/**
* PDFBOX-4241: check whether the output stream is closed twice.
*
* @throws IOException
*/
@Test
public void testPDFBox4241() throws IOException {
PDDocument doc = new PDDocument();
PDPage page = new PDPage();
doc.addPage(page);
doc.save(new BufferedOutputStream(new ByteArrayOutputStream(1024) {
private boolean open = true;
@Override
public void close() throws IOException {
// Thread.dumpStack();
open = false;
super.close();
}
@Override
public void flush() throws IOException {
if (!open) {
throw new IOException("Stream already closed");
}
// Thread.dumpStack();
}
}));
doc.close();
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class PageExtractorTest method testExtract.
/**
* Test of extract method, of class com.tom_roush.pdfbox.util.PageExtractor.
*/
public void testExtract() throws Exception {
PDDocument sourcePdf = null;
PDDocument result = null;
try {
// this should work for most users
sourcePdf = PDDocument.load(new File("src/test/resources/pdfbox/input/cweb.pdf"));
PageExtractor instance = new PageExtractor(sourcePdf);
result = instance.extract();
assertEquals(sourcePdf.getNumberOfPages(), result.getNumberOfPages());
closeDoc(result);
instance = new PageExtractor(sourcePdf, 1, 1);
result = instance.extract();
assertEquals(1, result.getNumberOfPages());
closeDoc(result);
instance = new PageExtractor(sourcePdf, 1, 5);
result = instance.extract();
assertEquals(5, result.getNumberOfPages());
closeDoc(result);
instance = new PageExtractor(sourcePdf, 5, 10);
result = instance.extract();
assertEquals(6, result.getNumberOfPages());
closeDoc(result);
instance = new PageExtractor(sourcePdf, 2, 1);
result = instance.extract();
assertEquals(0, result.getNumberOfPages());
closeDoc(result);
} finally {
closeDoc(sourcePdf);
closeDoc(result);
}
}
Aggregations