Converting Office Documents to PDF with the Office Interop Assemblies

Office, SharePoint 2010, SharePoint 2013, Office Interop Assemblies, PDF Conversion, SharePoint 2010, SharePoint 2013

image

If you want to convert a document to PDF you can save it as PDF (File -> Export -> PDF). But what if you have a lot of documents you want to convert to PDF. Then the Office Interop Assemblies could help you. This blog explains how you could use the Office Interop Assemblies to convert Word, PowerPoint and Excel files to PDF.

Prerequisites:
– Microsoft Office needs to be installed
– Some dev skills

This is not something you would like to use on a large production environment. But if you are in need of a onetime solution this could be a solution. Always keep in mind that you backup your Office documents and check the results after converting.

Word

Add Assembly reference to project: Microsoft.Office.Interop.Word

Code:

var wordApp = new Microsoft.Office.Interop.Word.Application();

var wordDocument = wordApp.Documents.Open(@"C:\WordDocument.docx");

          

wordDocument.ExportAsFixedFormat(@"C:\NewPDFFile.PDF", Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);

 

wordDocument.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges,

                   Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat,

                   false); //Close document

 

wordApp.Quit(); //Important: When you forget this Word keeps running in the background

 

 

PowerPoint

Add Assembly reference to project: Microsoft.Office.Interop.PowerPoint

Code:

var powerpointApp = new Microsoft.Office.Interop.PowerPoint.Application();

 

var powerpointDocument = powerpointApp.Presentations.Open(@"C:\PowerPoint.pptx",

                Microsoft.Office.Core.MsoTriState.msoTrue, //ReadOnly

                Microsoft.Office.Core.MsoTriState.msoFalse, //Untitled

                Microsoft.Office.Core.MsoTriState.msoFalse); //Window not visible during converting

         

powerpointDocument.ExportAsFixedFormat(@"C:\NewPDFFile.pdf",

                Microsoft.Office.Interop.PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF);

 

powerpointDocument.Close(); //Close document

powerpointApp.Quit(); //Important: When you forget this PowerPoint keeps running in the background

 

Excel

Add assembly reference to project: Microsoft.Office.Interop.Excel

Code:

var excelApp = new Microsoft.Office.Interop.Excel.Application();

 

var excelDocument = excelApp.Workbooks.Open(@"C:\ExcelDocument.xlsx");

 

excelDocument.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF,

                                  @"C:\NewPDFFile.pdf");

 

excelDocument.Close(false, "", false); //Close document

excelApp.Quit(); //Important: When you forget this Excel keeps running in the background

 

VeryDOC has "DOC to Any Converter Command Line" and "DOC to Any Converter SDK/COM" products, these products are support Office Interop Assemblies and other technologies, you can use "DOC to Any Converter" Command Line or SDK/COM to convert office files to PDF files with or without MS Office installed in your system,

http://www.verydoc.com/doc-to-any.html

You can call "DOC to Any Converter Command Line" or "DOC to Any Converter SDK/COM" product to convert office files to PDF files from C#, PHP, ASP, ASP.NET, Javascript, VBScript, C++, VB, Delphi, FoxPro, Java, etc. program languages,

http://www.verydoc.com/blog/verydoc-doc-to-any-converter-command-line-v3-5-release-notes-convert-word-to-pdf-without-office-and-openoffice.html

http://www.verydoc.com/blog/verydoc-release-notes-verydoc-releases-an-exe-com-of-verypdfcomruncmd-exe-today-verypdf-exe-com-does-allow-you-to-call-ms-office-and-any-exe-application-from-asp-php-c-net-etc-program-languag.html

http://www.verydoc.com/blog/how-to-call-doc2any-exe-from-php-source-code.html

VN:F [1.9.20_1166]
Rating: 1.0/10 (1 vote cast)
VN:F [1.9.20_1166]
Rating: +1 (from 1 vote)
Posted in DOC to Any Converter | Tagged , , | 1 Comment

Do you have an API software solution we could try in order to convert our PDF's to a clean PS or Postscript file?

Hi there,

We are a printing solutions company who has their own bespoke software for printing our documents.

We are considering converting all of our documents to a more viewable PDF format.

However for printing we are looking for a PostScript solution, do you have an API software solution we could try in order to convert our PDF's to a clean PS file.

We have used GhostScript in the past and for many documents it produced files which printed too slowly for our needs.

If you could let me know I would be most grateful.

Thanks.
Customer
----------------------------------------------

image
Please download PDF to Vector Converter Command Line from following web page to try, you can use PDF to Vector Converter Command Line to convert PDF file to PS file quickly,

http://www.verydoc.com/pdf-to-vector.html
http://www.verydoc.com/pdf2vec_cmd.zip

for example,

pdf2vec.exe -psmode 0 C:\in.pdf C:\out.ps
pdf2vec.exe -psmode 1 C:\in.pdf C:\out.ps
pdf2vec.exe -psmode 2 C:\in.pdf C:\out.ps

VeryDOC
----------------------------------------------
Thanks for this.

My initial testing is showing some good output.

To give you some background we produce PDF output but have limited print options unless we convert the files to PS, we still need to use PCL drivers.

So far this solution looks good.

I have a few questions.

1. Can we select a number of pages (a page range) rather than produce the entire PDF to PS?

2. It seems as though using pdf2vec.exe -psmode 2 gives us the best output -psmode 0 seems to be producing huge PS and the output is erratic when sent to a printer and -psmode 1 seems to produce just one page does this sound correct for what we are trying to do?

Thanks so far for your help.

Best regards
Customer
----------------------------------------------
>>1. Can we select a number of pages (a page range) rather than produce the entire PDF to PS?

-firstpage <int> : first page to print, from 1 to max page
-lastpage <int> : last page to print, from 1 to max page

You can run following command line to select a number of pages (a page range) from PDF file to PS file,

pdf2vec.exe -psmode 0 -firstpage 10 -lastpage 20 E:\pagetest.pdf E:\pagetest.ps

pdf2vec.exe -psmode 1 -firstpage 10 -lastpage 20 E:\pagetest.pdf E:\pagetest.ps

pdf2vec.exe -psmode 2 -firstpage 10 -lastpage 20 E:\pagetest.pdf E:\pagetest.ps

>>2. It seems as though using pdf2vec.exe -psmode 2 gives us the best output psmode 0 seems to be producing huge PS and the output is erratic when sent to a printer and psmode 1 seems to produce just one page does this sound correct for what we are trying to do?

Yes, "-psmode 1" does create a PS file for each PDF page, you can write a simple script to send these PS files to target printer one by one.

"-psmode 0" and "-psmode 2" are all can convert PDF files to PS files quickly and properly, they are using different render technologies to convert PDF files to Postscript files.

You can test the output PS files carefully by these options, if you need any assistance, please feel free to let us know, we will assist you asap.

VeryDOC

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)
Posted in PDF to Vector Converter | Tagged , | Leave a comment

How to compress, shrink and reduce PDF files? Reducing PDF file size for Email attachment.

Hello,

Can you offer a special version of the pdf-compressor-software where the grade of compression is selectable and where the resulting file size is shown before the compression-process is executed?!

image

And do you have a pdf-software that makes it possible to increase the contrast of a scanned document because when I scan a document the background of the resulting site is usually (divergent from the original-document; using a HP-Scanner) not really white (as the original-document) it is more likely light grey?!

Best regards,
Customer
--------------------------------------------------------

How do I reduce/compress PDF file size from scanned document

Hi Guys,

I just bought a HP  M1217nfw MFP, being a real estate agent, where I have to scan 20 pages per document, and the scan function with 75 dpi and output to a pdf document gives me a file of 14 Mbytes. There is no way i can send this via email. I used to be able to scan 20 pages with the HP Officejet into a much smaller file.

Any help would be appreciated on how i can get small sized scanned files. My alternative is to take back the printer to Staples

Thanks so much for your help
Customer
--------------------------------------------------------

image
Please download "VeryDOC PDF Compressor Command Line" from following web page to try,

http://www.verydoc.com/pdfcompressor.html
http://www.verydoc.com/url/pdfcompressor.zip
http://www.verydoc.com/pdfcompressor-cmd.html

You can use "VeryDOC PDF Compressor Command Line" to compress PDF files easily by following command lines,

pdfcompressor.exe -ci jpg -cidown -cidownres 50 -gi jpg -gidown -gidownres 50 -mi fax -midown -midownres 50 C:\in.pdf C:\out.pdf

pdfcompressor.exe -jbig2 -jpx C:\in.pdf C:\out.pdf

"VeryDOC PDF Compressor Command Line" does show compression ratio information after conversion, if you encounter any problem with this version, please feel free to let us know.

VeryDOC PDF Compressor does compress PDF file size. VeryDOC PDF Compressor component serves the purpose of optimizing PDF documents specifically in preparation for certain applications such as web-based publication, data exchange or printing.

VeryDOC

VN:F [1.9.20_1166]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)
Posted in PDF Compressor | Tagged , | Leave a comment

PDF Parser in Spool File Page Counter SDK is not parse paper size (A4, A3 etc.) from PDF file correctly?

Hello support,

We are testing Spool File Page Counter SDK, but parser for PDF for recognizing format (A4, A3 etc.) is not working (also for test file from directory sample).

We would like to use this SDK also for parser PDF files directly.

Thank you for the solution, we will buy it developer license after solving this problem.

Thank you for any solution.

Lower priority issue: Canon PCL6 drivers are not supported, is there any way (some tested drivers for Canon) which are supported for parser by this SDK?

Thank you.
Customer
------------------------------------------------

image
We apologize for any inconvenience this may have caused to you, can you please send to us your sample PDF file and Canon PCL6 file? after we checked your sample files, we will figure out a solution to you asap.

btw, we have tried to parse "test_colors.pdf" file in "sample" folder, everything is fine,

vc_test.exe E:\ps-and-pcl-info-sdk\bin\sample\test_colors.pdf
=============================
Page 1 is [Color]
Page 2 is [ Gray]
Page 3 is [ BW]
=============================
Statistics: bwPageCount=2, colorPageCount=1
=======================================
File = 'E:\ps-and-pcl-info-sdk\bin\sample\test_colors.pdf'
Return Value = TRUE
bIsRenderToPDF = 1
bwPageCount = 2
colorPageCount = 1
copyCount = 1
PageWidth = 0
PageHeight = 0
PaperSizeName = ''

VeryPDF
------------------------------------------------
Hello support,

PDF PaperSizeName issue:

Column PaperWidth, Paper Height, and PaperSizeName are not working. For example in PaperSizeName we need for example A4 format for A4 pdf.

Test file is attached.

Thank you.
Customer
------------------------------------------------
Canon issue:

prn file and result is attached.

Notice: this is probably something special in Canon PCL6 driver, because, if this status page is sent to other vendor than Canon, the result is the same - 563 BW pages are printed.

Thank you
Customer
------------------------------------------------
Please download the latest version from following URL to try again, you can use this version to extract paper size from PDF file properly,

http://www.verydoc.com/ps-and-pcl-info-sdk.zip

For example,

D:\downloads2>E:\ps-and-pcl-info-sdk\bin\vc_test.exe D:\downloads\ricoh.pdf
=============================
Page 1 is [Color]
Page 2 is [Color]
Page 3 is [Color]
Page 4 is [Color]
Page 5 is [Color]
Page 6 is [Color]
=============================
Statistics: bwPageCount=0, colorPageCount=6
=======================================
File = 'D:\downloads\ricoh.pdf'
Return Value = TRUE
bIsRenderToPDF = 1
bwPageCount = 0
colorPageCount = 6
copyCount = 1
PageWidth = 5960
PageHeight = 8400
PaperSizeName = ''

VeryPDF
------------------------------------------------
Hello support,

Thank you for this version, PageWidth and PageHeight are working correctly.

Best regards
Customer

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)
Posted in PCL, PS, PDF Page Counter | Tagged , | Leave a comment

What conversion product is the best to be used as a part of conversion service implemented with .NET C# Framework 4.0

Hello Support.

We are looking for a conversion solution (library) to create an automatic conversion service.

Input formats will include all of MS Office document formats and most usable industry image formats.

We have downloaded and tested your Doc2Any command utility. It looks pretty attractive especially Vector conversion.

I tested the software on Windows 7 work station, but the service will be running on Windows 2008 server machine where normally MS Office is not installed. We can install it on server box, but would like to avoid well known problems related to MS Office automation on server environment.

I saw the utility can convert without Office library involved, but in this case output PDF files have unmatched page content formatting.

Using Office gives much better result.

So there are several questions I would like to clarify:

1. What conversion product is the best to be used as a part of conversion service implemented with .NET C# Framework 4.0?

2. Does Doc2Any using Office automation? Does it require Office profile to exist?

3. Does command utility return any conversion status to the client program, is there any process log?

4. Is it possible to add Searchable PDF function if needed?

5. Is any possibility to control the conversion process from a client program?

6. Does COM version provide all the functionality and conversion quality as command utility.

Regards
Customer
-----------------------------------------------------------------
>>1. What conversion product is the best to be used as a part of conversion service implemented with .NET C# Framework 4.0?

Doc2Any Command Line is the best software to convert office files to PDF files.

>>2. Does Doc2Any using Office automation? Does it require Office profile to exist?

Doc2Any Command Line does convert office files to PDF files WITH and WITHOUT MS Office and OpenOffice.

If your system has MS Office or OpenOffice installed, Doc2Any Command Line will call MS Office or OpenOffice to do the conversion automatically.

If your system hasn't MS Office and OpenOffice installed, Doc2Any Command Line will use ourself's Office Document Reader to convert office files to PDF files, in this case, Doc2Any Command Line doesn't use MS Office and OpenOffice at all.

>>3. Does command utility return any conversion status to the client program, is there any process log?

doc2any.exe will create "doc2any.log" file and log message to console, you can check log messages easily.

>>4. Is it possible to add Searchable PDF function if needed?

doc2any.exe does convert office files to searchable PDF files automatically.

However, if source documents are scanned image files, you can use "PDF to Text OCR Converter Command Line" to convert these scanned image files to searchable PDF files easily,

http://www.verypdf.com/app/pdf-to-text-ocr-converter/try-and-buy.html

>>5. Is any possibility to control the conversion process from a client program?

You can use CreateProcess() or Shell() functions to call doc2any.exe from your code, you can also use TerminateProcess() function to kill doc2any.exe at anytime, you can control everything easily from your client program.

>>6. Does COM version provide all the functionality and conversion quality as command utility.

Yes, COM version and Command Line version are using same source code, so the COM version is contain all functions which included in Command Line version.

VeryDOC

-----------------------------------------------------------------
Thanks for the quick response.

Does an execution of the line below (with no optional parameters) involve Office to the processing or it is doc2any internal library support?

C:\Users\XXXX\Work\doc2any_cmd>doc2any.exe mydoc.docx mydoc.docx.pdf

Thanks
Customer
-----------------------------------------------------------------
This command line will invoke MS Office first, if your system hasn't MS Office installed, it will try to invoke OpenOffice, and then try to use doc2any internal library, it will try everything as possible as it can.

VeryDOC
-----------------------------------------------------------------
Thanks for the response.

A couple of more clarifications please.

1. We are planning to run a conversion on a Windows server 2008 environment. So is there any chance to get user interactive messages while the converter invoking Office libraries?

2. Any difference from conversion perspective (I mean conversion formats limitation) between MS Office and Open Office installed?

3. Any Office version requirements (MS Office 2007 and up?)?

Thanks
Customer
-----------------------------------------------------------------
>>1. We are planning to run a conversion on a Windows server 2008 environment. So is there any chance to get user interactive messages while the converter invoking Office libraries?

doc2any.exe does call Office libraries at background, so you will not able to see the user interactive messages during conversion.

>>2. Any difference from conversion perspective (I mean conversion formats limitation) between MS Office and Open Office installed?

If your system has MS Office and Open Office installed, the converted PDF files will look like original documents, the layout will be best.

If your system hasn't MS Office and Open Office installed, doc2any.exe will use our internal Office Render engine to convert office document formats to PDF files, our internal Office Render engine may not keep same layout in some documents, so the converted PDF files may not same as original documents.

If the page layout is important to you, you should better install MS Office or Open Office. If page layout is not important to you and text contents are important to you, you can simple use our internal Office Render engine with "-nooffice" option, our our internal Office Render engine is faster than MS Office and Open Office applications.

>>3. Any Office version requirements (MS Office 2007 and up?)?

Our doc2any.exe is support all version of MS Office, include MS Office 2003 and up.

VeryDOC

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)
Posted in DOC to Any Converter | Tagged , , | Leave a comment
Page 20 of 335« First...10...1819202122...304050...Last »