use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class TestPublicKeyEncryption method reload.
/**
* Reloads the given document from a file and check some contents.
*
* @param file input file
* @param decryptionPassword password to be used to decrypt the doc
* @param keyStore password to be used to decrypt the doc
* @return reloaded document
* @throws Exception if
*/
private PDDocument reload(File file, String decryptionPassword, InputStream keyStore) throws IOException, NoSuchAlgorithmException {
PDDocument doc2 = PDDocument.load(file, decryptionPassword, keyStore, null, MemoryUsageSetting.setupMainMemoryOnly());
Assert.assertEquals("Extracted text is different", text, new PDFTextStripper().getText(doc2));
Assert.assertEquals("Producer is different", producer, doc2.getDocumentInformation().getProducer());
return doc2;
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class JPEGFactoryTest method testCreateFromImageRGB.
/**
* Tests RGB JPEGFactory#createFromImage(PDDocument document, BufferedImage
* image) with color JPEG image
*/
@Test
public void testCreateFromImageRGB() throws IOException {
PDDocument document = new PDDocument();
Bitmap image = BitmapFactory.decodeStream(testContext.getAssets().open("pdfbox/com/tom_roush/pdfbox/pdmodel/graphics/image/jpeg.jpg"));
// assertEquals(3, image.getColorModel().getNumComponents()); TODO: PdfBox-Android
PDImageXObject ximage = JPEGFactory.createFromImage(document, image);
validate(ximage, 8, 344, 287, "jpg", PDDeviceRGB.INSTANCE.getName());
doWritePDF(document, ximage, testResultsDir, "jpegrgb.pdf");
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class JPEGFactoryTest method testCreateFromImageUSHORT_555_RGB.
/**
* Tests USHORT_555_RGB JPEGFactory#createFromImage(PDDocument document, BufferedImage
* image), see also PDFBOX-4674.
* @throws java.io.IOException
*/
@Test
public void testCreateFromImageUSHORT_555_RGB() throws IOException {
// http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7044758
if (System.getProperty("java.runtime.name").equals("OpenJDK Runtime Environment") && (System.getProperty("java.specification.version").equals("1.6") || System.getProperty("java.specification.version").equals("1.7") || System.getProperty("java.specification.version").equals("1.8"))) {
return;
}
PDDocument document = new PDDocument();
Bitmap image = BitmapFactory.decodeStream(testContext.getAssets().open("pdfbox/com/tom_roush/pdfbox/pdmodel/graphics/image/jpeg.jpg"));
// create an USHORT_555_RGB image
int width = image.getWidth();
int height = image.getHeight();
Bitmap rgbImage = image.copy(Bitmap.Config.RGB_565, true);
for (int x = 0; x < rgbImage.getWidth(); ++x) {
for (int y = 0; y < rgbImage.getHeight(); ++y) {
rgbImage.setPixel(x, y, (rgbImage.getPixel(x, y) & 0xFFFFFF) | ((y / 10 * 10) << 24));
}
}
PDImageXObject ximage = JPEGFactory.createFromImage(document, rgbImage);
validate(ximage, 8, width, height, "jpg", PDDeviceRGB.INSTANCE.getName());
assertNull(ximage.getSoftMask());
doWritePDF(document, ximage, testResultsDir, "jpeg-ushort555rgb.pdf");
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class JPEGFactoryTest method testCreateFromStream256.
/**
* Tests JPEGFactory#createFromStream(PDDocument document, InputStream
* stream) with gray JPEG file
*/
@Test
public void testCreateFromStream256() throws IOException {
PDDocument document = new PDDocument();
InputStream stream = testContext.getAssets().open("pdfbox/com/tom_roush/pdfbox/pdmodel/graphics/image/jpeg256.jpg");
PDImageXObject ximage = JPEGFactory.createFromStream(document, stream);
// TODO: PdfBox-Android
validate(ximage, 8, 344, 287, "jpg", PDDeviceRGB.INSTANCE.getName());
doWritePDF(document, ximage, testResultsDir, "jpeg256stream.pdf");
checkJpegStream(testResultsDir, "jpeg256stream.pdf", testContext.getAssets().open("pdfbox/com/tom_roush/pdfbox/pdmodel/graphics/image/jpeg256.jpg"));
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class LosslessFactoryTest method testCreateLosslessFromImage4BYTE_ABGR.
// testCreateLosslessFromImageBITMASK_INT_ARGB: Android does not have bitmask transparency
// testCreateLosslessFromImageBITMASK4BYTE_ABGR: Android does not have bitmask transparency
/**
* Tests 4BYTE_ABGR LosslessFactoryTest#createFromImage(PDDocument document,
* BufferedImage image)
*
* @throws java.io.IOException
*/
@Test
public void testCreateLosslessFromImage4BYTE_ABGR() throws IOException {
PDDocument document = new PDDocument();
Bitmap image = BitmapFactory.decodeStream(testContext.getAssets().open("pdfbox/com/tom_roush/pdfbox/pdmodel/graphics/image/png.png"));
// create an ARGB image
int w = image.getWidth();
int h = image.getHeight();
Bitmap argbImage = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas();
canvas.setBitmap(argbImage);
Paint paint = new Paint();
canvas.drawBitmap(image, 0, 0, paint);
int[] argbPixels = new int[w * h];
argbImage.getPixels(argbPixels, 0, w, 0, 0, w, h);
for (int x = 0; x < argbImage.getWidth(); ++x) {
for (int y = 0; y < argbImage.getHeight(); ++y) {
argbPixels[x + w * y] = (argbPixels[x + w * y] & 0xFFFFFF) | ((y / 10 * 10) << 24);
}
}
argbImage.setPixels(argbPixels, 0, w, 0, 0, w, h);
PDImageXObject ximage = LosslessFactory.createFromImage(document, argbImage);
validate(ximage, 8, w, h, "png", PDDeviceRGB.INSTANCE.getName());
checkIdent(argbImage, ximage.getImage());
checkIdentRGB(argbImage, ximage.getOpaqueImage());
assertNotNull(ximage.getSoftMask());
validate(ximage.getSoftMask(), 8, w, h, "png", PDDeviceGray.INSTANCE.getName());
assertTrue(colorCount(ximage.getSoftMask().getImage()) > image.getHeight() / 10);
doWritePDF(document, ximage, testResultsDir, "4babgr.pdf");
}
Aggregations