PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

PDFSharp with VB.NET doesn't display doc
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2250
Page 1 of 1

Author:  foxbari [ Thu Nov 29, 2012 1:16 pm ]
Post subject:  PDFSharp with VB.NET doesn't display doc

I have 2 versions of the same app. 1 in C#, the other in VB.NET.
The C# version works as expected. The VB.NET version does not.

They both create the PDF but the VB.NET version will not display teh created PDF.
What's the difference?\

Thanks

foxbari

Author:  Thomas Hoevel [ Thu Nov 29, 2012 2:27 pm ]
Post subject:  Re: PDFSharp with VB.NET doesn't display doc

foxbari wrote:
What's the difference?
Something missing in the VB code?

Author:  foxbari [ Mon Dec 03, 2012 7:29 pm ]
Post subject:  Re: PDFSharp with VB.NET doesn't display doc

I used a code converter to create my Vb project. Nothing was eliminated. After the conversion, the code ran fine except for the pdfsharp display.
You'll see that I am using the ClientScript.RegisterClientScriptBlock method to display the pdf in a new window.

Here's my code:

Protected Sub btnAll_Click(ByVal sender As Object, ByVal e As EventArgs)
_view = False
Me.lblMessage1.Visible = False
Me.ReportDetail()
Me.ReportSummary()
Me.ReportMain()
Dim loss_files() As String = Directory.GetFiles(ConfigurationManager.AppSettings("ReportFolder"), "*_LossAnalysis.pdf")
Dim x As Integer = 0
Do While (x < loss_files.Length)
File.Delete(loss_files(x))
x = (x + 1)
Loop
' Get list of files and Open the output document
Dim files() As String = Directory.GetFiles(ConfigurationManager.AppSettings("ReportFolder"), "*.pdf")
Dim outputDocument As PdfSharp.Pdf.PdfDocument = New PdfSharp.Pdf.PdfDocument
' Iterate files
Try
For Each file As String In files
' Open the document to import pages from it.
Dim inputDocument As PdfSharp.Pdf.PdfDocument = PdfSharp.Pdf.IO.PdfReader.Open(file, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import)
' Iterate pages
Dim count As Integer = inputDocument.PageCount
Dim idx As Integer = 0
Do While (idx < count)
' Get the page from the external document...
Dim page As PdfSharp.Pdf.PdfPage = inputDocument.Pages(idx)
' ...and add it to the output document.
outputDocument.AddPage(page)
idx = (idx + 1)
Loop
Next
Dim filename As String = (ConfigurationManager.AppSettings("ReportFolder") _
& (Me.txt1.Text & "_LossAnalysis.pdf"))
outputDocument.Save(filename)
Dim sb As StringBuilder = New StringBuilder
Dim replaced As String = ConfigurationManager.AppSettings("ReportFolder").ToString.Replace("\\", "\\\\")
sb.Append(("<script language='javascript'>window.open('" _
& (replaced _
& (Me.txt1.Text & ("_LossAnalysis.pdf" + "','thiswindow','resizable=1,scrollbars=1,width=650,height=500')</script>")))))
' if the script is not already registered
If Not Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType, "PrintPDF") Then
ClientScript.RegisterClientScriptBlock(Page.GetType, "PrintPDF", sb.ToString)
End If
Catch ex As Exception
log.Error(("Error concatenating pdfs: " + ex.Message))
End Try
End Sub

Author:  Thomas Hoevel [ Tue Dec 04, 2012 10:13 am ]
Post subject:  Re: PDFSharp with VB.NET doesn't display doc

Here's how I see the problem:
  • It has nothing to do with PDFsharp
  • You have C# code that works
  • You have automatically converted VB code that does not work

I think I'd take the working HTML file from C# and the not working HTML file from VB and compare them.
Maybe RegisterClientScriptBlock does not work, maybe there is just a minor error with special characters .

Author:  foxbari [ Wed Dec 05, 2012 6:41 pm ]
Post subject:  Re: PDFSharp with VB.NET doesn't display doc

Nevermind. Got it!
Thanks to all!

Author:  Thomas Hoevel [ Thu Dec 06, 2012 8:33 am ]
Post subject:  Re: PDFSharp with VB.NET doesn't display doc

foxbari wrote:
Got it!
Will you let us know what the problem was?

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/