Creating Adobe PDF documents

TX Text Control .NET Server for ASP.NET includes a powerful PDF engine to create PDF documents in a very fast and reliable manner.

This demo shows how to convert a DOCX document to PDF and how to set various document access permissions using the SaveSettings object.

Demo





Password:


Did you know that TX Text Control is not only able to create Adobe PDF files, but allows the import of PDF files as well? Load PDF documents into TX Text Control and reuse formatted content.

Sources

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace tx_aspnet_samples.Basics
{
    public partial class pdf : System.Web.UI.Page
    {
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            // create a new instance of ServerTextControl
            using (TXTextControl.ServerTextControl tx = 
                new TXTextControl.ServerTextControl())
            {
                tx.Create();

                // load the sample document
                tx.Load(Server.MapPath("/documents/sample.docx"), 
                    TXTextControl.StreamType.WordprocessingML);

                TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings();
                
                // set the document access permissions based on the checkboxes
                TXTextControl.DocumentAccessPermissions permissions = 
                    new TXTextControl.DocumentAccessPermissions();
                    

                if (cbAllowHighLevelPrinting.Checked == true)
                    permissions = 
                        TXTextControl.DocumentAccessPermissions.AllowHighLevelPrinting;

                if (cbAllowDocumentAssembly.Checked == true)
                    permissions = permissions | 
                        TXTextControl.DocumentAccessPermissions.AllowDocumentAssembly;

                if (cbAllowExtractContents.Checked == true)
                    permissions = permissions | 
                        TXTextControl.DocumentAccessPermissions.AllowExtractContents;

                if (cbAllowGeneralEditing.Checked == true)
                    permissions = permissions | 
                        TXTextControl.DocumentAccessPermissions.AllowGeneralEditing;

                saveSettings.DocumentAccessPermissions = permissions;

                saveSettings.MasterPassword = tbPassword.Text;
                saveSettings.UserPassword = tbPassword.Text;

                // save the document as PDF in a byte array
                byte[] data;
                tx.Save(out data, TXTextControl.BinaryStreamType.AdobePDF, saveSettings);

                // return the document to the browser for download
                Response.Clear();
                Response.AddHeader("content-disposition",
                    String.Format("attachment;filename={0}", "txtextcontrol.pdf"));
                Response.ContentType = "application/pdf";
                Response.BinaryWrite(data);
                Response.End();
            }
        }
    }
}

ServerTextControl Basics