Excel2pdf conversion

I’m converting my excel files to pdf.
I’ve updated to a newer Aspose.Pdf version (3.6.2.0), and as well Aspose.Cells(4.4.1.3), and now no conversion is happening.

I only got empty pdf files.

I’ve attached the files.

Thanks for your help.

Hi,

I don't find any problem using the Aspose.Cells and Aspose.Pdf components. How do you code.

Following is my sample code and attached are the output pdf files using your template files. (designerFile, xmlFile and pdfFile are string variables in which i store the related file with path)

.
.

Workbook wb = new Aspose.Cells.Workbook();
FileStream fstream = new FileStream(designerFile, FileMode.Open);
wb.Open(fstream);
wb.Save(xmlFile, FileFormatType.AsposePdf);
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML(xmlFile, null);
pdf.Save(pdfFile);
.

Thank you.

my code looks like this:

Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();
using (Stream str = new MemoryStream())
{
str.Write(byte[] a, 0, (int)a.Length);
str.Seek(0, SeekOrigin.Begin);
workbook.Open(str);
}

for (int k = 0; k < workbook.Worksheets.Count; k++)
{
workbook.Worksheets[k].PageSetup.FitToPagesWide = 1;
}

Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
using (Stream str = new MemoryStream())
{

newWorkbook.Save(str, Aspose.Cells.FileFormatType.AsposePdf);
pdf.BindXML(str, null);
pdf.IsImagesInXmlDeleteNeeded = true;
pdf.Security = new Aspose.Pdf.Security();
pdf.Security.IsContentsModifyingAllowed = this.modifyPermission;
pdf.Security.IsCopyingAllowed = this.copyPermission;
pdf.Security.IsPrintingAllowed = this.printPermission;
pdf.Security.IsAnnotationsModifyingAllowed = this.annotationsPermission;
pdf.Security.IsDocumentAssemblyingAllowed = this.assemblePermission;
pdf.Security.IsFormFillingAllowed = this.fillFormFieldsPermission;
pdf.Security.IsDegradedPrintingAllowed = this.degradedPrintPermission;
pdf.CompressionLevel = this.pdfOutQuality;
}
byte[] convertedFile = null;

using (Stream str = new MemoryStream())
{
pdf.Save(str);
str.Position = 0;
convertedFile = new byte[str.Length];
str.Read(convertedFile, 0, (int)str.Length);
}


Hi,

Which languange do you use?

If you are not using US Language and using 3.6.2, you will get an empty pdf. Pdf 3.6.2 have done some change with language setting.

We will post a fix soon. Thanks for your patience.

I’m using German Language. This might be the problem.

I hope I get a fix soon.

Thanks for your information.

Hi,

Please try the fix (4.4.1.8) downloading it from the thread: <A href="</A>. Actually we already fixed it with the release of 4.4.1.7, so you may try 4.4.1.7 or greater version / fix for your problem.</P> <P>Thank you.</P>

Thank you know it works fine.

I have the same problem, when I convert from Excel to PDF, I get a blank PDF file.

What can be the problem?

My code:

Private Sub GenerateManagementReport()Dim Workbook As Workbook = New Workbook()

Dim Sheet As Worksheet = Workbook.Worksheets(0)

Dim DataTable As DataTable = New DataTable("Prospects")

DataTable.Columns.Add("ProspectID", Type.GetType("System.Int32"))

DataTable.Columns.Add("Jaartal", Type.GetType("System.Int32"))

DataTable.Columns.Add("Achternaam", Type.GetType("System.String"))

DataTable.Columns.Add("Voorletters", Type.GetType("System.String"))

DataTable.Columns.Add("Status", Type.GetType("System.String"))

DataTable.Columns.Add("Opvolgdatum", Type.GetType("System.String"))

DataTable.Columns.Add("Eigenaar", Type.GetType("System.String"))

Dim SQL1 As String = "SELECT ProspectID, Jaartal, Achternaam, Voorletters, Opvolgdatum, EigenaarID FROM Prospecten ORDER BY Jaartal, ProspectID"

Dim CMD1 As SqlCommand = New SqlCommand(SQL1, Connection)

Dim ProspectList As New List(Of Prospect)

Try

Connection.Open()

Dim RDR1 As SqlDataReader = CMD1.ExecuteReader()

Do While (RDR1.Read())

Dim Prospect As New Prospect

Prospect.ProspectID = CInt(RDR1.Item(0))

Prospect.Jaartal = CInt(RDR1.Item(1))

Prospect.Achternaam = RDR1.Item(2).ToString()

Prospect.Voorletters = RDR1.Item(3).ToString()

Prospect.Opvolgdatum = CDate(RDR1.Item(4))

