Quantcast
Channel: Nayyer Shahbaz – Blog – Aspose.com
Viewing all articles
Browse latest Browse all 129

XFA to Standard AcroForm, adding layers to PDF, get hyperlink destination, improved PDF optimization with Aspose.Pdf for .NET 9.3.0

$
0
0

aspose Pdf for net 100 XFA to Standard AcroForm, adding layers to PDF, get hyperlink destination, improved PDF optimization with Aspose.Pdf for .NET 9.3.0Aspose team is always enthusiastic to introduce new and exciting features/enhancements in its API’s, where the main intent is to provide out of the box API’s which can make our customers life easy. We all know that life has many complications, but here at Aspose, we try to bring a bit relief to our customers by preventing them from doing the tedious work which is required during document manipulation. We always thrive to present products which are simple and easy to use, so that our customers focus on their business logic and forget about inner details/implementations. Nevertheless, we ensure that all our products are quality orientated, up-to the industry standards and they undergo thorough testing before they are published.

Aspose.Pdf for .NET is one of the award winning API and over the years, it has been helping the customers for PDF document creation as well as manipulation. In every new release, the development team works really hard to introduce new demanding features and fix issues reported in earlier versions, so that a better version of API is presented to our users. Keeping the similar tradition alive, we have introduced some new features in latest version of Aspose.Pdf for .NET 9.3.0.

Dynamic XFA to Standard AcroForm conversion

Dynamic forms are based on an XML specification known as XFA, the “XML Forms Architecture”. The information about the form (as far as PDF is concerned) is very vague – it specifies that fields exist, with properties, and JavaScript events, but does not specify any rendering. The contents of such forms are rendered during the PDF display process by respective viewer application. Due to this nature/structure of forms, if we directly try to convert it to image format, nothing is rendered in resultant files. Therefore, first these forms should be converted to Standard AcroForms and then the conversion to image can be performed. Aspose.Pdf for .NET supports the feature to convert XFA forms to standard forms. In order to cater this requirement, the values from an enumeration named FormType can be passed to Document.Form.Type property. For further details, please follow the instructions specified over Convert Dynamic XFA form to Standard AcroForm

Set Document access Privilege using Aspose.Pdf DOM

Aspose.Pdf.Generator namespace provides the capability to create PDF files from scratch and during PDF creation, you may consider setting document access privileges (restrictions). Similarly, the Aspose.Pdf.Facades namespace has been offering the feature to set document access privileges to existing PDF documents for quite sometime. However recently we have received a requirement to support similar feature in new Document Object Model of Aspose.Pdf namespace, so that a single approach can be used to set access privileges while creating new document, as well as manipulating existing one. For further details, please visit Set Privileges on an Existing PDF File

Adding Layer on existing PDF

Adding layers in a PDF is a very unique concept. It can be very useful for cases where multi-lingual file that you want to distribute and have text in each language appear on different layers, with the background design appearing on a separate layer as well. The latest release of Aspose.Pdf for .NET 9.3.0 supports the feature to add layers to PDF documents. For further information, please visit Add Layers to PDF file

Getting hyperlink destination

Hyperlinks are added as LinkAnnotation in PDF file. Aspose.Pdf for .NET supports the feature to Add hyperlink in PDF file , Update links in PDF file, Extract links from PDF file and it also offers the capability to get the destination URL of LinkAnnotation (hyperlink) in PDF document. In order to get the destination URL of link, get the LinkAnnotation Action as GoToURIAction. For further details, please visit the following link Get PDF Hyperlink destination (URL).

Remove Signature and keep signature field

The RemoveSignature(..) method in PdfFileSignature class provides the capability to remove signature field from PDF file. When using this method with versions earlier to 9.3.0, it removes both signature and signature field as well. However we received a requirement to support only removing the signature and keeping the signature field, so that the same field can be used to resign the document. In order to keep the signature field and only remove the signature, please try using following code snippet.


private static void Run_34561_tests()
{
    new License().SetLicense(@"E:\Aspose.Pdf.lic");
    string inSingleSignedFile = @"C:\pdftest\PDFNEWNET_34561_SingleSigned.pdf";
    string outSingleUnsignedFile = @"C:\pdftest\PDFNEWNET_34561_SingleUnSigned.pdf";
    string inOutSingleResignedFile = @"C:\pdftest\PDFNEWNET_34561_SingleReSigned.pdf";

    PdfFileSignature pdfSignSingle = new PdfFileSignature();
    pdfSignSingle.BindPdf(inSingleSignedFile);
    IList names = pdfSignSingle.GetSignNames();
    Stream pfx = new FileStream(@"C:\pdftest\test1.pfx", FileMode.Open);
    PKCS7 pcks = new PKCS7(pfx, "test1");
    string sigNameSingle = names[0] as string;
    if (sigNameSingle != null && sigNameSingle != string.Empty)
    {
        pdfSignSingle.RemoveSignature(sigNameSingle, false);
        pdfSignSingle.Save(outSingleUnsignedFile);

        PdfFileSignature pdfSignSingle2 = new PdfFileSignature();
        pdfSignSingle2.BindPdf(outSingleUnsignedFile);
        pdfSignSingle2.SignatureAppearance = @"C:\pdftest\butterfly.jpg";
        pdfSignSingle2.Sign("Signature1", pcks);
        pdfSignSingle2.Save(inOutSingleResignedFile);
        pdfSignSingle2.BindPdf(inOutSingleResignedFile);
        // Assert.True(pdfSignSingle2.VerifySignature("Signature1"));
        Console.Write("Signature 1 check result : " + pdfSignSingle2.VerifySignature("Signature1").ToString() + " \n");
    }

    // Test file with multiple signatures
    string inManySignedFile = @"C:\pdftest\PDFNEWNET_34561_ManySigned.pdf";
    string outManyUnsignedFile = @"C:\pdftest\PDFNEWNET_34561_ManyUnSigned.pdf";
    string inOutManyResignedFile = @"C:\pdftest\PDFNEWNET_34561_ManyReSigned.pdf";
    PdfFileSignature pdfSignMany = new Aspose.Pdf.Facades.PdfFileSignature(inManySignedFile);

    IList sigNames = pdfSignMany.GetSignNames();
    foreach (string sigName in sigNames)
    {
        pdfSignMany.RemoveSignature(sigName, false);
    }

    pdfSignMany.Save(outManyUnsignedFile);

    PdfFileSignature pdfSignMany2 = new PdfFileSignature();
    pdfSignMany2.BindPdf(outManyUnsignedFile);
    pdfSignMany2.Sign("Signature1", pcks);
    pdfSignMany2.Save(inOutManyResignedFile);
    pdfSignMany2.BindPdf(inOutSingleResignedFile);
    //Assert.IsTrue(pdfSignMany2.VerifySignature("Signature1"));
    Console.Write("Signature 2 check result : " + pdfSignMany2.VerifySignature("Signature1").ToString() + " ");
}

For details can be found over Remove Digital Signature from the PDF File (Facades)

Generate 3 sets of fonts to ensure maximum browser compatibility

Prior to the release of Aspose.Pdf for .NET 9.3.0, the API supported the feature to either save the fonts as WOFF or TTF. So unfortunately the fonts could not be loaded in IE6 – IE8, meaning documents didn’t look right when viewed in these browsers. Also for mobile browsers, the TTF fonts were required for maximum compatibility. So the solution was to generate 3 sets of fonts, to ensure maximum browser compatibility and then reference all fonts in the CSS like as shown below. The following format is similar somewhat described over this link.


@font-face {
	font-family:"WBULFR+Arial-BoldMT";
	src:url("fa507958-0001-0000-0000-000000000000.eot");
	src:url("fa507958-0001-0000-0000-000000000000.eot?#iefix") format("embedded-opentype"),
	url("fa507958-0001-0000-0000-000000000000.woff") format("woff"),
	url("fa507958-0001-0000-0000-000000000000.ttf") format("truetype");
}

In order to accomplish this requirement, SaveInAllFormats font saving mode is introduced in HtmlSaveOptions.FontSavingModes enumeration. Following code snippet demonstrates how to generate 3 sets of fonts:


string inPdf = @"F:\ExternalTestsData\36192.pdf";
string outHtml = @"F:\ExternalTestsData\36873.html";

Document doc = new Document(inPdf);
HtmlSaveOptions htmlOptions = new HtmlSaveOptions();
htmlOptions.FixedLayout = true;
htmlOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsExternalPngFilesReferencedViaSvg;
htmlOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.SaveInAllFormats;

doc.Save(outHtml, htmlOptions);

Further details regarding this feature can be found over, PDF to HTML – Save Fonts as WOFF or TTF.

As well as the new features above, this new version includes fixes related to PDF to image conversion, saving PDF files in a particular PDF version, deleting images from PDF files, performance improvements when generating PDF files and much more. Go ahead, download and start exploring the new release of Aspose.Pdf for .NET 9.3.0.


Viewing all articles
Browse latest Browse all 129

Trending Articles