Nayyer Shahbaz June 6, 2016one Comment

PDF to TIFF Using Bradley Algorithm, Custom Page Number Formatting For Stamping Object with Aspose.Pdf for .NET 11.6.0

PDF to TIFF Using Bradley Algorithm, Custom Page Number Formatting For Stamping Object with Aspose.Pdf for .NET 11.6.0

June 6, 2016
Share on FacebookTweet about this on TwitterShare on LinkedIn

Aspose.Pdf for .NET logo

The new release of Aspose.Pdf for .NET 11.6.0 has already been published with significant improvements in PDF to PDF/A, PDF to TIFF/JPEG and HTML to PDF features. The API has also been greatly improved to handle various complex scenarios which were causing some issues in earlier release versions. Indeed, this version is better and stable release, as compared to earlier versions.

PDF to TIFF – Use Bradley algorithm during conversion

Aspose.Pdf for .NET has been supporting the feature to convert PDF to TIF using LZW compression and then with the use of AForge, Binarization can be applied. However one of the customers requested that for some images, they need to get the Threshold using Otsu, so they also would like to use Bradley. For further details, please visit Convert PDF files to TIFF using Bradley algorithm.

string outputImageFile = @"c:\resultant.tif";
string outputBinImageFile = @"c:\37116-bin.tif";
//open document
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(@"c:\input.pdf");
//create Resolution object
Resolution resolution = new Resolution(300);
//create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.LZW;
tiffSettings.Depth = 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);

using (FileStream inStream = new FileStream(outputImageFile, FileMode.Open))
{
       using (FileStream outStream = new FileStream(outputBinImageFile, FileMode.Create))
       {
              tiffDevice.BinarizeBradley(inStream, outStream, 0.1);
       }
}

Custom Numbering style for PageNumberStamp

The PageNumberStamp class offers the feature to add Page Number information as stamp object inside PDF document. Prior to this release, the class only supported 1,2,3,4 as page numbering style. However, there has been a requirement from some customers to use custom numbering style when placing page number stamp inside PDF document. 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
For related details, please visit Custom Numbering style for PageNumberStamp.

DOM approach

// load existing PDF file
Document doc = new Document("source.pdf");
// instantiate PageNumberStamp object
PageNumberStamp page_Stamp = new PageNumberStamp();
// set numbering style for page number stamp
// select numberingstyle value from enumeration
page_Stamp.NumberingStyle = NumberingStyle.NumeralsRomanUppercase;
// itterate through PDF pages
foreach (Page page in doc.Pages)
{
    // put page numbering style stamp
    page_Stamp.Put(page);
}
// save updated PDF document
doc.Save("resultnat.pdf");

Facades approach

// instantiate PDFFileStamp object
Aspose.Pdf.Facades.PdfFileStamp pst = new PdfFileStamp();
// bind source PDF file
pst.BindPdf("source.pdf");
// specify numbering style as Numerals Roman UpperCase
pst.NumberingStyle = NumberingStyle.NumeralsRomanUppercase;
// Add page number stamp at Bottom-Center of page
pst.AddPageNumber("#");
// save updated PDF file
pst.Save("output.pdf");

Miscellaneous fixes

As well as the enhancements and features discussed above, there have been specific improvements regarding PDF to PDF/A, PDF to HTML, XPS to PDF, PDF to XPS, HTML to PDF, RedactionAnnotation, Text manipulation and Image placement/manipulation in PDF document. Please download and try the latest release of Aspose.Pdf for .NET 11.6.0.

Join the Conversation

1 Comment

Leave a comment

Posted inAspose.PDF Product Family, Nayyer Shahbaz
 

Related Articles