PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Jul 17, 2024 6:45 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Nov 29, 2012 1:16 pm 
Offline

Joined: Thu Nov 29, 2012 1:08 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 29, 2012 2:27 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
foxbari wrote:
What's the difference?
Something missing in the VB code?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 03, 2012 7:29 pm 
Offline

Joined: Thu Nov 29, 2012 1:08 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Tue Dec 04, 2012 10:13 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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 .

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 05, 2012 6:41 pm 
Offline

Joined: Thu Nov 29, 2012 1:08 pm
Posts: 3
Nevermind. Got it!
Thanks to all!


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 06, 2012 8:33 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
foxbari wrote:
Got it!
Will you let us know what the problem was?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 31 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group