Prospect.EigenaarID = CInt(RDR1.Item(5))

ProspectList.Add(Prospect)

Loop

Finally

Connection.Close()

End Try

For Each Prospect As Prospect In ProspectList

Dim SQL2 As String = "SELECT Gebruiker FROM Gebruikers WHERE GebruikerID = @GebruikerID"

Dim CMD2 As SqlCommand = New SqlCommand(SQL2, Connection)

CMD2.Parameters.AddWithValue("GebruikerID", Prospect.EigenaarID)

Try

Connection.Open()

Prospect.Eigenaar = CMD2.ExecuteScalar().ToString()

Finally

Connection.Close()

End Try

Dim SQL3 As String = "SELECT Statussen.Status FROM Statussen, Prospectstatussen WHERE Statussen.StatusID = Prospectstatussen.StatusID AND Prospectstatussen.ProspectID = @ProspectID GROUP BY Prospectstatussen.ProspectstatusID, Statussen.Status, Prospectstatussen.Datum ORDER BY Prospectstatussen.Datum DESC"

Dim CMD3 As SqlCommand = New SqlCommand(SQL3, Connection)

CMD3.Parameters.AddWithValue("ProspectID", Prospect.ProspectID)

Try

Connection.Open()

Dim RDR3 As SqlDataReader = CMD3.ExecuteReader()

If (RDR3.Read()) Then

Prospect.Huidigestatus = RDR3.Item(0).ToString()

Else

Prospect.Huidigestatus = "-"

End If

Finally

Connection.Close()

End Try

Dim DataRow As DataRow = DataTable.NewRow()

DataRow(0) = Prospect.ProspectID

DataRow(1) = Prospect.Jaartal

DataRow(2) = Prospect.Achternaam

DataRow(3) = Prospect.Voorletters

DataRow(4) = Prospect.Huidigestatus

DataRow(5) = Prospect.Opvolgdatum.ToShortDateString

DataRow(6) = Prospect.EigenaarID

DataTable.Rows.Add(DataRow)

Next

Sheet.Cells.ImportDataTable(DataTable, True, "A2")

Sheet.AutoFitColumns()

Dim Cells As Aspose.Cells.Cells = Workbook.Worksheets(0).Cells

Dim Style As Style = Workbook.Styles(0)

Style.VerticalAlignment = TextAlignmentType.Top

Style.HorizontalAlignment = TextAlignmentType.Left

Dim Flag As New StyleFlag

Flag.All = False

Cells.ApplyColumnStyle(0, Style, Flag)

Cells.ApplyColumnStyle(1, Style, Flag)

Cells.ApplyColumnStyle(2, Style, Flag)

Cells.ApplyColumnStyle(3, Style, Flag)

Cells.ApplyColumnStyle(4, Style, Flag)

Cells.ApplyColumnStyle(5, Style, Flag)

Cells.ApplyColumnStyle(6, Style, Flag)

Workbook.Styles.Add()

Sheet.Cells("A1").PutValue("Rapportage " & Now().ToLongDateString)

Sheet.Cells("A1").Style.Font.IsBold = True

Dim ExcelPath As String = Server.MapPath("Reports/" & "Rapportage" & Now().ToShortDateString & ".xls")

Dim XmlPath As String = Server.MapPath("Reports/" & "Rapportage" & Now().ToShortDateString & ".xml")

Dim PdfPath As String = Server.MapPath("Reports/" & "Rapportage" & Now().ToShortDateString & ".pdf")

Workbook.Save(ExcelPath, FileFormatType.Default)

Workbook.Save(XmlPath, FileFormatType.AsposePdf)

Dim Pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()

Pdf.BindXML(XmlPath, Nothing)

Pdf.Save(PdfPath)

End Sub


Hi,

There is a problem in you code. I think you may try to add a line to your code (see your code below). For your info, when you call Workbook.Save() method, all the data, objects etc. related to the workbook would be null, so, you need to re-load the generated excel file and then save it as .xml (Aspose.Pdf integrated) file.

Private Sub GenerateManagementReport()Dim Workbook As Workbook = New Workbook()

Dim Sheet As Worksheet = Workbook.Worksheets(0)

Dim DataTable As DataTable = New DataTable("Prospects")

DataTable.Columns.Add("ProspectID", Type.GetType("System.Int32"))

DataTable.Columns.Add("Jaartal", Type.GetType("System.Int32"))

DataTable.Columns.Add("Achternaam", Type.GetType("System.String"))

DataTable.Columns.Add("Voorletters", Type.GetType("System.String"))

DataTable.Columns.Add("Status", Type.GetType("System.String"))

DataTable.Columns.Add("Opvolgdatum", Type.GetType("System.String"))

