How to Convert Office File to PDF File Format in C#

How to Convert Office file to pdf in C#.

These codes are used for Microsoft Office products with the Save As PDF add-in installed.

Note that You will need to add a reference to Microsoft.Office.Interop.(word,excel, or powerpoint)

<Word To PDF>

public string ConvertWordToPdf(string inputFile)
{
string outputFileName = “Desired Output File Path”;
Microsoft.Office.Interop.Word.ApplicationClasswordApp =
new rosoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document wordDoc = null;
object inputFileTemp = inputFile;

try
{
wordDoc = wordApp.Documents.Open(refinputFileTemp);
wordDoc.ExportAsFixedFormat(outputFileName, WdExportFormat.wdExportFormatPDF);
}
finally
{
if (wordDoc != null)
{
wordDoc.Close(WdSaveOptions.wdDoNotSaveChanges);
}
if (wordApp != null)
{
wordApp.Quit(WdSaveOptions.wdDoNotSaveChanges);
wordApp = null;
}
}

return outputFileName;
}

<Excel To PDF>

public static string ConvertExcelToPdf(string inputFile)
{
string outputFileName = “DesireOutput File Path”;
Microsoft.Office.Interop.Excel.Application excelApp =
new Microsoft.Office.Interop.Excel.Application();
excelApp.Visible = false;
Workbook workbook = null;
Workbooks workbooks = null;
try
{
workbooks = excelApp.Workbooks;
workbook = workbooks.Open(inputFile);
workbook.ExportAsFixedFormatXlFixedFormatType.xlTypePDF,outputFileName,
XlFixedFormatQuality.xlQualityStandard, true, true, Type.Missing,Type.Missing, false,Type.Missing);
}
finally
{
if (workbook != null)
{
workbook.Close(XlSaveAction.xlDoNotSaveChanges);
while(Marshal.FinalReleaseComObject(workbook) != 0) { };
workbook = null;
}
if (workbooks != null)
{
workbooks.Close();
while(Marshal.FinalReleaseComObject(workbooks) != 0) { };
workbooks = null;
}
if(excelApp != null)
{
excelApp.Quit();
excelApp.Application.Quit();
while(Marshal.FinalReleaseComObject(excelApp) != 0) { };
excelApp = null;
}
}

return outputFileName;
}

<PowerPoint To PDF>

public static string ConvertPowerPointToPdf(string inputFile)
{
string outputFileName = “DesireOutput File Path”;
Microsoft.Office.Interop.PowerPoint.ApplicationClass powerPointApp =
new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
Presentation presentation = null;
Presentations presentations = null;
try
{
presentations = powerPointApp.Presentations;
presentation = presentations.Open(inputFile, MsoTriState.msoFalse,MsoTriState.msoFalse,
MsoTriState.msoFalse);

presentation.ExportAsFixedFormat(outputFileName, PpFixedFormatType.ppFixedFormatTypePDF,
PpFixedFormatIntent.ppFixedFormatIntentScreen, MsoTriState.msoFalse,
PpPrintHandoutOrder.ppPrintHandoutVerticalFirst,PpPrintOutputType.ppPrintOutputSlides,
MsoTriState.msoFalse,null,PpPrintRangeType.ppPrintAll, string.Empty, false, true, true, true, false,
Type.Missing);
}
finally
{
if (presentation != null)
{
presentation.Close();
Marshal.ReleaseComObject(presentation);
presentation = null;
}
if (powerPointApp != null)
{
powerPointApp.Quit();
Marshal.ReleaseComObject(powerPointApp);
powerPointApp = null;
}
}
return outputFileName;

}

Kyoungsu Do
Software Quality Engineer
ImageSource, Inc.

How to Count Multi-Page TIFF Files

Here is the simple TIFF file page counter using TiffBitmapDecode.

This code works for most cases. Some TIFF file compression may not work.

 

Kyoungsu Do
Software Quality Engineer
ImageSource, Inc. 

 

Making Form Screenshots In .NET

Have you ever need to take a screenshot of your .NET form from code within the form?  Some sort of print screen method?  Don’t touch that PrtSc button just yet, there is another way.

No, I’m not talking about using the gdi32.dll or the Visual Basic Power Pack.  The .NET graphics object has it’s own built in screenshot-taking ability, and ImageSource is here to help show you how to use it.

Getting a screenshot of your form is as easy as instantiating a Bitmap object (sized to your form’s width and height), creating a graphics object from that bitmap and finally calling Graphics object’s CopyFromScreen method.  The code below demonstrates how to do this:

private Bitmap GetFormScreenshot(Form frmRef)
{
   //Setup the bitmap and graphics objects
   Bitmap bmp = new Bitmap(frmRef.Width, frmRef.Height,
      PixelFormat.Format32bppArgb);
   Graphics gfx = Graphics.FromImage(bmp);

   //Take the screenshot
   gfx.CopyFromScreen(frmRef.Bounds.X, frmRef.Bounds.Y, 0, 0,
       frmRef.Bounds.Size, CopyPixelOperation.SourceCopy);

   return bmp;
}

Wow, it’s just that simple.  Enjoy the rest of your day knowing that you’ll be screenshotting your troubles away.

Adventures with IPM 11g continued (Part 2)

I thought it would be simple. Take the very first example from the Oracle examples for IPM 11g, compile it, and start adding my own code. This is my standard way to learn a new API (and probably yours, too). Start with the examples and keep adding functions to exercise features.

Well, I followed the instructions provided with the example programs (basically copy down some Jar files and put them on your classpath), and while the program compiles fine, I get a NoClassDefFoundError, which is common enough in Java when you use dynamic loading (Class.forName was something I used quite a bit in the old days).

However, the class it can;t find is weblogic.xml.jaxp.RegistryParser which should be in one of the Weblogic jar files; but I cannot find it. Oracle tech support also can’t locate it. I am waiting to hear back from their 2nd line support. Is it really that hard?

Anybody else out there used the examples?

  

Adventures with Oracle IPM 11g (part 1)

Part 1.

Oracle starting shipping its latest IPM product, 11g earlier this quarter. As a company, ImageSource has been working as a partner with Oracle on this next step in their ECM evolution. I, personally, am a little late to the 11g game, so I will be sharing with you my impressions as a relative newcomer to the 11g world.

First off, 11g is a complete rewrite from IPM 7.7.x and the 11g install is big. The download is well over a gigabyte and I ended up downloading two other components in excess of 700M apiece. Installation is no picnic either. It’s been my experience over the years that Oracle produces products which are hard to install and configure properly, but once properly setup, they can outperform anything else in their class.

I will admit that I was unable to get my 11g system installed properly (I still say it’s Oracle’s fault, but that’s a long story; it also had to do with the undersized server I was attempting to use), but the guys in the Tech Support and Services department are letting me use one of their installs to get my dev system booted.

11g  is written in Java and lives on top of WebLogic and the rest of Oracle’s Fusion Middleware products, so it’s time to dust off the old Java coding skills. The Fusion Middleware stuff is good news for customers and developers who want to integrate with any number of Oracle back-end systems (PeopleSoft, JD Edwards, etc). It will be much more tightly integrated.

My first impression of the new web interface for the Imaging piece is that it’s nice, but not “wow!” but better than before. Some of the icons look a little clunky, but I suppose we will get used to them. The controls I’ve seen have both Tooltips and annoying Ajax popup menus. I’ve not had a chance to look very deeply into Process Management piece, which is built on BPEL, but I’ll be blogging more on it as I get deeper into in.

The API into the system is kind of the reverse from the IPM 7.7 way of doing things. There, the WebService API called down into the COM layer. Here, the Java client-side calls all go into the WebServices on the server. There’s no actual “client” codebase or DLL to call into. You log into one of several webservices (ApplicationService, ConnectionService, DocumentContentService, DocumentService, ImportExportService,LoginService, PreferenceService, SearchServiceService, SecurityService, TicketService) and proceed from there.

  

ILINX Capture 4 Web Client Enhancements

Welcome to 2010!  Hope you all had a great holiday

Below are two of my most favorite features in ILINX Capture 4 web client.

clip_image001[5]

Detachable Viewer

ILINX Capture 4 now supports detachable viewer – enabling the indexing panel to be on one screen and the image on another screen.

image

Personalization

ILINX Capture 4 enables more configuration settings on the web client.  Both scanning options and confirmation prompts are now configurable

image

There also a tons of other improvements under the cover both on the client and server, but I find myself using these two features above the most.

Hope this helps.

  

failed due to the following error: 80040154.

As a developer, I install and uninstall all sort of programs on my system so I am not surprised when some weird and random error message popped up. 

I ran into the following error dialog today when I was writing some .NET integration code with EMC AppXtender.

image

This exception was thrown when I was trying to create the AppXtender DBConnection object.  So I fired up the AppXtender Document Manager to verify my installation and it ran successfully.

Going back to my Visual Studio project, I verified the Interop.AEXDBLib reference and that seems right.  A quick search on MSDN on error code 80040154 showed a list of COM errors on 32-bit OS, and I am seeing this error on my 64-bit OS.

The fix is to change the Platform target of my .NET solution to x86. 

clip_image001[6]

Hope this helps.

  

Follow

Get every new post delivered to your Inbox.