Excel2PDF Print Orientation

Good job on the Excel to PDF programming! This is really a needed product and I’m very impressed with the work just released. Unfortunately during testing I ran into a problem that you may be able to help us out with.

I am executing code (listed below) that takes a preexisting XLS file and converts them using the ASPOSE Excel and PDF components to convert the XLS to a PDF file. The problem that I encountered is that the original print area in the spreadsheet is set at Landscape and when converting it to PDF it does not recognized it’s orientation and does not output the document as Landscape. At this juncture, I’ll even pass a Boolean to the function to make sure the output is printed and PDF’d correctly. Is there a way to make sure the printing orientation is correct based on input. If not, how can we make sure that PDF saves it as Landscape.

Thanks for you help,

David





Public Function RPMExcelXslToPDF(ByVal inUNC As String, ByVal outUNC As String, ByVal strUserLogon As String, ByVal PrintLandscape As Boolean) As String
        Dim RtnVal As String = String.Empty
        Dim InPath As String = inUNC.Trim
Dim OutPath As String = outUNC.Trim
        If Not File.Exists(InPath) Then
RtnVal = "ERROR|" & "File does not exist: " & InPath
Return RtnVal
Exit Function
End If
        If strUserLogon.Trim.Length = 0 Then
RtnVal = "ERROR|" & "User Logon ID was not provided." & InPath
Return RtnVal
Exit Function
End If
        'Determine if ASPOSE License is avalible for use; otherwise watermarked output will be created (for testing servers)
Dim ExcelLicense As String = GetWebConfigAppValue("ASPOSEExcelLicenseFile")
If ExcelLicense.Length > 0 Then
If Not File.Exists(ExcelLicense) Then
RtnVal = "ERROR|" & "ASPOSE Excel License File in Web.Config can not be found. Contact RPM Systems support."
Return RtnVal
Exit Function
End If
End If
        Dim PDFLicense As String = GetWebConfigAppValue("ASPOSEPDFLicenseFile")
If PDFLicense.Length > 0 Then
If Not File.Exists(PDFLicense) Then
RtnVal = "ERROR|" & "ASPOSE PDF License File in Web.Config can not be found. Contact RPM Systems support."
Return RtnVal
Exit Function
End If
End If
        'Delete Temp Work file
Dim fi As FileInfo = New FileInfo(InPath)
        Dim DirName As String = fi.DirectoryName
Dim FileName As String = fi.Name.Substring(0, fi.Name.IndexOf(".")) & "_TMP.XML"
Dim wrkFile As String = DirName & "\" & FileName
        If File.Exists(FileName) Then File.Delete(FileName)
If File.Exists(wrkFile) Then File.Delete(wrkFile)
        Try
If ExcelLicense.Length > 0 Then
EXCEL.Excel.SetLicense(ExcelLicense)
End If
            Dim objDocument As EXCEL.Excel = New EXCEL.Excel
objDocument.Open(InPath)

objDocument.Save(wrkFile, EXCEL.FileFormatType.AsposePdf)
            Dim objPDF As PDF.Pdf = New PDF.Pdf
            If PDFLicense.Length > 0 Then
PDF.Pdf.SetLicense(PDFLicense)
End If

objPDF.BindXML(wrkFile, Nothing)
            'Add Timestamp Note.
Dim CRLF As String = System.Environment.NewLine
            'Attach Timestamp to file
Dim strTimestamp As String = CRLF & "Approved and submitted for conversion by" & CRLF & strUserLogon & " on " & Now.ToShortDateString & " " & Now.ToLongTimeString & ". " & CRLF & " "
            Dim sec1 As PDF.Section = objPDF.Sections.Add()
            If PrintLandscape = True Then sec1.IsLandscape = True
            Dim table1 As PDF.Table = New PDF.Table
sec1.Paragraphs.Add(table1)
table1.ColumnWidths = "1.5inch 1.5inch" 'Dims per cell
            Dim row1 As PDF.Row = table1.Rows.Add()
            Dim cell1Row1 As PDF.Cell = row1.Cells.Add(strTimestamp)
