DynamicPDF Rasterizer for .NET V4.0 Released

by James B

Wed, June 14 2023, 10:14 AM (US Eastern Time)

DynamicPDF announces that DynamicPDF Rasterizer for .NET is updated to version 4.0 and is available for updating or installation. Easily update your project to the latest version using Visual Studio's NuGet package manager. This version fixes several bugs and improves Linux support by removing Rasterizer's dependence on Windows GDI+ on Windows systems. Changes include:

  • DynamicPDF Rasterizer no longer uses Windows GDI+ on Windows systems,
  • image output is now consistent on Windows and Linux systems,
  • fixes the image type limitation and different assembly when installing Rasterizer on Linux,
  • fixes the "Parameter is not valid" error that sometimes occurred when converting a PDF into a bitmap image,
  • fixes an issue with error codes.

DynamicPDF Rasterizer for .NET converts PDF documents into different image file formats. Most conversions require no more than two lines of code. Refer to the DynamicPDF Rasterizer for .NET product page for more details.

 

For more information: www.dynamicpdf.com, sales@dynamicpdf.com, or 1-800-631-5006.

Tags:

DynamicPDF Core Suite for .NET V12.X Released

by James B

Thu, March 9 2023, 4:12 PM (US Eastern Time)

DynamicPDF Core Suite for .NET is updated to V12.x and is available for updating or installation. Update using Visual Studio's NuGet package manager to easily update your project to our latest version.

DynamicPDF Core Suite for .NET now supports the following exciting new features. The Layout Engine (DLEX) now supports 1D and 2D barcodes, links, and dynamic images. We also offer new AutoLayout classes and better RTL support. DynamicPDF Core Suite also supports 3D image extraction and supports RichTextField form field extraction. And our documentation was overhauled to make it easier to find what you need to know when using our help documents.

New features in V12X:

  • new AutoLayout classes,
  • Layout Engine (DLEX) now supports
    • Barcodes (1D and 2D)
    • Links
    • Dynamic Images
  • better RTL support,
  • 3D image support and extraction, and
  • RichTextField form fields.

Refer to our website for a complete list of DynamicPDF Core Suite's features at https://www.dynamicpdf.com/docs/dotnet/dynamic-pdf-core-suite-features.

DynamicPDF offers two Core Suite editions: DynamicPDF Core Suite Essential Edition and DynamicPDF Core Suite Full Edition. Our website's Licensing and Editions page (https://www.dynamicpdf.com/docs/dotnet/dynamic-pdf-core-suite-features) contains more details.

 For more information: www.dynamicpdf.com, sales@dynamicpdf.com, or 1-800-631-5006.

Tags:

DynamicPDF Converter v3 Released

by James B

Thu, September 24 2020, 9:21 AM (US Eastern Time)

DynamicPDF ConverterNow updated to v3, DynamicPDF Converter is available for download. This new release removes the Windows service that runs in the background and allows downloading DynamicPDF Converter directly from NuGet.

DynamicPDF Converter supports the following features,

  • converts most major file types to PDF (including Office and HTML),
  • supports multi-threading for faster conversion,
  • allows appending while converting a file to PDF,
  • has an intuitive and flexible object model,
  • and has transparent pricing.

DynamicPDF Converter for .NET allows any .NET developer to convert over 50 document types to PDF dynamically, including

  • MS Excel,
  • HTML,
  • MS Powerpoint,
  • TIFF,
  • MS Word,
  • and many more.

DynamicPDF Converter is intuitive, efficient, and integrates seamlessly with DynamicPDF's other products. And plenty of documentation and examples are provided, including the following examples.

DynamicPDF Converter is available via our Pro, Pro Plus, or Ultimate subscription plans. For more information, refer to the DynamicPDF Converter product page.

For more information: www.dynamicpdf.com, sales@dynamicpdf.com, or 1-800-631-5006.

Tags: , , ,

Convert HTML to PDF Using DynamicPDF HTML Converter

by James B

Tue, August 18 2020, 12:50 PM (US Eastern Time)

Introduction

