Print2eDoc SDK
SDK for document conversion to PDF, PNG, JPEG, TIFF...
Compatibility
VB VB.NET VC++ C# Delphi

A Web Application To Convert Documents Using Print2eDoc SDK

Use Print2eDoc SDK on a Web application to allow users to upload and convert documents to PDF, BMP, and other formats.
By Shivaranjini M.
Important

This product has been discontinued. Please check our old products page for more information.

Important

Please note that Print2eDoc SDK is no longer supported in Windows Server and Web application environments.

Print2eDoc SDK allows you to accomplish everything that the application Print2eDoc does, programmatically and silently. This means that you can choose to use Print2eDoc SDK on a Web to convert uploaded documents.

For this article, we will see a sample Web application project done in Visual Studio 2005 to convert documents using Print2eDoc SDK. (Check the downloads section for the project files.)

The ASP.NET page PrinterProperties.aspx contains a form with several Web controls. One of them is a file upload control, which allows the user to upload a file to the server. Other controls on the form allows the user to specify various output options including document creation profile that needs to be used.

The PDF Creation Properties button leads to another ASP.NET page PDFProperties.aspx. This page lists available document creation profiles and displays PDF-related settings of the selected document creation profile. The user can make changes to the profile and have the changes saved to the profile so that the uploaded document can be converted using updated profile.

Both these pages create an instance of the IgtPrint2eDoc object when they get loaded. For example, PrinterProperties.aspx.cs populates the Document Creation Profiles list box with available profiles obtained from the IgtPrint2eDoc object.

// Clear the list box
cbProfiles.Items.Clear();

string[] ProfileNames;

// Get profiles list from the IgtPrint2eDoc object
ProfileNames = (string[])PrinterObj.GetProfilesList();

// Populate the list box
for (int i = 0; i < ProfileNames.Length; i++)
{
 cbProfiles.Items.Add(ProfileNames[i]);
}
cbProfiles.SelectedValue = PrinterObj.CurrentProfileName;

Similarly, PDFProperties.aspx.cs reads the default settings in the selected profile and sets default options in the Web controls in PDFProperties.aspx.

private void ReadProfileSettings(gtProfileSettingsX AProfile)
{
  // Set the default selection states for  
  // "Content Selection" controls 
  chkText.Checked = AProfile.PDFRenderTextItem;
  chkImage.Checked = AProfile.PDFRenderImageItem;
  chkDrawing.Checked = AProfile.PDFRenderDrawingItem;
  chkExportAsImage.Checked = AProfile.PDFExportAsImage;

  ...
  
  // Set the default selection in 
  // the "Text Compression Level" list box
  cbTextCompressionLevel.SelectedIndex = 
                (int)AProfile.PDFTextCompressionLevel;

  ...

}

The button click event for the Print button is used to save the file selected in the file upload control to the server. The saved file is then converted using the current document creation profile. The converted file is also saved as per settings chosen by the user in the PrinterProperties.aspx page.

if (FileUpload1.HasFile) {
 string FileName;
 FileName = 
  string.Concat(
           Server.MapPath(
                    Path.GetFileName(
                           FileUpload1.FileName)));
 FileUpload1.SaveAs(FileName);
 PrintDocument(FilName);
 // Delete the file after it is converted
 File.Delete(FileName);     
}

private void PrintDocument(string AFilName)
{
 // Set printer properties using selected 
 // values of Web controls
 PrinterObj.OutputDocumentFormat =
  (TxgtDocumentFormat)cbOutputFileFormat.SelectedIndex;
 PrinterObj.UseCustomDocumentName = true;
 PrinterObj.DefaultOutputDirectory = 
   Path.GetDirectoryName(txtOutputFileName.Text);
 PrinterObj.OutputDocumentName = 
   Path.GetFileName(txtOutputFileName.Text);
 PrinterObj.SelectCurrentProfile(cbProfiles.Text);

 ...

 // Disable interactive dialogs
 PrinterObj.ShowPreview = false;
 PrinterObj.ShowSaveDialog = false;
 PrinterObj.ShowSettingsDialog = false;
 PrinterObj.ViewGeneratedDocuments = false;
 PrinterObj.KeepOfficeApplicationsOpen = false;

 PrinterObj.FileExistsOption = 
              TxgtFileExistsOption.feReplaceDirectly;
 PrinterObj.ApplyOfficeAddinSettings = 
              chkApplySettings.Checked;

 ...
 
 // Check uploaded file's extension
 if (string.Compare(
              Path.GetExtension(AFilName),
              ".rtf",
              true) == 0 ||
     string.Compare(
              Path.GetExtension(AFilName), 
              ".doc", 
              true) == 0)
 {
  // Convert the file using Word add-in settings
  PrinterObj.Update();
  PrinterObj.PrintWordDocument(AFilName);
 }
 else if (string.Compare(
              Path.GetExtension(AFilName), 
              ".xls", 
              true) == 0)
 {
   // Convert the file using Excel add-in settings
   PrinterObj.Update();
   PrinterObj.PrintExcelDocument(AFilName);
 }
 else if (string.Compare(
              Path.GetExtension(AFilName), 
              ".ppt", 
              true) == 0)
 {
  // Convert the file using PowerPoint add-in settings
  PrinterObj.Update();
  PrinterObj.PrintPowerPointPresentation(AFilName);
 }
 else
 {
   // Convert the file using file type's default application
   PrinterObj.PrintDocument(AFilName);
 }
}

The converted file can then be e-mailed to the user or sent back to the browser as a binary download using other components.

---o0O0o---

Downloads:

Privacy | Legal | Feedback | Newsletter © 2002-2010 Gnostice Information Technologies Private Limited. All rights reserved.

This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows users are advised to use Microsoft ClearType Tuning for optimal experience. Linux and other users can enable font smoothing, as supported by their OS. Also, please use the latest version of a standards-compliant browser such as Opera, FireFox, Chrome or Safari.