cell1Row1.ColumnsSpan = 2
cell1Row1.Border = New PDF.BorderInfo(CType(PDF.BorderSide.All, Integer), 2.5, New PDF.Color("BLUE"))
            If File.Exists(OutPath) Then
File.Delete(OutPath)
End If
            objPDF.Save(OutPath)
            If Not File.Exists(OutPath) Then
RtnVal = "ERROR|" & "Output File does not exist. File not created : " & InPath
Else
RtnVal = "SUCCESS|" & OutPath
End If
        Catch ex As Exception
Dim x As String = ex.Message
RtnVal = "ERROR|" & ex.Message
End Try
        Try
If File.Exists(wrkFile) Then File.Delete(wrkFile)
Catch ex As Exception
Dim x As String = ex.Message
End Try
        Return RtnVal
    End Function





David,

Thank you for the report.

Actually we didn't care about the page setup the previous release. We will support it in the future release.

If you don't set print area in a sheet, all data will be converted. However, if print area is set, only data in the print area will be converted. How do you think about this routine?

Hi David,

Now this feature is available. Please download the hotfix v2.7.2 at

In a related topic, I’m creating a report in Excel and then converting it to a PDF. All of the formatting comes through except for my horizontally merged cells. PDF’s have a property called ColumnsSpan that is equivalent to merged cells in Excel. Is there anything that I can do to get Aspose to recognize the merged cells and translate them?

Could you please upload your report here? We will check this issue ASAP.

Here is my merge code:

Public Function MergeCells(ByVal xWorkSheet As Aspose.Excel.Worksheet, ByVal RowValue As Integer)

Dim y As Integer

For y = 0 To 2 * yFields.Length - 1 Step 2

xWorkSheet.Cells(RowValue + y, 0).Style.VerticalAlignment = TextAlignmentType.Center

xWorkSheet.Cells.Merge(RowValue + y, 0, 2, 1)

Next

End Function

Here is my export code:

'============== PDF Save =====================

Dim pdf1 As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf

pdf1.BindXML(“regional.xml”, Nothing)

pdf1.Save(“C:\Cnetpub\wwwroot\BSA_Metrics\mybsa_emea_reporting\Output\individual.pdf”)

pdf1.Save(“c:\Cnetpub\wwwroot\BSA_Metrics\mybsa_emea_reporting\Output\regional.pdf”)


Vertical merged cell is not supported yet. We will work with Aspose.Pdf team to make it ASAP.

This question wasn’t about vertical text, I’m having an issue with merged cells in Excel not being translated properly into PDF’s.

the code is above.

thx,

dave

Hi Dave,

We understand your need.

If you don’t merge cell in two rows but in two columns, you can see the merged cells are converted correctly. Right?
Your cells are vertically merged. This is not supported yet.

We will work with Aspose.Pdf team to solve it ASAP.

Hi Laurence,

Horizontally merging isn’t being translated properly either. Can I email you some screen shots?

thanks,
David

Hi David,

Vertical merged cells conversion is not supported in Aspose.Pdf. Aspose.Pdf team is working to support it.

Actually if you merge cell in one row, it’s supported for conversion. But there is a bug to deal with the text alignment. We already fixed it and the new hotfix will be available at the start of next week.

@David,
Aspose.Excel is deprecated now and is no more under active development. It is replaced by Aspose.Cells that has much advanced features as sompared to its predecessor and also supports the latest features available in different versions of MS Excel. You can convert Excel to PDF having merged cells with vertically aligned text. Here is an example that demonstrates this feature.

Workbook workbook = new Workbook("Book1.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();

PageSetup pageSetup = worksheet.PageSetup;
pageSetup.Orientation = PageOrientationType.Landscape;
workbook.Save("output.pdf", pdfSaveOptions);

Here is the program input Excel file and output PDF where text is rendered that is vertically aligned in a merged cells area and output PDF is in Landscape format.

Here you will find the detailed information about rendering Excel file:
Rendering

Download the free trial version here for testing above sample code:
Aspose.Cells for .NET (Latest Version)

Download a runnable solution that can be compiled and executed to test variety of features of this new product without writing any code.