The DynamicPDF HTML Converter product is available and included with any of our subscription plans (subscription pricing). You can also use DynamicPDF HTML Converter free if you accept a small footer stating "Created with the DynamicPDF Essentials Edition" and link to the DynamicPDF website from a public area of your website. DynamicPDF HTML Converter supports the following features,

  • quickly converts HTML to PDF,
  • supports the latest HTML, CSS, and JavaScript,
  • works with files, byte arrays, and URLs,
  • supports custom headers and footers,
  • supports .NET Framework and .NET Core (including Linux),
  • and supports a transparent pricing model.

As this tutorial will demonstrate, DynamicPDF HTML Converter is an intuitive yet powerful library for converting HTML files, URLs, and webpages into PDF documents. A video tutorial is also included if you prefer watching the video rather than reading this tutorial. Or better yet, watch the video and work through the written tutorial. All source is available on Github, and the video is available here or on our YouTube channel.

The Converter and ConversionOptions Classes

The DynamicPDF HTML Converter namespace (ceTe.DynamicPDF.HtmlConverter documentation), consists of four classes,

and two enumerations,

Of these, the two classes most important for understanding this tutorial are the Converter and ConversionOptions classes.  The Converter class is how we convert the document from HTML to PDF using the static Convert or AsyncConvert methods. Both methods are overloaded to support different ways of processing HTML conversion. Although these two methods are all that is required, if you wish to perform any formatting of a PDF document, then you must use the ConversionOptions class to format that PDF. The ConversionOptions class supports specifying a PDF document's metadata, such as author, subject, and name. It also supports formating a PDF document by specifying page size, page orientation, headers, footers, and margins.

Now that we discussed the Converter and ConversionOptions classes let's explore using these classes to convert and format HTML to PDF. 

Creating the Project

Start by creating or downloading the project. You can choose to follow the instructions here or download the project from GitHub (link).

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using ceTe.DynamicPDF.HtmlConverter;

namespace ConsoleAppHtmlToPdf
{
    class Program
    {
       static void Main(string[] args)
       {
        Console.WriteLine("Hello World!");
       }
    }
}

Convert Dynamically Generate PDF

After creating the project, in this first example, we dynamically generate a PDF using an HTML table generated by sample form data.

  • Create a new method named ConvertDynamicHtmlToPdf and add a multidimensional array as a string parameter.
  • Create sample data to load and display as an HTML table.
static string[,] companyData = {{ "Grey Fox Brewing", "Mark Smith", "Canada" },
{"Deutsche Ingolstadt","Elias Schneider","Germany"},
{"Centro comercial Moctezuma","Alejandra Silva","Columbia"},
{"West Indies Trading Company","Helen Moore","UK"},
{"Bharat of India","Aarnav Chanda","India"},
{"Magazzini Alimentari Riuniti","Giovanni Esposito","Italy"},
{"Joyas de Cristal","Helena Garcia","Spain"},
{"Telemar Brasil","Elias Martinez","Brazil"},
{"Joe's Pizzaria","Joe Bowman","United States"} };
The data consists of an array containing each entry which consists of the company name, contact name, and the country the company is located.
static void ConvertDynamicHtmlToPdf(string[,] data)
{
     string head = "<html><head><style>"
         + "table {font-family:arial, sans-serif;border-collapse:collapse;width:100%;}"
         + "td,th {border:1px solid #dddddd;text-align:left;padding:8px;}"
         + "tr:nth-child(even){background-color:#dddddd;}"
         + "</style></head><body>";
     string title = "<h2>Company Contacts Listing</h2>";
     string rowHeader = "<tr><th>Company</th><th>Contact</th>"
         + "<th>Country</th></tr>";
     string[] tableTag = { "<table>", "</table>" };
     string close = "</body></html>";

     StringBuilder output = new StringBuilder(head).Append(title);
     output.Append(tableTag[0]);
     output.Append(rowHeader);

     int i = 0;
     foreach (string rec in companyData)
     {
          if (i++ % 3 == 0) output.Append("<tr>");
          output.Append("<td>").Append(rec).Append("</td>");
           if (i % 3 == 0) output.Append("</tr>");
      }

      output.Append(tableTag[1]).Append(close);
      Converter.Convert(output.ToString(), "example5.pdf");
}

After creating our newly created method, add it to the project's Main method.

  • Modify Main to call the newly created method.
  • Run the program and review the created PDF document.
static void Main(string[] args)
{
     ConvertSaveToFileNoInputHtml();
}

Example illustrating HTML with base tag.

