Skip to main content
You are viewing help content for pre-release software. This document and the features it describes are subject to change.
All docs
V26.1
  • Migrate to New PDF Document API

    • 6 minutes to read

    PDF Document API* introduces new and improved API in v26.1. Both versions are available side by side in the following namespaces:

    This topic helps you migrate existing PDF Document API code from previous types to the new API. It is useful in the following cases

    • You have an existing application and expect long-term support/development.
    • You are starting a new project and want to reuse code from an existing codebase.

    To migrate from the DevExpress.Pdf namespace to DevExpress.Docs.Pdf, follow the steps below:

    1. Reference the DevExpress.Docs.Pdf NuGet package. You can run the following command:

      dotnet add package DevExpress.Docs.Pdf
      
    2. If you do not use any Office File API libraries other than PDF Document API, remove the DevExpress.Document.Processor NuGet package reference.

    3. Change the namespace reference from DevExpress.Pdf to using DevExpress.Docs.Pdf:

      // using DevExpress.Pdf;
      using DevExpress.Docs.Pdf;
      
    4. Replace types with their new versions (see the table below).

    5. Test the PDF Document API output (open/save documents, edit document content, etc).

    Basic Migration Example

    Previous API

    using DevExpress.Pdf;
    using System.Linq;
    
    using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
        // Load a document
        processor.LoadDocument("..\\..\\Result.pdf");
    
        // Access the first page
        PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];
    
        // Obtain all free-text annotations
        var freeTextAnnotations = pageFacade.Annotations.Where
            (annotation => annotation.Type == PdfAnnotationType.FreeText);
        foreach (PdfFreeTextAnnotationFacade freeText in freeTextAnnotations) {
            // Change border parameters and text justification
            freeText.InteriorColor = new PdfRGBColor(0.36, 0.54, 0.66);
            freeText.BorderWidth = 0.5;
            freeText.TextJustification = PdfTextJustification.Centered;
        }
    
        // Generate a watermark
        string fontName = "Arial Black";
        int fontSize = 12;
        PdfStringFormat stringFormat = PdfStringFormat.GenericTypographic;
        stringFormat.Alignment = PdfStringAlignment.Center;
        stringFormat.LineAlignment = PdfStringAlignment.Center;
    
        using (DXSolidBrush brush = new DXSolidBrush(Color.FromArgb(63,Color.Black))) {
            DXFont font = new DXFont(fontName,fontSize);
            foreach (var page in processor.Document.Pages) {
                var watermarkSize = page.CropBox.Width * 0.75;
                using (PdfGraphics graphics = processor.CreateGraphicsPageSystem()) {
                    SizeF stringSize = graphics.MeasureString(text,font);
                    float scale = (float)(watermarkSize / (double)stringSize.Width);
                    graphics.TranslateTransform((float)(page.CropBox.Width * 0.5),(float)(page.CropBox.Height * 0.5));
                    graphics.RotateTransform((float)45.0);
                    graphics.TranslateTransform((float)(-stringSize.Width * scale * 0.5),(float)(-stringSize.Height * scale * 0.5));
                    DXFont actualFont = new DXFont(fontName,fontSize * scale);
                    RectangleF rect = new RectangleF(0,0,stringSize.Width * scale,stringSize.Height * scale);
                    graphics.DrawString(text,actualFont,brush,rect,stringFormat);
    
                    graphics.AddToPageForeground(page);
                }
            }
        }
        // Save the result
        processor.SaveDocument("..\\..\\Result_1.pdf");
    }
    

    New API

    using DevExpress.Docs.Pdf;
    using System.Drawing;
    
    using (PdfDocument document = new PdfDocument(File.OpenRead("Demo.pdf"), new LoadOptions())) {
    
        // Access the first page
        Page page = document.Pages[0];
    
        // Obtain all free-text annotations
        var freeTextAnnotations = page.Annotations.Where
            (annotation => annotation is FreeTextAnnotation);
        foreach (FreeTextAnnotation freeText in freeTextAnnotations) {
            // Change border parameters and text justification
            freeText.Color = PdfColor.DarkSlateGray;
            freeText.Border = new AnnotationBorder{ Width = 0.5 };
            freeText.TextJustification = TextJustification.Centered;
        }
    
        // Generate a watermark
        TextFragment textFragment = new() {
            Text = "WATERMARK",
            Location = new PointF(150, 80),
            Font = new("Arial"),
            FontSize = 100,
            RotationAngle = 45,
            ForegroundFill = new SolidFill(PdfColor.Red,0.2)
        };
    
        for (int i = 0; i < document.Pages.Count; i++) {
            document.Pages[i].Fragments.Add(textFragment);
        }
    
        // Save the result
        document.Save(new FileStream("Demo1.pdf", FileMode.Create, FileAccess.Write));
    }
    

    PDF Type Equivalents

    The table below lists members/types available in the DevExpress.Pdf namespace and their DevExpress.Docs.Pdf counterparts.

    Core Document Types

    Previous Version New Version
    DevExpress.Pdf.PdfDocumentProcessor DevExpress.Docs.Pdf.PdfDocument
    DevExpress.Pdf.PdfDocumentFacade DevExpress.Docs.Pdf.PdfDocument
    DevExpress.Pdf.PdfPageFacade DevExpress.Docs.Pdf.Page
    DevExpress.Pdf.PdfPage DevExpress.Docs.Pdf.Page

    Annotation Types

    Previous Version New Version
    DevExpress.Pdf.PdfAnnotation DevExpress.Docs.Pdf.BaseAnnotation
    DevExpress.Pdf.PdfAnnotationFacade DevExpress.Docs.Pdf.BaseAnnotation
    DevExpress.Pdf.PdfFreeTextAnnotationFacade DevExpress.Docs.Pdf.FreeTextAnnotation
    DevExpress.Pdf.PdfTextAnnotationFacade DevExpress.Docs.Pdf.TextAnnotation
    DevExpress.Pdf.PdfMarkupAnnotationFacade DevExpress.Docs.Pdf.MarkupAnnotation
    DevExpress.Pdf.PdfCircleAnnotationFacade DevExpress.Docs.Pdf.CircleAnnotation
    DevExpress.Pdf.PdfSquareAnnotationFacade DevExpress.Docs.Pdf.SquareAnnotation
    DevExpress.Pdf.PdfLineAnnotationFacade DevExpress.Docs.Pdf.LineAnnotation
    DevExpress.Pdf.PdfInkAnnotationFacade DevExpress.Docs.Pdf.InkAnnotation
    DevExpress.Pdf.PdfRedactAnnotationFacade DevExpress.Docs.Pdf.RedactionAnnotation
    DevExpress.Pdf.PdfCaretAnnotationFacade DevExpress.Docs.Pdf.CaretAnnotation
    DevExpress.Pdf.PdfRubberStampAnnotationFacade DevExpress.Docs.Pdf.RubberStampAnnotation
    DevExpress.Pdf.PdfFileAttachmentAnnotationFacade DevExpress.Docs.Pdf.FileAttachmentAnnotation
    DevExpress.Pdf.PdfPathAnnotationFacade DevExpress.Docs.Pdf.PathAnnotation
    DevExpress.Pdf.PdfPolygonAnnotationFacade DevExpress.Docs.Pdf.PolygonAnnotation
    DevExpress.Pdf.PdfPolyLineAnnotationFacade DevExpress.Docs.Pdf.PolylineAnnotation
    DevExpress.Pdf.PdfPopupAnnotation DevExpress.Docs.Pdf.PopupAnnotation
    DevExpress.Pdf.PdfLinkAnnotationFacade DevExpress.Docs.Pdf.LinkAnnotation

    Annotation Properties and Enumerators

    Previous Version New Version
    DevExpress.Pdf.PdfAnnotationType Type checking with is operator (for example, annotation is FreeTextAnnotation)
    DevExpress.Pdf.PdfAnnotationAppearance DevExpress.Docs.Pdf.AnnotationAppearance
    DevExpress.Pdf.PdfAnnotationBorder DevExpress.Docs.Pdf.AnnotationBorder
    DevExpress.Pdf.PdfAnnotationBorderStyle DevExpress.Docs.Pdf.AnnotationBorderStyle
    DevExpress.Pdf.PdfBorderStyle DevExpress.Docs.Pdf.BorderStyle
    DevExpress.Pdf.PdfAnnotationLineEndingStyle DevExpress.Docs.Pdf.AnnotationLineEndingStyle
    DevExpress.Pdf.PdfAnnotationHighlightingMode DevExpress.Docs.Pdf.AnnotationHighlightingMode

    Widgets

    Previous Version New Version
    DevExpress.Pdf.PdfWidgetAnnotation DevExpress.Docs.Pdf.WidgetAnnotation
    DevExpress.Pdf.PdfWidgetFacade DevExpress.Docs.Pdf.WidgetAnnotation
    DevExpress.Pdf.PdfComboBoxWidgetFacade DevExpress.Docs.Pdf.ComboBoxWidgetAnnotation
    DevExpress.Pdf.PdfListBoxWidgetFacade DevExpress.Docs.Pdf.ListBoxWidgetAnnotation
    DevExpress.Pdf.PdfSignatureWidgetFacade DevExpress.Docs.Pdf.SignatureWidgetAnnotation
    DevExpress.Pdf.PdfCheckBoxWidgetFacade DevExpress.Docs.Pdf.CheckBoxWidgetAnnotation
    DevExpress.Pdf.PdfButtonWidgetFacade DevExpress.Docs.Pdf.ButtonWidgetAnnotation
    DevExpress.Pdf.PdfRadioButtonWidgetFacade DevExpress.Docs.Pdf.RadioGroupItemWidgetAnnotation
    DevExpress.Pdf.PdfTextWidgetFacade DevExpress.Docs.Pdf.TextBoxWidgetAnnotation

    Form Fields

    Previous Version New Version
    DevExpress.Pdf.PdfAcroFormCheckBoxField DevExpress.Docs.Pdf.CheckBoxField
    DevExpress.Pdf.PdfAcroFormComboBoxField DevExpress.Docs.Pdf.ComboBoxField
    DevExpress.Pdf.PdfAcroFormGroupField DevExpress.Docs.Pdf.GroupField
    DevExpress.Pdf.PdfAcroFormListBoxField DevExpress.Docs.Pdf.ListBoxField
    DevExpress.Pdf.PdfAcroFormRadioGroupField DevExpress.Docs.Pdf.RadioGroupField
    DevExpress.Pdf.PdfAcroFormSignatureField DevExpress.Docs.Pdf.SignatureField
    DevExpress.Pdf.PdfAcroFormTextBoxField DevExpress.Docs.Pdf.TextBoxField

    Add/Clear Content

    Previous Version New Version
    DevExpress.Pdf.PdfGraphics.DrawString DevExpress.Docs.Pdf.Page.AddTextFragment
    DevExpress.Pdf.PdfGraphics.DrawImage DevExpress.Docs.Pdf.Page.AddImageFragment
    DevExpress.Pdf.PdfGraphics.DrawRectangle DevExpress.Docs.Pdf.Page.AddPathFragment
    DevExpress.Pdf.PdfGraphics.DrawEllipse DevExpress.Docs.Pdf.Page.AddPathFragment
    DevExpress.Pdf.PdfGraphics.DrawPolygon DevExpress.Docs.Pdf.Page.AddPathFragment
    DevExpress.Pdf.PdfGraphics.DrawLine DevExpress.Docs.Pdf.Page.AddPathFragment
    DevExpress.Pdf.PdfGraphics.DrawBezier DevExpress.Docs.Pdf.Page.AddPathFragment
    DevExpress.Pdf.PdfGraphics.DrawPath DevExpress.Docs.Pdf.Page.AddPathFragment
    DevExpress.Pdf.PdfPageFacade.ClearContent DevExpress.Docs.Pdf.PdfDocument.ClearContent

    Encryption

    Previous Version New Version
    DevExpress.Pdf.PdfEncryptionOptions DevExpress.Docs.Pdf.EncryptionOptions
    DevExpress.Pdf.PdfEncryptionOptions.InteractivityPermissions DevExpress.Docs.Pdf.PdfDocument.InteractivityPermissions
    DevExpress.Pdf.PdfEncryptionOptions.ModificationPermissions DevExpress.Docs.Pdf.PdfDocument.ModificationPermissions
    DevExpress.Pdf.PdfEncryptionOptions.DataExtractionPermissions DevExpress.Docs.Pdf.PdfDocument.DataExtractionPermissions
    DevExpress.Pdf.PdfEncryptionOptions.PrintingPermissions DevExpress.Docs.Pdf.PdfDocument.PrintPermissions

    Document Metadata

    Previous Version New Version
    DevExpress.Pdf.Xmp.XmpMetadata DevExpress.Docs.Pdf.XmpMetadata
    DevExpress.Pdf.Xmp.XmpArray DevExpress.Docs.Pdf.XmpBoolArray
    DevExpress.Pdf.Xmp.XmpArray DevExpress.Docs.Pdf.XmpDateArray
    DevExpress.Pdf.Xmp.XmpArray DevExpress.Docs.Pdf.XmpStringArray
    DevExpress.Pdf.PdfMetadata DevExpress.Docs.Pdf.DocumentMetadata
    DevExpress.Pdf.Xmp.XmpSimpleNode DevExpress.Docs.Pdf.XmpValue

    Color, Font, and Style Types

    Previous Version New Version
    DevExpress.Pdf.PdfRGBColor DevExpress.Docs.Pdf.PdfColor
    DevExpress.Pdf.PdfColor DevExpress.Docs.Pdf.PdfColor
    DevExpress.Pdf.PdfColorSpace DevExpress.Docs.Pdf.ColorSpace
    DevExpress.Pdf.PdfTextJustification DevExpress.Docs.Pdf.TextJustification
    DevExpress.Pdf.PdfFont DevExpress.Docs.Office.TextFont

    Icon and Action Types

    Previous Version New Version
    DevExpress.Pdf.PdfRubberStampAnnotationIconName DevExpress.Docs.Pdf.RubberStampAnnotationIconName
    DevExpress.Pdf.PdfFileAttachmentAnnotationIconName DevExpress.Docs.Pdf.FileAttachmentAnnotationIconName
    DevExpress.Pdf.PdfTextAnnotationIconName DevExpress.Docs.Pdf.TextAnnotationIconName
    DevExpress.Pdf.PdfAction DevExpress.Docs.Pdf.AnnotationAction