Browse our Products

Aspose.PDF for .NET 25.2

Improvements and Changes

Features and Enhancements

Aspose.PDF for .NET enables you to convert a PDF file to a PDF/X-compliant PDF file. PDF/X is a subset of the PDF standard that facilitates graphics exchange and has a series of printing-related requirements that do not apply to standard PDF files. Starting from version 25.2, we support the PDF/X-4 standard. This feature was made according to the User’s request PDFNET-56954.

The following code snippet shows how to convert PDF files to PDF/X-4 compliant PDF and provide an external ICC profile to ensure the proper color rendition.

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPdfToPdfX()
{
    // The path to the documents directory
    string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "PDFToPDFX.pdf"))
    {
        // Set up the desired PDF/X format with PdfFormatConversionOptions
        Aspose.Pdf.PdfFormatConversionOptions options = new Aspose.Pdf.PdfFormatConversionOptions(Aspose.Pdf.PdfFormat.PDF_X_4, Aspose.Pdf.ConvertErrorAction.Delete);

        // Provide the name of the external ICC profile file (optional)
        options.IccProfileFileName = dataDir + "ISOcoated_v2_eci.icc";

        // Provide an output condition identifier and other necessary OutputIntent properties (optional)
        options.OutputIntent = new Aspose.Pdf.OutputIntent("FOGRA39");

        // Convert to PDF/X compliant document
        document.Convert(options);

        // Save PDF document
        document.Save(dataDir + "PDFToPDFX4_out.pdf");
    }
}

We’ve added an option to avoid twice calls from the CustomSignHash delegate during signing. This was made at the User’s request PDFNET-56058 which was originally reported as a bug. If you use SignHash to create a digital signature, you may find that the delegate is called twice during the document-saving process. Suppose for some reason you cannot afford two calls, for example. If a PIN code request occurs during the call, you can use the AvoidEstimatingSignatureLength option for the PKCS1, PKCS7, PKCS7Detached, and ExternalSignature classes.

The following code shows the use of the new options:

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SignWithCertificate(string pfxFilePath, string password)
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();

    using (var sign = new Aspose.Pdf.Facades.PdfFileSignature())
    {   
        // Bind PDF document
        sign.BindPdf(dataDir + "input.pdf");
        // Create PKCS#7 object to sign
        var pkcs7 = new Aspose.Pdf.Forms.PKCS7(pfxFilePath, password);// You can use PKCS7Detached with digest algorithm argument
        // Set the delegate to external sign
        pkcs7.CustomSignHash = CustomSignHash;
        // Set an option to avoiding twice SignHash calling.
        pkcs7.AvoidEstimatingSignatureLength = true;
        // Sign the file
        sign.Sign(1, "reason", "cont", "loc", false, new System.Drawing.Rectangle(0, 0, 500, 500), pkcs7);
        // Save PDF document
        sign.Save(dataDir + "SignWithCertificate_out.pdf");
    }

    // Custom hash signing function to generate a digital signature
    byte[] CustomSignHash(byte[] signableHash, Aspose.Pdf.DigestHashAlgorithm digestHashAlgorithm)
    {
        var inputP12 = "111.p12";
        var inputPfxPassword = "123456";
        X509Certificate2 signerCert = new X509Certificate2(inputP12, inputPfxPassword, X509KeyStorageFlags.Exportable);
        RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
        var xmlString = signerCert.PrivateKey.ToXmlString(true);
        rsaCSP.FromXmlString(xmlString);
        byte[] signedData = rsaCSP.SignData(signableHash, CryptoConfig.MapNameToOID("SHA1"));
        return signedData;
    }
}

Detailed information on the enhancement has already been added to the documentation.

In Aspose.PDF 25.2, we have added a new GetSignatureNames() method to obtain information about PDF digital signatures. This method returns a list of SignatureName objects, which prevents collisions when verifying signatures with the same names. Methods that accept the SignatureName type instead of a string signature name have also been added. The old PdfFileSignature.VerifySigned() method is deprecated. This improvement is logged as PDFNET-58918 in our issue tracker.

Thus, the recommended code for verifying signatures changes to the following:

// For complete examples and data files, check for https://github.com/aspose-pdf/Aspose.PDF-for-.NET  
private static void Verify()
{
    // The path to the documents directory
    string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
    
    // Open the document
    using (var document = new Aspose.Pdf.Document(dataDir + "signed_rsa.pdf"))
    {
        // Create an instance of PdfFileSignature for working with signatures in the document
        using (var signature = new Aspose.Pdf.Facades.PdfFileSignature(document))
        {         
            // Get a list of signature names in the document
            var sigNames = signature.GetSignatureNames();

            // Loop through all signature names to verify each one
            foreach (var sigName in sigNames)
            {
                // Verify that the signature with the given name is valid
                if (!signature.VerifySignature(sigName))
                {
                    throw new Exception("Not verified");
                }
            }
        }
    }
}

The possibility of adding a TextBoxField with several widget annotations has been added. This enhancement was made according to the User’s request PDFNET-58251.

Below is an example of the code used:

// For complete examples and data files, please visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddTextBoxFieldToPdf()
{
    // The path to the documents directory
    string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();

    // Create PDF document
    using (var document = new Aspose.Pdf.Document())
    {
        // Add a new page in the created document
        var page = document.Pages.Add();

        // Defining an array with rectangle data for widget annotations. 
        // The number of elements in the array determines the number of widget annotations to add.
        var rects = new Rectangle[]
        {
            new Rectangle(10, 600, 110, 620),
            new Rectangle(10, 630, 110, 650),
            new Rectangle(10, 660, 110, 680)
        };

        // Defining an array with DefaultAppearance used to specify how widget annotations are displayed in the added field.
        var defaultAppearances = new DefaultAppearance[]
        {
            new DefaultAppearance("Arial", 10, System.Drawing.Color.DarkBlue),
            new DefaultAppearance("Helvetica", 12, System.Drawing.Color.DarkGreen),
            new DefaultAppearance(FontRepository.FindFont("TimesNewRoman"), 14, System.Drawing.Color.DarkMagenta)
        };

        // Create a field
        var textBoxField = new TextBoxField(page, rects);

        // Setting the appearances of widget annotations
        short i = 0;
        foreach (WidgetAnnotation wa in textBoxField)
        {
            wa.DefaultAppearance = defaultAppearances[i++];
        }
        textBoxField.Value = "Text";

        // Add field to the document
        document.Form.Add(textBoxField);

        // Save PDF document
        document.Save(dataDir + "TextBox_out.pdf");
    }
}

Other notable enhancements

KeySummary
PDFNET-58866Enhance image compression without quality loss on PDF optimization
PDFNET-58999Updating System.Text.Json dependency version to avoid possible vulnerability
PDFNET-59123PDF signature attack detection improved to prevent false positives
PDFNET-59134Ability to edit values ​​in the ExtGState subdictionary of the resource dictionary
PDFNET-59224The Document Repair method improved to check and fix values in the Annotation.Rect array

Bug Fixing and Other Changes

KeySummaryCategory
PDFNET-47559Text stamp not properly added to PDFBug
PDFNET-51104Aspose.PDF 21.12 PdfExtractor extracts only the first four pages when the venture license is usedBug
PDFNET-55663PIN box for smart card authentication appears two times while signing a PDF documentBug
PDFNET-58328System.NullReferenceException thrown.Bug
PDFNET-59231Link annotations get duplicated on the first and second pagesBug
PDFNET-58764Creating table: Content overflow in a Table CellBug
PDFNET-56613Regression: Wrong PDF-to-XSLX conversionBug
PDFNET-59001PDF with 17 pages loads only 6 pages and the other 11 pages in the collection are nullBug
PDFNET-45923Missing text when converting particular PS to PDFBug
PDFNET-50372Converting PS to PDF produces a blank documentBug
PDFNET-46142PDF to PDF/A-2b - An exception occurs while convertingBug
PDFNET-47974WordWrap property is not working when TextStamp is rotatedBug
PDFNET-49649Bookmarks Titles are changed - Change zoom of bookmarksBug
PDFNET-52765Aspose.PDF memory leak issues while merging multiple PDF files and adding page numberBug
PDFNET-55119PostScript to PDF conversion generates empty outputBug
PDFNET-57249HTML Superscript looks different in PDF (the baseline is lower and the font bigger)Bug
PDFNET-58243PdfException when Verifying a signatureBug
PDFNET-58945Chinese language characters are not being rendered correctly when adding bookmarksBug
PDFNET-58960Copying text from one PDF to another - Rotated text is not being copied correctlyBug
PDFNET-58962Remove text failed with IndexOutOfRangeExceptionBug
PDFNET-58965Null reference error from TextFragmentAbsorberBug
PDFNET-45148Various properties of CheckBoxField are throwing NullReferenceExceptionBug
PDFNET-43012PDF to PNG - incorrect rendering of the textBug
PDFNET-44585Output PDF/A-1b - incorrect rendering of the text style symbolBug
PDFNET-44687PDF to PDF/A-1a - the output PDF does not pass the compliance testBug
PDFNET-58786PDF to TIFF: StackOverflow exceptionBug
PDFNET-58952System.IndexOutOfRangeException occurs while searching text in PDF filesBug
PDFNET-59058Flattening PDF with ‘UpdateAppearances = true’ throws IndexOutOfRangeExceptionBug
PDFNET-59092GraphicsAbsorber.Visit(Page) throws System.NullReferenceExceptionBug
PDFNET-59124PDF signature verification issueBug
PDFNET-59009Outline titles with unmatched parentheses cause corrupted PDF outlinesBug
PDFNET-57879PageNumberStamp creates the corrupted fileBug
PDFNET-58767Setting text on textFragment place cuts of the textBug
PDFNET-58863Conversion of XFA form to standard hangs.Bug
PDFNET-59149System.NullReferenceException is thrown when saving a PDF fileBug
PDFNET-59155PDF to PDF/A-2 conversion leads to “PDF-Syntax” ErrorBug
PDFNET-59054PDF/A conversion issue under load test with concurrent usersBug
PDFNET-56064Aspose.PDF 23.11.1: Loading a particular PS document throws an exceptionBug
PDFNET-58619PDF to SVG: PCDATA invalid Char errorBug
PDFNET-58625PDF to SVG: Content not rendered correctlyBug
PDFNET-58736Regression; HTML to PDF - Svg with Arabic text not rendered correctlyBug
PDFNET-59096PDF printing performance with System FontsBug
PDFNET-54768While replacing a text using TextFragment.Text throws System.NullReferenceExceptionBug
PDFNET-57609IndexOutOfRangeException thrown under Linux in PdfExtractor.ExtractTextBug
PDFNET-59093Hang while generating pageBug
PDFNET-59154Regression: The result of TextAbsorber for a page rotated by 90 has deteriorated compared to version 23.11.1Bug
PDFNET-51856OutOfMemoryException is thrown while adding SVG as ImageStampBug
PDFNET-52152System.IndexOutOfRangeException is thrown TextFragmentAbsorberBug
PDFNET-35523Bookmark issue while concatenating PDF documentsBug
PDFNET-40559API throws ArgumentNullException while attempting to access Outlines CollectionsBug
PDFNET-42362PdfBookmarkEditor throws ArgumentNullException while extracting bookmarksBug
PDFNET-57566Save does not finish/Corrupted 0kb file is generatedBug
PDFNET-37432PCL to PDF: some elements are located in the incorrect positionBug
PDFNET-38874PDF to DOCX - Hyperlinks are missing in the resultant fileBug
PDFNET-43067Bookmarks missing after PDF file concatenationBug
PDFNET-55712Different Thai characters when exporting to HTMLBug

Public API and Backward Incompatible Changes

Added APIs

  • Type: Aspose.Pdf.DataEditor.CosPdfDictionary
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.#ctor(Aspose.Pdf.Resources) System.Void
  • Property: Aspose.Pdf.DataEditor.CosPdfDictionary.AllKeys System.Collections.Generic.ICollection`1[System.String]
  • Property: Aspose.Pdf.DataEditor.CosPdfDictionary.Keys System.Collections.Generic.ICollection`1[System.String]
  • Property: Aspose.Pdf.DataEditor.CosPdfDictionary.Values System.Collections.Generic.ICollection`1[Aspose.Pdf.DataEditor.ICosPdfPrimitive]
  • Property: Aspose.Pdf.DataEditor.CosPdfDictionary.Count System.Int32
  • Property: Aspose.Pdf.DataEditor.CosPdfDictionary.IsReadOnly System.Boolean
  • Property: Aspose.Pdf.DataEditor.CosPdfDictionary.Item(System.String) Aspose.Pdf.DataEditor.ICosPdfPrimitive
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.CreateEmptyDictionary(Aspose.Pdf.Page) Aspose.Pdf.DataEditor.CosPdfDictionary
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.CreateEmptyDictionary(Aspose.Pdf.Document) Aspose.Pdf.DataEditor.CosPdfDictionary
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.ContainsKey(System.String) System.Boolean
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.Remove(System.String) System.Boolean
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.TryGetValue(System.String,Aspose.Pdf.DataEditor.ICosPdfPrimitive@) System.Boolean
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.Add(System.String,Aspose.Pdf.DataEditor.ICosPdfPrimitive) System.Void
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.Add(System.Collections.Generic.KeyValuePair{System.String,Aspose.Pdf.DataEditor.ICosPdfPrimitive}) System.Void
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.Clear System.Void
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.Contains(System.Collections.Generic.KeyValuePair{System.String,Aspose.Pdf.DataEditor.ICosPdfPrimitive}) System.Boolean
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.CopyTo(System.Collections.Generic.KeyValuePair,System.Int32) System.Void
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.Remove(System.Collections.Generic.KeyValuePair{System.String,Aspose.Pdf.DataEditor.ICosPdfPrimitive}) System.Boolean
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.GetEnumerator System.Collections.Generic.IEnumerator1[System.Collections.Generic.KeyValuePair2[System.String,Aspose.Pdf.DataEditor.ICosPdfPrimitive]]
  • Method: Aspose.Pdf.DataEditor.CosPdfDictionary.ToCosPdfDictionary Aspose.Pdf.DataEditor.CosPdfDictionary
  • Method: Aspose.Pdf.DataEditor.CosPdfPrimitive.ToCosPdfDictionary Aspose.Pdf.DataEditor.CosPdfDictionary
  • Method: Aspose.Pdf.DataEditor.DictionaryEditor.#ctor(Aspose.Pdf.Resources) System.Void
  • Method: Aspose.Pdf.DataEditor.ICosPdfPrimitive.ToCosPdfDictionary Aspose.Pdf.DataEditor.CosPdfDictionary
  • Method: Aspose.Pdf.Facades.PdfFileSignature.GetSignatureNames(System.Boolean) System.Collections.Generic.IList`1[Aspose.Pdf.Facades.SignatureName]
  • Method: Aspose.Pdf.Facades.PdfFileSignature.GetSignatureNames(System.Boolean) System.Collections.Generic.IList`1[Aspose.Pdf.Facades.SignatureName]
  • Method: Aspose.Pdf.Facades.PdfFileSignature.CoversWholeDocument(Aspose.Pdf.Facades.SignatureName) System.Boolean
  • Method: Aspose.Pdf.Facades.PdfFileSignature.GetRevision(Aspose.Pdf.Facades.SignatureName) System.Int32
  • Method: Aspose.Pdf.Facades.PdfFileSignature.RemoveSignature(Aspose.Pdf.Facades.SignatureName) System.Void
  • Method: Aspose.Pdf.Facades.PdfFileSignature.RemoveSignature(Aspose.Pdf.Facades.SignatureName,System.Boolean) System.Void
  • Method: Aspose.Pdf.Facades.PdfFileSignature.GetSignerName(Aspose.Pdf.Facades.SignatureName) System.String
  • Method: Aspose.Pdf.Facades.PdfFileSignature.GetDateTime(Aspose.Pdf.Facades.SignatureName) System.DateTime
  • Method: Aspose.Pdf.Facades.PdfFileSignature.GetReason(Aspose.Pdf.Facades.SignatureName) System.String
  • Method: Aspose.Pdf.Facades.PdfFileSignature.GetLocation(Aspose.Pdf.Facades.SignatureName) System.String
  • Method: Aspose.Pdf.Facades.PdfFileSignature.GetContactInfo(Aspose.Pdf.Facades.SignatureName) System.String
  • Method: Aspose.Pdf.Facades.PdfFileSignature.VerifySignature(Aspose.Pdf.Facades.SignatureName) System.Boolean
  • Method: Aspose.Pdf.Facades.PdfFileSignature.VerifySignature(Aspose.Pdf.Facades.SignatureName,Aspose.Pdf.Security.ValidationOptions,Aspose.Pdf.Security.ValidationResult@) System.Boolean
  • Method: Aspose.Pdf.Facades.PdfFileSignature.ExtractImage(Aspose.Pdf.Facades.SignatureName) System.IO.Stream
  • Method: Aspose.Pdf.Facades.PdfFileSignature.ExtractCertificate(Aspose.Pdf.Facades.SignatureName) System.IO.Stream
  • Type: Aspose.Pdf.Facades.SignatureName
  • Property: Aspose.Pdf.Facades.SignatureName.HasSignature System.Boolean
  • Method: Aspose.Pdf.Facades.SignatureName.ToString System.String
  • Field: Aspose.Pdf.Facades.SignatureName.Name System.String
  • Field: Aspose.Pdf.Facades.SignatureName.FullName System.String
  • Property: Aspose.Pdf.Forms.Signature.AvoidEstimatingSignatureLength System.Boolean
  • Property: Aspose.Pdf.Forms.Signature.DefaultSignatureLength System.Int32
  • Method: Aspose.Pdf.Forms.TextBoxField.#ctor(Aspose.Pdf.Page,Aspose.Pdf.Rectangle[]) System.Void
  • Property: Aspose.Pdf.ImageStamp.XIndent System.Double
  • Property: Aspose.Pdf.ImageStamp.YIndent System.Double
  • Field: Aspose.Pdf.PdfFormat.PDF_X_4
  • Type: Aspose.Pdf.Security.SignatureLengthMismatchException

Removed APIs

No removings.

For Aspose.PDF 25.2 we have completed work on the namespaces for APIs to make the structure simpler and more convenient.

Moved:

BeforeAfter
TypeAspose.Pdf.PdfToMarkdown.EmphasisStyle Aspose.Pdf.EmphasisStyle
FieldAspose.Pdf.PdfToMarkdown.EmphasisStyle.Asterisk Aspose.Pdf.EmphasisStyle.Asterisk
FieldAspose.Pdf.PdfToMarkdown.EmphasisStyle.Underscore Aspose.Pdf.EmphasisStyle.Underscore
TypeAspose.Pdf.PdfToMarkdown.HeadingRecognitionStrategy Aspose.Pdf.HeadingRecognitionStrategy
FieldAspose.Pdf.PdfToMarkdown.HeadingRecognitionStrategy.Outlines Aspose.Pdf.HeadingRecognitionStrategy.Outlines
FieldAspose.Pdf.PdfToMarkdown.HeadingRecognitionStrategy.Heuristic Aspose.Pdf.HeadingRecognitionStrategy.Heuristic
FieldAspose.Pdf.PdfToMarkdown.HeadingRecognitionStrategy.Auto Aspose.Pdf.HeadingRecognitionStrategy.Auto
FieldAspose.Pdf.PdfToMarkdown.HeadingRecognitionStrategy.None Aspose.Pdf.HeadingRecognitionStrategy.None
TypeAspose.Pdf.PdfToMarkdown.HeadingStyle Aspose.Pdf.HeadingStyle
FieldAspose.Pdf.PdfToMarkdown.HeadingStyle.Atx Aspose.Pdf.HeadingStyle.Atx
FieldAspose.Pdf.PdfToMarkdown.HeadingStyle.Setext Aspose.Pdf.HeadingStyle.Setext
TypeAspose.Pdf.PdfToMarkdown.LineBreakStyle Aspose.Pdf.LineBreakStyle
FieldAspose.Pdf.PdfToMarkdown.LineBreakStyle.Windows Aspose.Pdf.LineBreakStyle.Windows
FieldAspose.Pdf.PdfToMarkdown.LineBreakStyle.Unix Aspose.Pdf.LineBreakStyle.Unix
FieldAspose.Pdf.PdfToMarkdown.LineBreakStyle.Auto Aspose.Pdf.LineBreakStyle.Auto
PropertyAspose.Pdf.MarkdownSaveOptions.LineBreakStyle Aspose.Pdf.PdfToMarkdown.LineBreakStyleAspose.Pdf.MarkdownSaveOptions.LineBreakStyle Aspose.Pdf.LineBreakStyle
PropertyAspose.Pdf.MarkdownSaveOptions.EmphasisStyle Aspose.Pdf.PdfToMarkdown.EmphasisStyleAspose.Pdf.MarkdownSaveOptions.EmphasisStyle Aspose.Pdf.EmphasisStyle
PropertyAspose.Pdf.MarkdownSaveOptions.HeadingStyle Aspose.Pdf.PdfToMarkdown.HeadingStyleAspose.Pdf.MarkdownSaveOptions.HeadingStyle Aspose.Pdf.HeadingStyle
PropertyAspose.Pdf.MarkdownSaveOptions.HeadingRecognitionStrategy Aspose.Pdf.PdfToMarkdown.HeadingRecognitionStrategyAspose.Pdf.MarkdownSaveOptions.HeadingRecognitionStrategy Aspose.Pdf.HeadingRecognitionStrategy

Other changes:

The following Fields are changed to the Properties:

  • Aspose.Pdf.HtmlSaveOptions.SaveFullFont System.Boolean
  • Aspose.Pdf.Rectangle.Empty Aspose.Pdf.Rectangle