Creating PDF Reports with Database Data (SQL)

Thu, July 11 2019, 11:04 AM (US Eastern Time)

DynamicPDF ReportWriter make’s it easy to create reports based on your business objects, but sometimes it may be preferred to access data directly from a database using an SQL query or stored procedure. This can easily be done by utilizing one of these report data classes:

Let’s take a look at the steps involved with doing this. First, attach an event to the DocumentLayout’s ReportDataRequired event. This event will be called anytime a report or sub report requires data.

// Create the document's layout from a DLEX template
DocumentLayout documentLayout = new DocumentLayout(Util.GetResourcePath("SimpleReport.dlex"));

// Attach to the ReportDataRequired event
documentLayout.ReportDataRequired += DocumentLayout_ReportDataRequired;

Now in that event, first check the elementId of the report or sub report that is requesting the data. This is necessary in case there are multiple reports or sub reports in your document layout. Next, create a DataReader or DataTable and use it to create a DataReaderReportData or DataTableReportData class. Then set the event’s RepartData event argument to it.

private static void DocumentLayout_ReportDataRequired(object sender, ReportDataRequiredEventArgs args)
{
    if (args.ElementId == "ProductsReport")
    {
        string sqlString =
            "SELECT ProductName, QuantityPerUnit, UnitPrice " +
            "FROM   Products ";

        SqlConnection connection = new SqlConnection(connectionString);
        SqlCommand command = new SqlCommand(sqlString, connection);
        connection.Open();
        SqlDataReader reader = command.ExecuteReader();
        args.ReportData = new DataReaderReportData(connection, reader);
    }
}

Lastly, layout your DocuementLayout to a Document and output the PDF.

// Specify the data
NameValueLayoutData layoutData = new NameValueLayoutData();
layoutData.Add("ReportCreatedFor", "Alex Smith");

// Layout the document and save the PDF
Document document = documentLayout.Layout(layoutData);
document.Draw(outputFilePath);
Wrap Up

A C# Visual Studio project demonstrating this is available on GitHub:

https://github.com/DynamicPDF/dotnet-pdf-report-from-database

If you have any questions or comments, I would love to hear from you.

Tags: , , , , , ,

DynamicPDF Converter v2 for .NET Release

Wed, July 3 2019, 6:30 PM (US Eastern Time)

This version is a huge leap forward for the product. Here are some of the great new features and improvements:

  • Chromium based HTML Conversion Engine
  • New file type specific converter classes with advanced options
  • More events to monitor the conversion process
  • Printer driver is no longer required for most conversions
  • Many stability and efficiency improvements

Download v2 Today!

Tags: , , , ,

Creating PDFs with Custom XMP Schema's

Mon, June 3 2019, 4:23 PM (US Eastern Time)

XMP metadata is a powerful tool for describing the contents of a PDF document. DynamicPDF has built in support for many of the most popular schemas:

However, there are times when you may need to embed other metadata in a PDF. This can easily be done by creating a class that inherits from the XmpSchema base class and overriding the Draw method. This Draw method will then be called when the XMP metadata is being added to the PDF. First let’s define a CustomSchema class that inherits from XmpSchema:

class CustomSchema : XmpSchema
{
    private string userName;
    private DateTime creationDate;

    public CustomSchema(string userName, DateTime creationDate)
    {
        this.userName = userName;
        this.creationDate = creationDate;
    }

    protected override void Draw(XmpWriter xmpWriter)
    {
        xmpWriter.BeginDescription("http://ns.adobe.com/xap/1.0/", "xmp", " ");
        if (userName != null) xmpWriter.Draw("\t\t" + userName + "\n");
        xmpWriter.Draw("\t\t" + creationDate.ToString("yyyy-MM-dd'T'HH:mm:sszzz") + "\n");
        xmpWriter.Draw("\t\t" + xmpWriter.Producer + "\n");
        xmpWriter.Draw("\t\t" + xmpWriter.Date.ToLocalTime().ToString("yyyy-MM-dd'T'HH:mm:sszzz") + "\n");
        xmpWriter.EndDescription();
    }
}