As this first example illustrated, creating a PDF document from dynamically generated HTML data is straightforward and only required a document path as a URL and the PDF output.

Convert HTML to PDF Using URI

As the previous example illustrated, generating PDF from HTML is easy when using DynamicPDF HTML Converter. Now let's convert a PDF using a URI to an HTML document, only this time we use a large HTML document combined with ConversionOptions to format the PDF and then save it to a local file.  

  • Create a new static method named ConvertSaveToFileNoInputHtml.
  • Add the URL to the Project Guttenberg's "A Tale of Two Cities."
  • Create a ConversionOptions instance and add the margins, author, creator, title, subject, and the header and footer to the ConversionOptions properties.
  • Call the Converter.Convert method, passing the URL document to convert, the output path for the PDF document, and the conversion options.
  • The code for the ConvertUriToPdf method should appear as follows. 
static void ConvertUriToPdf()
{
     // method signature: public static void Convert(Uri uri, string outputPath, 
    // ConversionOptions conversionOptions = null);

    string outputDocumentPath = "./tale-two-cities--document.pdf";
    string taleOfTwoCities = "https://www.gutenberg.org/files/98/98-h/98-h.htm";
    Uri resolvePath = new Uri(taleOfTwoCities);
    double leftRightMarginsPts = 36;
    double topBottomMarginsPts = 144;

    ConversionOptions conversionOptions = new ConversionOptions(PageSize.Letter, 
           PageOrientation.Portrait, leftRightMarginsPts, topBottomMarginsPts);
           conversionOptions.Author = "Charles Dickens";
           conversionOptions.Creator = "James B";
           conversionOptions.Title = "A Tale of Two Cities";
           conversionOptions.Subject = "Guttenberg press version of Charles Dickens\'s"
               + " A Tale of Two Cities.";
           conversionOptions.Header = "<div style = 'text-align:center;width:100%"
               +";font-size:15em;'>A Tale of Two Cities</div>";
           conversionOptions.Footer = "<div style='text-align:left;"
               +"text-indent:10px;display:inline-block;"
               + "font-size:6em;'><span class=url></span></div>"
               + "<div style = 'text-align:center; display:inline-block; width:60%'></div>"
               + "<div style = 'text-align:right; display:inline-block;"
               +"font-size:6em;'>Page <span class=\"pageNumber\">"
               + "</span> of <span class=\"totalPages\"></span></div>";

     Converter.Convert(resolvePath, outputDocumentPath, conversionOptions);
}

Example illustraing HTML to PDF conversion.

As this second example illustrated, the conversion from HTML to PDF in this example was also straightforward. The ConversionOptions class, although optional, provides powerful options to format a PDF.  For example, in the code above, we created a header from CSS that wrote the title at the top of each page. We also created a footer from CSS that wrote the path and page number at the bottom of each page.

Convert with Base Path and URI

The Convert method consists of an overloaded method that takes an input HTML string, a URL, and an optional ConversionOptions parameter. The following is the method's signature.

public static void Convert(string inputHtml, string outputPath, Uri basePath = null,
     ConversionOptions conversionOptions = null);

The inputHtml is the string content containing HTML, while the basePath is the URL to the document's root path. This overloaded Convert method is how we can process an HTML document using a baseTag. Refer to HTML baseTag on W3Schools for more details on HTML base paths.

  • Create a static method named ConvertSaveToFileInputHtml.
  • Add an array with two relative paths.
  • Create a string containing links to the relative paths in the array.
  • Create a new URI containing the path listed below to Wikimedia Commons.
  • Call the Convert method, passing the input HTML, the output path, and the URI.
  • Create a new ConversionOptions instance and set the page size, page orientation, and the left/right and bottom/top margins.
  • Reduce the zoom to 25% by setting the Zoom property in ConversionOptions.
  • Add the ConvertSaveToFileInputHtml method call to the Main method.
