As a part of our continuous improvement process, a new release of Aspose.Pdf for .NET 11.3.0 has been published with some new features. Among these new features, we also have fixed major issues regarding PDF to PDF/A conversion, PDF to TIFF, ePUB to PDF, HTML to PDF, PDF to JPEG and general performance improvements.
Controlling Z-Order of Rectangle
Aspose.Pdf for .NET supports the feature to add graph objects (for example graph, line, rectangle etc.) to PDF documents. When adding more than one instance of same object inside PDF file, we can control their rendering by specifying the Z-Order. Z-Order is also used when we need to render objects on top of each other.
// instantiate Document class object
Document doc1 = new Document();
/// add page to pages collection of PDF file
Aspose.Pdf.Page page1 = doc1.Pages.Add();
// set size of PDF page
page1.SetPageSize(375, 300);
// set left margin for page object as 0
page1.PageInfo.Margin.Left = 0;
// set top margin of page object as 0
page1.PageInfo.Margin.Top = 0;
// create a new rectangle with Color as Red, Z-Order as 0 and certain dimensions
AddRectangle(page1, 50, 40, 60, 40, Aspose.Pdf.Color.Red, 2);
// create a new rectangle with Color as Blue, Z-Order as 0 and certain dimensions
AddRectangle(page1, 20, 20, 30, 30, Aspose.Pdf.Color.Blue, 1);
// create a new rectangle with Color as Green, Z-Order as 0 and certain dimensions
AddRectangle(page1, 40, 40, 60, 30, Aspose.Pdf.Color.Green, 0);
// save resultant PDF file
doc1.Save("c:/pdftest/Z-Order_Test.pdf");
static void AddRectangle(Aspose.Pdf.Page page, float x, float y, float width, float height, Aspose.Pdf.Color color, int zindex)
{
// create graph object with dimensions same as specified for Rectangle object
Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(width, height);
// can we change the position of graph instance
graph.IsChangePosition = false;
// set Left coordinate position for Graph instance
graph.Left = x;
// set Top coordinate position for Graph object
graph.Top = y;
// Add a rectangle inside the "graph"
Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(0, 0, width, height);
// set rectangle fill color
rect.GraphInfo.FillColor = color;
// color of graph object
rect.GraphInfo.Color = color;
// add rectangle to shapes collection of graph instance
graph.Shapes.Add(rect);
// set Z-Index for rectangle object
graph.ZIndex = zindex;
// add graph to paragraphs collection of page object
page.Paragraphs.Add(graph);
}
For further details, please visit Controlling Z-Order of Rectangle.
Add transparent Text in PDF
A PDF file contains Image, Text, Graph, attachment, Annotations objects and while creating TextFragment, you can set foreground, background color information as well as text formatting. Aspose.Pdf for .NET supports the feature to add text with Alpha color channel.
// create Document instance
Document doc = new Document();
// create page to pages collection of PDF file
Aspose.Pdf.Page page = doc.Pages.Add();
// create Graph object
Aspose.Pdf.Drawing.Graph canvas = new Aspose.Pdf.Drawing.Graph(100, 400);
// create rectangle instance with certain dimensions
Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(100, 100, 400, 400);
// create color object from Alpha color channel
rect.GraphInfo.FillColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(128, System.Drawing.Color.FromArgb(12957183)));
// add rectanlge to shapes collection of Graph object
canvas.Shapes.Add(rect);
// add graph object to paragraphs collection of page object
page.Paragraphs.Add(canvas);
// set value to not change position for graph object
canvas.IsChangePosition = false;
// create TextFragment instance with sample value
TextFragment text = new TextFragment("transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text ");
// create color object from Alpha channel
Aspose.Pdf.Color color = Aspose.Pdf.Color.FromArgb(30, 0, 255, 0);
// set color information for text instance
text.TextState.ForegroundColor = color;
// add text to paragraphs collection of page instance
page.Paragraphs.Add(text);
// save PDF file
doc.Save("c:/pdftest/Transparent_Text.pdf");
For more details, please visit How to add transparent Text in PDF.
Miscellaneous fixes
As well as the enhancements and features discussed above, there have been specific improvements regarding Floating Boxes & RichtextBox rendering, EPUB to PDF, PDF to HTML, HTML to PDF conversion features. Among these fixes, PDF to TIFF, TIFF to PDF conversion, conversion of PDF to PDF/A compliant documents, text replacement, rendering PDF files to XPS format, are also improved. Please download and try the latest release of Aspose.Pdf for .NET 11.3.0.