We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Another problem upgrading application from Aspose 5.3.0.0 to newer version

My code uses following to convert HTML to PDF.

-----------------------------------------------------------------------------------------------------

'Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf

'Dim section As Aspose.Pdf.Section = pdf.Sections.Add()

Dim pdf As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf

Dim section As Aspose.Pdf.Generator.Section = pdf.Sections.Add()

section.IsLandscape = False

Dim r As StreamReader = File.OpenText(Server.MapPath(".") & "\Test.html")

section.PageInfo.PageWidth = 560

section.PageInfo.PageHeight = 1060

section.PageInfo.Margin.Top = 10

section.PageInfo.Margin.Bottom = 10

section.PageInfo.Margin.Right = 10

section.PageInfo.Margin.Left = 10

'Dim text1 As Aspose.Pdf.Text = New Aspose.Pdf.Text(section, r.ReadToEnd())

Dim text1 As Aspose.Pdf.Generator.Text = New Aspose.Pdf.Generator.Text(section, r.ReadToEnd())

r.Close()

text1.IsHtmlTagSupported = True

pdf.HtmlInfo.ImgUrl = Server.MapPath(".") & "\html\"

section.Paragraphs.Add(text1)

'pdf.Save("Test.pdf", Aspose.Pdf.SaveType.OpenInAcrobat, Response)

pdf.Save(Server.MapPath(".") & "\Report_.pdf")

---------------------------------------------------------------------------------------

Note that my licence only activates up to 7.0.0.0 so I am converting application to Aspose.Pdf 7.0.0.0.

Basically I had to convert The Aspose.Pdf.Pdf class notation to Aspose.Pdf.Generator.Pdf notation. (See commented out code above.) But now the HTML table structure conversion that worked perfectly in 5.3.0.0 now works pretty bad. Most of the table attributes for formatting and background color and whatever else are not supported. It's like the functionality took a backward step when you went from the 5.3.0.0 to 7.0.0.0 . I understand there were some major class structure changes when coming out with new versions but what are my options for getting this to work? I have to upgrade to 7.0.0.0 for the Aspose.Pdf.Facades PDF form support. Can I have two different versions of Aspose.PDf on the web server at same time?

Thanks.

M.J.N.

I traced the problem to not reading the css style sheet properly. Version 7.0.0.0 seems really flaky in terms of supporting styling. I upgraded temporarily to version 8.3.1.0 and style sheet support is signifactly better but still too flaky to be useful.

I just find it odd that everything works perfectly in 5.3.0.0 but seems like everything was reimplemented in the newer version but the css support is not as good as the older version?

Hi there,


Thanks for your inquiry. Can you please share your source document here? So we will test the scenario at our end and will provide you more information.

Sorry for the inconvenience faced.

Best Regards,

Below is test procedure for converting HTML page to PDF. HTML page is written to file and then the file is converted to PDF. The old version of Aspose.pdf created a PDF that looked visually exactly like the HTML file that is generated when viewed in a web browser. But a PDF file generated in the newer version 8.3.1.0 does not look exactly like the web page.

Note that I hardcoded the style sheet into the HTML page using the style tag but linking to a style sheet works exactly the same.

-------------------------------------------------------------------------------------------------

Private Sub TestFile()

Dim display As String

