Print PDF Documents using PrintController and Add FlateDecode Images in XImageCollection of a Document

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

We at Aspose are honored announcing December Release i.e. Aspose.PDF for .NET 18.12 which is available for download and to be used in .NET Applications. This new release of API contains number of new features, enhancements and bug fixes for the issues reported in previous version(s) of the API. In order to have an insight into what has been introduced new and changed in latest release, it is recommended to go through the detailed release notes page in API documentation. Release notes page contains complete information about public API Changes in this release of the API.

Following sections provides insights into worth mentioning and useful features/enhancements in December revision of Aspose.PDF for .NET.

Print PDF Documents using PrintController of Aspose.PDF

Latest release of the API offers PrintController Class which helps saving a System.Drawing.Printing.PrintDocument as PDF format. Following is a simple example to use PrintController Class and its functionality:

public void PDFNEWNET_45624()
{
 string outFile = GetOutputPath("45624.pdf");
 PrintDocument doc = new PrintDocument();
 doc.PrintPage += new PrintPageEventHandler(mPrintDoc_PrintPage);
 Aspose.Pdf.PrintController printController = new Aspose.Pdf.PrintController();
 printController.FileName = outFile;
 doc.PrintController = printController;
 doc.Print();
}
private void mPrintDoc_PrintPage(object sender
, System.Drawing.Printing.PrintPageEventArgs e)

{
e.Graphics.DrawRectangle(new Pen(System.Drawing.Color.Red), 0, 0, 100, 100);
e.Graphics.FillEllipse(new SolidBrush(System.Drawing.Color.Blue), 100, 100, 200, 200);
}

Store FlateDecode Images in XImageCollection

With latest release of the API, the FlateDecode filter is supported for adding images into PDF Pages. You can consider following code snippet in order to achieve this functionality:

Aspose.Pdf.Document document = new Document();
document.Pages.Add();
Page page = document.Pages[1];
FileStream imageStream = new FileStream(@"c:\1.jpg", FileMode.Open);
page.Resources.Images.Add(imageStream, ImageFilterType.Flate); // New FilterType
XImage ximage = page.Resources.Images[page.Resources.Images.Count];
page.Contents.Add(new Operators.GSave());

For internal usage, you can pass ImageFilterType parameter Flate:

// XImageCollection
internal IPdfObject add(Stream stream, int quality
, bool isBlackWhite, ImageFilterType filterType, bool isMasked
, Stream predefinedStream = null)

{
stream = IsMetafile(stream);
return AddOrReplace(-1, stream, quality, isBlackWhite, filterType, isMasked
, predefinedStream);

}

Miscellaneous Fixes

As mentioned above that December release of the API has come with quite exciting features and enhancements. However, following are some useful fixes and improvements which have been included in this release to improve its performance and usability:

  • PDF/UA functionality has been enhanced in terms of:
    • Validating Text
    • Creating ITaggedContent Interface
    • Creating Factory of Structure Elements
    • Managing Logical Tree of Elements
    • Setting up Title and Language of Tagged PDF Documents
  • Enhanced PDF Optimization
  • Descriptive Exception is added for non-existing fonts in PDF to HTML Conversion Scenario
  • Performance has been improved for PDF to PNG Conversion
  • Various fixes have been made for text adding/editing scenarios
  • Following Conversion Engines have been improved further:
    • JPG to PDF
    • PDF to TIFF
    • PDF to JPEG
    • PDF to PNG
    • PDF to PDF/A-1B
    • PDF to PDF/UA
  • Improvements regarding Table data extraction have been made

Aspose.PDF for .NET Resources

As it is always recommended to use latest releases of our API’s, so we suggest you to please download the latest release Aspose.PDF for .NET 18.12 and check following resources which will help you working with API: