Solved

Damaged pdf when converting Excel workbook using PDFCreator

Posted on 2008-06-19
7
681 Views
Last Modified: 2012-05-05
I am trying to create *.pdf files from an Excel workbook using the following C# statement:

wb.PrintOut(1, wb.Sheets.Count, 1, false, "PDFCreator", true, false, FileName);

where wb is a Workbook using Microsoft.Office.Interop.Excel.

This results in a "damaged" pdf file - see attached file for error message.
What would be the solution?
Question.JPG
0
Comment
Question by:MTecho
  • 4
  • 3
7 Comments
 
LVL 45

Expert Comment

by:patrickab
ID: 21829413
MTecho,

If you use PDFCreator as a stand-alone application, does it create a valid working pdf file? Once you've established that then you can move on to other possibilities.

Patrick
0
 

Author Comment

by:MTecho
ID: 21837090
Thanks, Patrick.

Yes, it does.
0
 
LVL 45

Expert Comment

by:patrickab
ID: 21837112
MTecho,

In this statement:

wb.PrintOut(1, wb.Sheets.Count, 1, false, "PDFCreator", true, false, FileName);

how are you declaring and defining each element? Please give your actual code for

===
wb
Filename
===

Thanks

Patrick
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:MTecho
ID: 21837157
           string ReportID = "A1b";
            Microsoft.Office.Interop.Excel.Application xlApp = null;
...
                        xlApp = new Microsoft.Office.Interop.Excel.Application();
                        Workbook wb = xlApp.Workbooks.Open(Reports.Properties.Settings.Default.XLT_LOCATIONA1b, 3, false, 5, "", "", true, XlPlatform.xlWindows, null, null, false, null, false, false, XlCorruptLoad.xlNormalLoad);
                        Worksheet objsheet1 = (Worksheet)xlApp.Worksheets["All Arrivals"];
                        PivotTable Pv = (PivotTable)objsheet1.PivotTables("PivotTable1");
                        if (Pv.RefreshTable())
                        {
...
                                    wb.PrintOut(1, wb.Sheets.Count, 1, false, "PDFCreator", true, false, Reports.Properties.Settings.Default.WEB_FOLDER + (char)92 + ReportID + ".pdf");
...
                        }
==============================================
Reports.Properties.Settings.Default.XLT_LOCATIONA1b is a string setting, set by OpenFileDialog to the path for an Excel template file (*.xlt). The template file is loaded and the pivot table is refreshed
Reports.Properties.Settings.Default.WEB_FOLDER  is a string setting, set by OpenFolderDialog

Thanks

Mark
0
 
LVL 45

Accepted Solution

by:
patrickab earned 50 total points
ID: 21837454
Mark,

I do not pretend know anything about MS Interop, however it does look to be a very complicated way to do something that is really very simple. I'm not in the habit of producing pdf files from Excel so I had a look on the net and found Sonic PDF Creator 2.0. I installed it and then recorded an Excel macro to create a pdf file. All of that took a matter of minutes. The result was this short macro:

Sub print2pdf()
    Application.ActivePrinter = "Sonic PDF on Ne02:"
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
        "Sonic PDF on Ne02:", Collate:=True
End Sub

I obtained Sonic PDF Creator 2.0 from:

http://www.investintech.com/downloads/sonic/download.htm

I realise you are using C#, but perhaps it might be much easier to do what you want to do from within Excel and using VBA instead.

Patrick
0
 

Author Closing Comment

by:MTecho
ID: 31469055
Thanks for your help Patrick.
The solution I would really like would enable my application to process multiple Excel files and not require any macro in the spreadsheets.
I have found some VB code that does this, but generates an error when processing the second file - have not solved it yet.
0
 
LVL 45

Expert Comment

by:patrickab
ID: 21923541
MTecho - Thanks for the points. - Patrick
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now