'+ "" & vbCrLf _
display = "" & vbCrLf _
+ "" & vbCrLf _
+ "" & vbCrLf _
+ "" & vbCrLf _
+ "BODY {FONT-SIZE: 13px; COLOR: #383838; LINE-HEIGHT: 21px; FONT-FAMILY: Verdana, Helvetica, Arial, Sans-Serif}" & vbCrLf _
+ "STRONG {FONT-WEIGHT: bold}" & vbCrLf _
+ "EM {FONT-STYLE: italic}" & vbCrLf _
+ "U {TEXT-DECORATION: underline}" & vbCrLf _
+ "P {MARGIN-BOTTOM: 10px}" & vbCrLf _
+ "A {FONT-WEIGHT: bold; COLOR: #304742; TEXT-DECORATION: none}" & vbCrLf _
+ "#right_column A {TEXT-DECORATION: underline}" & vbCrLf _
+ "#right_column A:hover {TEXT-DECORATION: none}" & vbCrLf _
+ "H1 {FONT-WEIGHT: bold; MARGIN-BOTTOM: 10px; COLOR: #304742; TEXT-ALIGN: center}" & vbCrLf _
+ "H2 {FONT-WEIGHT: bold; MARGIN-BOTTOM: 10px; COLOR: #304742; TEXT-ALIGN: center}" & vbCrLf _
+ "H3 {FONT-WEIGHT: bold; MARGIN-BOTTOM: 10px; COLOR: #304742; TEXT-ALIGN: center}" & vbCrLf _
+ "H4 {FONT-WEIGHT: bold; MARGIN-BOTTOM: 10px; COLOR: #304742; TEXT-ALIGN: center}" & vbCrLf _
+ "H1 {FONT-SIZE: 22px}" & vbCrLf _
+ "H2 {FONT-SIZE: 14px}" & vbCrLf _
+ "H3 {FONT-SIZE: 14px; COLOR: #547872}" & vbCrLf _
+ "H4 {FONT-SIZE: 12px}" & vbCrLf _
+ "#right_column H2 {CLEAR: both; BORDER-TOP: #304742 3px solid; PADDING-LEFT: 10px; BACKGROUND: #cfd3bc no-repeat; LINE-HEIGHT: 32px; BORDER-BOTTOM: #7f7f7f 1px solid}" & vbCrLf _
+ "#right_column P.right {MARGIN-LEFT: 15px; TEXT-ALIGN: right}" & vbCrLf _
+ "#right_column IMG.right {MARGIN-LEFT: 15px; TEXT-ALIGN: right}" & vbCrLf _
+ "#right_column P.left {MARGIN-RIGHT: 15px; TEXT-ALIGN: left}" & vbCrLf _
+ "#right_column IMG.left {MARGIN-RIGHT: 15px; TEXT-ALIGN: left}" & vbCrLf _
+ "#right_column P.center {DISPLAY: block; MARGIN: 0px auto; TEXT-ALIGN: center}" & vbCrLf _
+ "#right_column IMG.center {DISPLAY: block; MARGIN: 0px auto; TEXT-ALIGN: center}" & vbCrLf _
+ "#right_column TABLE {BACKGROUND: #c8c8c8; MARGIN: 0px; BORDER-SPACING: 1px; BORDER-COLOR: #304742;BORDER-TOP: #304742 1px solid; BORDER-BOTTOM: #304742 1px solid; BORDER-LEFT: #304742 1px solid; BORDER-RIGHT: #304742 1px solid;}" & vbCrLf _
+ "#right_column TABLE CAPTION {FONT-SIZE: 10px; TEXT-ALIGN: center}" & vbCrLf _
+ "#right_column TABLE TH {FONT-WEIGHT: bold; BACKGROUND: #bbbbbb; PADDING-BOTTOM: 0px; COLOR: #383838; PADDING-TOP: 0px; TEXT-ALIGN: center;BORDER-COLOR: darkgray;}" & vbCrLf _
+ "#right_column TABLE TD {BACKGROUND: #ededed; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; LINE-HEIGHT: 12px; TEXT-ALIGN: left;BORDER-COLOR: darkgray;}" & vbCrLf _
+ "#bottom_column TABLE {BACKGROUND: #c8c8c8; MARGIN: 0px; BORDER-SPACING: 1px;}" & vbCrLf _
+ "#bottom_column TABLE CAPTION {FONT-SIZE: 10px; TEXT-ALIGN: center}" & vbCrLf _
+ "#bottom_column TABLE TH {FONT-SIZE: 10px; FONT-WEIGHT: bold; BACKGROUND: #bbbbbb; PADDING-BOTTOM: 0px; COLOR: #383838; PADDING-TOP: 0px; TEXT-ALIGN: left}" & vbCrLf _
+ "#bottom_column TABLE TD {FONT-SIZE: 10px; LINE-HEIGHT: 12px; BACKGROUND: #ededed; PADDING-BOTTOM: 0px; PADDING-TOP: 0px;}" & vbCrLf _
+ "" & vbCrLf _
+ "" & vbCrLf _
+ "" & vbCrLf _
+ "

" & vbCrLf _
+ "

Title 1

" & vbCrLf _
+ "

This is a long description that explain detail of table structure below and may wrap to the next line in some case.

" & vbCrLf _
+ "

" & vbCrLf _
+ "

Main Title

" & vbCrLf _
+ "" & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ "
Column 1Column 2Column 3Column 4Column 5Column 6Column 7Column 8
Title 1
Section 1
Item:0.001.621.620.000.000.000.000.00
" & vbCrLf _
+ "

" & vbCrLf _
+ "
" & vbCrLf _
+ "" & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ " " & vbCrLf _
+ "
Title 2
Item 10.1
Item 2100.00
" & vbCrLf _
+ "

" & vbCrLf _
+ "" & vbCrLf _
+ "" & vbCrLf

lblTest.Text = display


Dim datafile As System.IO.StreamWriter = New StreamWriter(Server.MapPath(".") & "\test.html")
Try
datafile.Write(display)
Finally
datafile.Close()
End Try


'Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf
'Dim section As Aspose.Pdf.Section = pdf.Sections.Add()
Dim pdf As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf
Dim section As Aspose.Pdf.Generator.Section = pdf.Sections.Add()

section.IsLandscape = False

Dim r As StreamReader = File.OpenText(Server.MapPath(".") & "\test.html")

section.PageInfo.PageWidth = 560
section.PageInfo.PageHeight = 1060
section.PageInfo.Margin.Top = 10
section.PageInfo.Margin.Bottom = 10
section.PageInfo.Margin.Right = 10
section.PageInfo.Margin.Left = 10


'pdf.HtmlInfo.ImgUrl = Server.MapPath(".") & "\stumpage\html\"
'pdf.HtmlInfo.ExternalResourcesBasePath = Server.MapPath(".") & "\"


'Dim text1 As Aspose.Pdf.Text = New Aspose.Pdf.Text(section, r.ReadToEnd())
Dim text1 As Aspose.Pdf.Generator.Text = New Aspose.Pdf.Generator.Text(section, r.ReadToEnd())
r.Close()

text1.IsHtmlTagSupported = True
'text1.IfHtmlTagSupportedOverwrightHtmlFontNames = True
'text1.IfHtmlTagSupportedOverwrightHtmlFontSizes = True

section.Paragraphs.Add(text1)

'pdf.Save("Test.pdf", Aspose.Pdf.SaveType.OpenInAcrobat, Response)
pdf.Save(Server.MapPath(".") & "\test.pdf")


End Sub

Hi there,

Thanks for providing additional information. I've managed to notice difference in HTML to PDF conversion results in v5.3.0 and v8.3.0 DLLs on my side and logged the issue in our bug tracking system as PDFNEWNET-35709 for further investigation and resolution. I've also linked your request to this issue and you will be notified via this thread as soon as it is resolved.


We are sorry for the inconvenience caused.

Best Regards,