Tilal Ahmad Sana July 15, 20160 Comments

Support of Bradley algorithm, Image Filter, and custom page number style for stamping in Aspose.Pdf for Java 11.6.0

Support of Bradley algorithm, Image Filter, and custom page number style for stamping in Aspose.Pdf for Java 11.6.0

July 15, 2016
Share on FacebookTweet about this on TwitterShare on LinkedIn

Aspose.Pdf for Java 11.6.0 has been released. We are pleased to announce that this version of Aspose.Pdf for Java includes same features and enhancements introduced in Aspose.Pdf for .NET 11.6.0. Some of these are support of Bradley algorithm in PDF to TIFF conversion, improved text extraction, Adding image with filter type and support of different styles of  page number in Page number stamp.

The following sections describe some details regarding these newly added enhancements.

PDF to TIFF – Use Bradley algorithm during conversion

We received a requirement to convert a PDF document to TIFF using Bradley algorithm, The feature was implemented in Aspose.Pdf for .NET version at first place and now it is also available in Java version of Aspose.Pdf.

String outputImageFile = "OutputFile.tif";
String outputBinImageFile = "OutputFile_binary.tif";
//open document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("Input.pdf");
//create Resolution object
Resolution resolution = new Resolution(300);
//create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.setCompression(CompressionType.LZW);
tiffSettings.setDepth(com.aspose.pdf.devices.ColorDepth.Format1bpp);
//create TIFF device
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
//convert a particular page and save the image to stream
tiffDevice.process(pdfDocument, outputImageFile);
InputStream inStream = new FileInputStream(outputImageFile);
OutputStream outStream = new FileOutputStream(outputBinImageFile);
tiffDevice.binarizeBradley(inStream, outStream, 0.1);
inStream.close();
outStream.close();

Custom Page number style

Now we can add page number in existing PDF document, with different Page number styles such as I, II, III, or A, B, C instead of just the typical 1, 2, 3. In order to accomplish this requirement, NumberingStyle property has been introduced, which accepts the values from NumberingStyle enumeration. Specified below are values offered in this enumeration.

 

  • LettersLowercase
  • LettersUppercase
  • NumeralsArabic
  • NumeralsRomanLowercase
  • NumeralsRomanUppercase

DOM approach

Document doc = new Document("input.pdf");
PageNumberStamp pst = new PageNumberStamp();
PageLabel label1 = new PageLabel();
label1.setNumberingStyle(NumberingStyle.NumeralsRomanUppercase);
label1.setStartingValue(1);
doc.getPageLabels().updateLabel(0, label1);
pst.setNumberingStyle(NumberingStyle.NumeralsRomanUppercase);
for (Page page : (Iterable<Page>) doc.getPages())
{
pst.put(page);
}
doc.save("output.pdf");

Facades approach

com.aspose.pdf.facades.PdfFileStamp pst = new PdfFileStamp();
pst.bindPdf("input.pdf");
pst.setNumberingStyle(NumberingStyle.NumeralsRomanUppercase);
pst.addPageNumber("#");
pst.save("output.pdf");

Adding image with Filter type

Sometime customer has requirement to decrease PDF size after adding image into PDF document and he can use OptimizationOptions to compress the PDF. In this release we have introduced an ImageFilterType property to achieve this goal when adding image to PDF. The user has to use Jpeg2000 decoder to add image on the page (decrease the size of image up to 30% compare with old one) as following.
....
//get the page where image needs to be added
Page page = pdfDocument.getPages().get_Item(1);
//load image into stream
InputStream image = new FileInputStream("image.png");
//add image to Images collection of Page Resources
page.getResources().getImages().addWithImageFilterType(image, ImageFilterType.Jpeg2000);
//using GSave operator: this operator saves current graphics state
page.getContents().add(new Operator.GSave());
....

Improved Text extraction

We have introduced a new field MemorySaving in TextFormattingMode class, it skips the non-text commands and consumes less memory, but please note performance rise is insignificant.

Document pdfDocument = new Document(inFile);
//create TextAbsorber object to extract text
TextAbsorber textAbsorber = new TextAbsorber(new TextExtractionOptions(TextExtractionOptions.TextFormattingMode.MemorySaving));
//accept the absorber for all the pages
pdfDocument.getPages().accept(textAbsorber);
//get the extracted text
String extractedText = textAbsorber.getText();

Miscellaneous fixes

This version also includes some important bug fixes along with above stated enhancements. There have been specific improvements regarding printing, XPS to PDF, HTML to PDF, PDF to HTML, PDF to PDF/A, PDF to Image, Html text rendering and some other. Please check release notes of Aspose.Pdf for Java 11.6.0 for complete list of bug fixed.

Aspose.Pdf for Java Resources

The following resources will help you work with Aspose.Pdf for Java:

 

Leave a comment

Posted inAspose.PDF Product Family
 

Related Articles