Notice that the Draw method starts by calling the BeginDescription method and ends by calling the EndDescription method. XMP metadata is XML based, and these methods are responsible for the opening and closing XML tags for the custom schema. The Draw method that is called multiple times between them is then responsible for outputting the other XML data.

Next, we will add the CustomSchema class we created to the XMP metatdata of the document:

XmpMetadata xmpMetadata = new XmpMetadata();
xmpMetadata.AddSchema(new CustomSchema("John", DateTime.Now));
document.XmpMetadata = xmpMetadata;

The following custom metatdata will now appear in the PDFs XMP metadata:

<rdf:Description rdf:about=' ' xmlns:xmp='http://ns.adobe.com/xap/1.0/'>
    <xmp:CreatedBy>John</xmp:CreatedBy>
    <xmp:DateCreated>2019-06-03T16:18:17-04:00</xmp:DateCreated>
    <xmp:CreatorTool>DynamicPDF for .NET v10.12.0.40 (Build 38759)</xmp:CreatorTool>
    <xmp:MetadataDate>2019-06-03T16:18:17-04:00</xmp:MetadataDate>
</rdf:Description>
Wrap Up

A C# Visual Studio project demonstrating this is available on GitHub:

https://github.com/DynamicPDF/dotnet-custom-xmp-schemas

If you have any questions or comments, I would love to hear from you.

Tags: , , , ,

Working With Bookmarks When Merging PDFs

Wed, May 8 2019, 10:25 AM (US Eastern Time)

When merging PDFs together using DynamicPDF Merger or Core Suite, all bookmarks (or outlines) will be added to the output PDF by default. They will appear in the order they are merged, with the first document's bookmarks coming first, followed by the next document's bookmarks. However, this is not always the desired behavior, so let's take a look at a couple of other options.

Adding a Bookmark For Each Document

Sometimes you may want to add a bookmark for each document, but remove any of the bookmarks that are in the original PDFs. Accomplishing this can easily be done by adding a bookmark for each document and setting the Outlines merge option to false:

MergeDocument document = new MergeDocument();
MergeOptions mergeOptions = MergeOptions.Append;
mergeOptions.Outlines = false;
document.Outlines.Add("Bookmark for PDF", new XYDestination(document.Pages.Count + 1, 0, 0));
document.Append(fileName, mergeOptions);

The full example file is available here.

Organizing Bookmarks For Each Document

Other times you may want to add a bookmark for each document and place the original document's bookmarks as children. This can quickly be done by creating a bookmark for each document and setting the RootOutline merge option property to that bookmark:

MergeDocument document = new MergeDocument();
MergeOptions mergeOptions = MergeOptions.Append;
Outline outline = document.Outlines.Add("Parent Bookmark for PDF",
    new XYDestination(document.Pages.Count + 1, 0, 0));
mergeOptions.RootOutline = outline;
document.Append(fileName, mergeOptions);

The full example file is available here.

Wrap Up

A C# Visual Studio project demonstrating this is available on GitHub:

https://github.com/DynamicPDF/dotnet-merge-pdf-bookmarks

There are of course many other options for how you may want to deal with bookmarks as well. If you have any questions or comments, I would love to hear from you.

Tags: , , , ,

DynamicPDF Converter v1.1 Release

Wed, March 13 2019, 12:59 PM (US Eastern Time)

Converter is evolving. ceTe Software is excited to announce the release of DynamicPDF Converter v1.1 for .NET with a new Chromium based HTML conversion engine. Version 1.1 is a free upgrade for all current v1.0 users. Upgrade or evaluate it for free today.

Download v1.1 Today!

Also, stay tuned for the BETA release of v2 coming in April.

Version 1.1 (Available Now):
  • New Chromium based HTML conversion engine
  • Latest bug fixes including one caused by a recent Windows update
Version 2.0 (Coming Soon):
  • Many new conversion options
  • Performance improvements
  • No print driver requirement for all conversion types

Tags: , , ,

DynamicPDF Viewer v3 for .NET Release

Tue, February 19 2019, 11:32 AM (US Eastern Time)

Version 3 of our customizable, embeddable .NET PDF Viewing control is here. DynamicPDF Viewer for .NET v3 adds a lot of new features including:

  • Support for localization
  • On demand page thumbnail generation
  • Ability to assign viewer functionality to a PdfToolStrip
  • Customize the search result highlight color
  • Ability to show or hide scroll bars
  • An improved PDF rendering engine

And best of all, it is available with 100% royalty free distribution and a free full featured evaluation edition.

Download v3 Today!

Tags: , , , , , ,

DynamicPDF Rasterizer for .NET Version 3 is Released

Fri, February 8 2019, 10:50 AM (US Eastern Time)

DynamicPDF Rasterizer v3 for .NET has been released! The new version has support for .NET Standard 2.X including .NET Core 2.X and ASP.NET Core 2.X. It includes an updated and improved PDF rendering engine as well as many new features and the latest bug fixes. Also, the developer edition now allows for 100% royalty free distribution to an unlimited number of servers or machines at a lower price point.

Download v3 Today!

Tags: , , , , ,

DynamicPDF Viewer for .NET Version 3 BETA Release

by Anil S

Fri, November 16 2018, 3:53 PM (US Eastern Time)

The DynamicPDF Viewer for .NET Version v3.0 BETA has just been posted to our site for download and testing.

DynamicPDF Viewer for .NET v3 Beta Download


We have added some great new features in version 3 including support for UI localization, page thumbnail generation, show/hide scroll bars and many more. Take a look at the full list of new features.

Email support@dynamicpdf.com with any questions or issues and thanks for taking part in our Version 3 BETA.

Tags: , ,

Version 10 Release of Dynamic PDF for .NET Core Suite

by Anil S

Fri, August 3 2018, 2:32 PM (US Eastern Time)

We are happy to announce the release of DynamicPDF for .NET Core Suite v10 (this includes our Merger, Generator and ReportWriter products).

v10 now supports .NET Standard 2.0 for seamless cross-platform deployment.  

Download it Today!

Version 10 adds several useful and exciting new features:

  • Deployment to any .NET implementation including .NET Core, .NET Framework, Mono, UWP, Xamarin.iOS and Xamarin.Android.
  • HTML layout engine for rapid PDF development using HTML and CSS
  • All new report layout engine (DLEX templates)
  • Take a look at a full list of All Version 10 Full Features

Free upgrades for Maintenance customers, discounted upgrades for eligible existing customers, eligible upgrades can be accessed via our Customer Area, www.dynamicpdf.com/customerarea or we can be contacted directly, sales@dynamicpdf.com or +1 410.772.8620.

Version 9 Release of Dynamic PDF for .NET Core Suite

Tue, December 12 2017, 2:43 PM (US Eastern Time)

DynamicPDF for .NET Core Suite v9 (this includes our Merger, Generator and ReportWriter products) has now been fully released.  Download it Today!

Version 9 adds tons of useful and exciting new features including:

  • HTML Rendering (convert HTML pages including CSS)
  • Disk Buffering (incremental PDF rendering decreases memory usage)
  • Character Shaping (for fonts of complex scripts)
  • Over 20 New Barcodes (Aztec, Code 11, Code 93, GS1 Databar, Australia Post, etc.)
  • Package PDFs
  • XFA Static Form Filling
  • Document, Page and Field Actions
  • Take a look at a full list of All Version 9 Full Features

What might be our best feature...Lower Prices across the board (all editions, all license models).

Free upgrades for Maintenance customers, discounted upgrades for eligible existing customers, eligible upgrades can be accessed via our Customer Area, www.dynamicpdf.com/customerarea or we can be contacted directly, sales@cete.com or +1 410.772.8620.

Tags: , , , , , , , , , , , , , ,

Month List