static void ConvertSaveToFileInputHtml()
{
        // method signature: public static void Convert(string inputHtml, string outputPath,
        // Uri basePath = null, ConversionOptions conversionOptions = null);

       string[] filePaths = new string[]{ "./e/ea/Doel_-_Water_pump_1.jpg", 
           "./3/3a/The_Soviet_Union_1939_CPA_690_stamp_%28Plane%29_cancelled.jpg" 
        };
        
        string tempHtml = "<html><body><img src=\"" + filePaths[0] + "\">" 
             + "<img src=\"" + filePaths[1] + "\">" + "</body></html>";

        Uri resolvePath = new Uri("https://upload.wikimedia.org/wikipedia/commons/");
        Converter.Convert(tempHtml, "example1.pdf", resolvePath);

        ConversionOptions conversionOptions = new ConversionOptions(PageSize.Tabloid, 
                PageOrientation.Landscape, 1, 1);
        conversionOptions.Zoom = 0.25F;

        Converter.Convert(tempHtml, "secondTry.pdf", resolvePath,conversionOptions);
      
}
 
  • Run the program and review the PDF output.

Example illustrating HTML with base tag.

In this example, we created a PDF document by combining an HTML string with its base path URI (https://upload.wikimedia.org/wikipedia/commons/). The complete HTML resolved as follows.

<html><body>
<img src="https://upload.wikimedia.org/wikipedia/commons/./e/ea/Doel_-
_Water_pump_1.jpg">
<img src="https://upload.wikimedia.org/wikipedia/commons/./3/3a/The_Soviet_Union_1939_
CPA_690_stamp_%28Plane%29_cancelled.jpg">
</body></html>

We then added document formatting, followed by calling the  Convert method to write the PDF document. Note that the conversion options included formatting the output page as tabloid, the orientation as landscape, and the margins as 1 for the left/right and top/bottom margins.

Convert with CSS and JavaScript

Now let's create the method ConvertHtmlWithCssJavaScriptToPdf to illustrate converting embedded CSS and embedded JavaScript.

  • Add the samplePageWithCss and samplePageWithJavaScript variables to the Program class.
static string samplePageWithCss = "<!DOCTYPE html><html><head ><style>" 
    + "body {background-color: lightblue;}"
    + "h1 {color: white; text-align: center;} p " 
    + "{font-family: verdana;font - size: 20px;}</style>" 
    + "</head><body><h1>My First CSS Example</h1>"
    + "<p>This is a paragraph.</p></body></html>";

static string samplePageWithJavaScript = "<!DOCTYPE html><html><body>"
     + "<h2>My First Web Page</h2>"
     + "<p>My First Paragraph.</p><p id=\"demo\"></p>"
     + "<script>document.getElementById(\"demo\")"
     + ".innerHTML = 5 + 6;</script></body></html>";
  • Create a new method named ConvertHtmlWithCssJavaScriptPdf.
  • Convert the embedded CSS and embedded JavaScript to PDFs.
static void ConvertHtmlWithCssJavaScriptPdf()
{
    // method signature: public static void Convert(string inputHtml, string outputPath, 
    // Uri basePath = null, ConversionOptions conversionOptions = null);

     Converter.Convert(samplePageWithCss, "cssExample.pdf");
     Converter.Convert(samplePageWithJavaScript, "jscriptExample.pdf");
 }

After running the method, both PDF documents output formatted CSS and JavaScript. As the two examples illustrate, DynamicPDF HTML Converter seamlessly supports CSS and JavaScript embedded in HTML documents.

Example illustrating converting embedded CSS and JavaScript into a PDF.

Convert to Byte Array

You can also convert a PDF to a byte array rather than saving it to a file. In this example, we convert an HTML document into a byte array. 

  • Create a new static method named ConvertWriteToByteArrayNoInputHtml.
  • Create a new ConversionOptions instance and pass the PageSize.Tabloid, PageOrientation.Landscape, and the left/right margin and top/bottom margins as 28 points.
  • Create a new URI object instance and pass the CNN URL to the constructor.
  • Call the Convert method, passing the URI and ConversionOptions as parameters and return a byte array as the result.
  • Save the byte array to a file. 
static void ConvertWriteToByteArrayNoInputHtml()
{
   // public static byte[] Convert(Uri uri, ConversionOptions conversionOptions = null);

   ConversionOptions conversionOptions = new ConversionOptions(PageSize.Tabloid, PageOrientation.Landscape, 28, 28);
   Uri document = new Uri("https://cnn.com");
   byte[] output = Converter.Convert(document,conversionOptions);
   File.WriteAllBytes("./cnn-printiout.pdf", output);

This simple example illustrated converting an HTML document to a PDF as a byte array. For simplicity, we saved the byte array to a file to demonstrate that the PDF was printed and formatted correctly.

Convert to Byte Array Asynchronous

For the final example, we convert an HTML document to a byte array asynchronously. If you ran the application in the first example, where it converted A Tale of Two Cities from HTML to PDF, then you probably noticed it took several seconds for the conversion to complete, as the document consists of 330 pages. When processing large documents, it makes sense to convert the document asynchronously so it processes without blocking the main thread. In this example, we convert HTML to PDF asynchronously.

  • Create a new static method named ConvertAsyncReturnByteArray that specifies async and returns a Task.
  • Create strings that specify the output document's path and the input document's path.
  • Create a URI from the input document's path.
  • Create a ConversionOptions instance, passing the page size as letter, the page orientation as portrait, and the margins as 28 points.
  • Add a title and footer to the ConversionOptions instance.
  • Call the ConvertAsync method and pass the input URI document and the ConversionOptions to the method as parameters. Return the output as a byte array.
static async Task ConvertAsyncReturnByteArray()
{
     // public static Task<byte[]> ConvertAsync(Uri uri, ConversionOptions
     // conversionOptions = null);

     string outputDocumentPath = "./gibbons-document.pdf";
     string gibbons = "https://www.gutenberg.org/files/731/731-h/731-h.htm";
     Uri resolvePath = new Uri(gibbons);
     double leftRightMarginsPts = 28;
     double topBottomMarginsPts = 28;

     ConversionOptions conversionOptions = new ConversionOptions(PageSize.Letter, 
     PageOrientation.Portrait, leftRightMarginsPts, topBottomMarginsPts);
     conversionOptions.Title = "HISTORY OF THE DECLINE AND FALL OF THE ROMAN" 
         + " EMPIRE";
      conversionOptions.Footer = "<div style='text-align:left;text-indent:10px;"
          +" display:inline-block; font-size:6em;'><span class=url></span></div>"
          + "<div style = 'text-align:center; display:inline-block; width:60%'></div>"
          + "<div style = 'text-align:right; display:inline-block;font-size:6em;'>"
          + "Page <span class=\"pageNumber\"></span> of <span"
          + "class=\"totalPages\"></span></div>";

      byte[] vals = await Converter.ConvertAsync(resolvePath, conversionOptions); 
      File.WriteAllBytes(outputDocumentPath, vals);
}
  • Modify the Main method to call the ConvertAsyncReturnByteArray method as an asynchronous task. 
static void Main(string[] args)
{
     var task = ConvertAsyncReturnByteArray();
      int i = 0;
      while(task.IsCompleted == false) { Console.Write("\r" + i++); }
      task.Wait();
}

When we execute the program, it takes several seconds to build the PDF document. However, as the simple code in Main illustrates, it does not block the thread while making the PDF.

GitHub Project 

The GitHub project is available here at DynamicPDF/blog-convert-html-to-pdf (project file).

Summary

In this tutorial, we explored using DynamicPDF HTML Converter. DynamicPDF HTML Converter supports synchronous and asynchronous document conversion. It also supports HTML strings with Base URLs, embedded CSS, and embedded JavaScript. And, as the examples illustrated, DynamicPDF HTML Converter supports formatting PDF with many formatting options. As the examples shown, creating a PDF from HTML is straightforward. Get started using Dynamic HTML Converter today by using the free version or by purchasing a subscription today.

Tags: , , , , ,

DynamicPDF HTML Converter Release

Tue, July 28 2020, 10:52 AM (US Eastern Time)

Our new HTML Converter product is now available and is included with any of our subscription plans. It is also available for FREE if you are OK with a small message at the bottom of your PDFs and linkback to our site from a public area of your website. Checkout these great features:

  • Quick HTML to PDF Conversion
  • Supports the latest HTML, CSS and JavaScript
  • Work with files, byte arrays or URLs
  • Custom headers and footers
  • Supports .NET Framework and .NET Core (including Linux)
  • Transparent pricing

Tags: , ,

DynamicPDF Subscriptions are Available

Wed, July 22 2020, 10:47 AM (US Eastern Time)

Subscriptions for our great products are now available. Subscriptions make it easy for you to stay current on the latest features, bug fixes and security patches. They also offer royalty free distribution and work well in cloud environments. Four subscription levels are available:

Tags: ,

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: , , , ,

Month List