DataTable.Columns.Add("Eigenaar", Type.GetType("System.String"))

Dim SQL1 As String = "SELECT ProspectID, Jaartal, Achternaam, Voorletters, Opvolgdatum, EigenaarID FROM Prospecten ORDER BY Jaartal, ProspectID"

Dim CMD1 As SqlCommand = New SqlCommand(SQL1, Connection)

Dim ProspectList As New List(Of Prospect)

Try

Connection.Open()

Dim RDR1 As SqlDataReader = CMD1.ExecuteReader()

Do While (RDR1.Read())

Dim Prospect As New Prospect

Prospect.ProspectID = CInt(RDR1.Item(0))

Prospect.Jaartal = CInt(RDR1.Item(1))

Prospect.Achternaam = RDR1.Item(2).ToString()

Prospect.Voorletters = RDR1.Item(3).ToString()

Prospect.Opvolgdatum = CDate(RDR1.Item(4))

Prospect.EigenaarID = CInt(RDR1.Item(5))

ProspectList.Add(Prospect)

Loop

Finally

Connection.Close()

End Try

For Each Prospect As Prospect In ProspectList

Dim SQL2 As String = "SELECT Gebruiker FROM Gebruikers WHERE GebruikerID = @GebruikerID"

Dim CMD2 As SqlCommand = New SqlCommand(SQL2, Connection)

CMD2.Parameters.AddWithValue("GebruikerID", Prospect.EigenaarID)

Try

Connection.Open()

Prospect.Eigenaar = CMD2.ExecuteScalar().ToString()

Finally

Connection.Close()

End Try

Dim SQL3 As String = "SELECT Statussen.Status FROM Statussen, Prospectstatussen WHERE Statussen.StatusID = Prospectstatussen.StatusID AND Prospectstatussen.ProspectID = @ProspectID GROUP BY Prospectstatussen.ProspectstatusID, Statussen.Status, Prospectstatussen.Datum ORDER BY Prospectstatussen.Datum DESC"

Dim CMD3 As SqlCommand = New SqlCommand(SQL3, Connection)

CMD3.Parameters.AddWithValue("ProspectID", Prospect.ProspectID)

Try

Connection.Open()

Dim RDR3 As SqlDataReader = CMD3.ExecuteReader()

If (RDR3.Read()) Then

Prospect.Huidigestatus = RDR3.Item(0).ToString()

Else

Prospect.Huidigestatus = "-"

End If

Finally

Connection.Close()

End Try

Dim DataRow As DataRow = DataTable.NewRow()

DataRow(0) = Prospect.ProspectID

DataRow(1) = Prospect.Jaartal

DataRow(2) = Prospect.Achternaam

DataRow(3) = Prospect.Voorletters

DataRow(4) = Prospect.Huidigestatus

DataRow(5) = Prospect.Opvolgdatum.ToShortDateString

DataRow(6) = Prospect.EigenaarID

DataTable.Rows.Add(DataRow)

Next

Sheet.Cells.ImportDataTable(DataTable, True, "A2")

Sheet.AutoFitColumns()

Dim Cells As Aspose.Cells.Cells = Workbook.Worksheets(0).Cells

Dim Style As Style = Workbook.Styles(0)

Style.VerticalAlignment = TextAlignmentType.Top

Style.HorizontalAlignment = TextAlignmentType.Left

Dim Flag As New StyleFlag

Flag.All = False

Cells.ApplyColumnStyle(0, Style, Flag)

Cells.ApplyColumnStyle(1, Style, Flag)

Cells.ApplyColumnStyle(2, Style, Flag)

Cells.ApplyColumnStyle(3, Style, Flag)

Cells.ApplyColumnStyle(4, Style, Flag)

Cells.ApplyColumnStyle(5, Style, Flag)

Cells.ApplyColumnStyle(6, Style, Flag)

Workbook.Styles.Add()

Sheet.Cells("A1").PutValue("Rapportage " & Now().ToLongDateString)

Sheet.Cells("A1").Style.Font.IsBold = True

Dim ExcelPath As String = Server.MapPath("Reports/" & "Rapportage" & Now().ToShortDateString & ".xls")

Dim XmlPath As String = Server.MapPath("Reports/" & "Rapportage" & Now().ToShortDateString & ".xml")

Dim PdfPath As String = Server.MapPath("Reports/" & "Rapportage" & Now().ToShortDateString & ".pdf")

Workbook.Save(ExcelPath, FileFormatType.Default)

workbook.Open(ExcelPath, FileFormatType.Default)

Workbook.Save(XmlPath, FileFormatType.AsposePdf)

Dim Pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()

Pdf.BindXML(XmlPath, Nothing)

Pdf.Save(PdfPath)

End Sub

Thank you.