use of com.tom_roush.pdfbox.io.RandomAccessBuffer in project PdfBox-Android by TomRoush.
the class RandomAccessSourceTest method testPositionRead.
@Test
public void testPositionRead() throws IOException {
byte[] inputValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
ByteArrayInputStream bais = new ByteArrayInputStream(inputValues);
RandomAccessSource randomAccessSource = new RandomAccessSource(new RandomAccessBuffer(bais));
Assert.assertEquals(0, randomAccessSource.getPosition());
randomAccessSource.read();
randomAccessSource.read();
randomAccessSource.read();
Assert.assertEquals(3, randomAccessSource.getPosition());
randomAccessSource.close();
}
use of com.tom_roush.pdfbox.io.RandomAccessBuffer in project PdfBox-Android by TomRoush.
the class RandomAccessSourceTest method testPositionReadBytes.
@Test
public void testPositionReadBytes() throws IOException {
byte[] inputValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
ByteArrayInputStream bais = new ByteArrayInputStream(inputValues);
RandomAccessSource randomAccessSource = new RandomAccessSource(new RandomAccessBuffer(bais));
Assert.assertEquals(0, randomAccessSource.getPosition());
byte[] buffer = new byte[4];
randomAccessSource.read(buffer);
Assert.assertEquals(4, randomAccessSource.getPosition());
randomAccessSource.read(buffer, 1, 2);
Assert.assertEquals(6, randomAccessSource.getPosition());
randomAccessSource.close();
}
use of com.tom_roush.pdfbox.io.RandomAccessBuffer in project PdfBox-Android by TomRoush.
the class CCITTFactoryTest method testCreateFromRandomAccessSingle.
/**
* Tests CCITTFactory#createFromRandomAccess(PDDocument document,
* RandomAccess reader) with a single page TIFF
*/
public void testCreateFromRandomAccessSingle() throws IOException {
String tiffG3Path = "pdfbox/com/tom_roush/pdfbox/pdmodel/graphics/image/ccittg3.tif";
String tiffG4Path = "pdfbox/com/tom_roush/pdfbox/pdmodel/graphics/image/ccittg4.tif";
PDDocument document = new PDDocument();
PDImageXObject ximage3 = CCITTFactory.createFromRandomAccess(document, new RandomAccessBuffer(testContext.getAssets().open(tiffG3Path)));
validate(ximage3, 1, 344, 287, "tiff", PDDeviceGray.INSTANCE.getName());
// Bitmap bim3 = ImageIO.read(new File(tiffG3Path));
// checkIdent(bim3, ximage3.getOpaqueImage());
PDPage page = new PDPage(PDRectangle.A4);
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page, AppendMode.APPEND, false);
contentStream.drawImage(ximage3, 0, 0, ximage3.getWidth(), ximage3.getHeight());
contentStream.close();
PDImageXObject ximage4 = CCITTFactory.createFromRandomAccess(document, new RandomAccessBuffer(testContext.getAssets().open(tiffG4Path)));
validate(ximage4, 1, 344, 287, "tiff", PDDeviceGray.INSTANCE.getName());
// Bitmap bim4 = ImageIO.read(new File(tiffG3Path));
// checkIdent(bim4, ximage4.getOpaqueImage());
page = new PDPage(PDRectangle.A4);
document.addPage(page);
contentStream = new PDPageContentStream(document, page, AppendMode.APPEND, false);
contentStream.drawImage(ximage4, 0, 0);
contentStream.close();
document.save(testResultsDir + "/singletiff.pdf");
document.close();
document = PDDocument.load(new File(testResultsDir, "singletiff.pdf"));
assertEquals(2, document.getNumberOfPages());
document.close();
}
Aggregations