Post by altair on Mar 30, 2015 6:31:37 GMT 10
Hi Folks,
I am creating an app that generates a report but It is frustrating as I always get my report in about 3 pages instead of 1 when I convert it to PDF.
Altair - The Flying One
|
|
Post by Nathan Lecompte on Mar 30, 2015 13:38:39 GMT 10
Could you show some code? It makes it easier to answer
|
|
Post by altair on Mar 30, 2015 21:09:24 GMT 10
Ok this is the code for the form that displays the report,
Imports Microsoft.Reporting Imports Microsoft.Reporting.WinForms Imports System.IO Imports System.Net Imports System.Net.Mail
Public Class Reporter
Public PDB As String Public CDB As String Public Sales As String Public Expenses As String Public ADIB As String Public CurDate As String Public Data1 As String Public Data2 As String Public Data3 As String Public Data4 As String Public Data5 As String Public Data6 As String Public Data7 As String Public Data8 As String Public Data9 As String Public Data10 As String
Private Sub Reporter_Load(sender As Object, e As EventArgs) Handles MyBase.Load SetParams() End Sub
Private Sub SetParams() Dim params(15) As Microsoft.Reporting.WinForms.ReportParameter params(0) = New Microsoft.Reporting.WinForms.ReportParameter("PDB", PDB) params(1) = New Microsoft.Reporting.WinForms.ReportParameter("CDB", CDB) params(2) = New Microsoft.Reporting.WinForms.ReportParameter("Sales", Sales) params(3) = New Microsoft.Reporting.WinForms.ReportParameter("Expenses", Expenses) params(4) = New Microsoft.Reporting.WinForms.ReportParameter("ADIB", ADIB) params(5) = New Microsoft.Reporting.WinForms.ReportParameter("Date", CurDate) params(6) = New Microsoft.Reporting.WinForms.ReportParameter("Data1", Data1) params(7) = New Microsoft.Reporting.WinForms.ReportParameter("Data2", Data2) params(8) = New Microsoft.Reporting.WinForms.ReportParameter("Data3", Data3) params(9) = New Microsoft.Reporting.WinForms.ReportParameter("Data4", Data4) params(10) = New Microsoft.Reporting.WinForms.ReportParameter("Data5", Data5) params(11) = New Microsoft.Reporting.WinForms.ReportParameter("Data6", Data6) params(12) = New Microsoft.Reporting.WinForms.ReportParameter("Data7", Data7) params(13) = New Microsoft.Reporting.WinForms.ReportParameter("Data8", Data8) params(14) = New Microsoft.Reporting.WinForms.ReportParameter("Data9", Data9) params(15) = New Microsoft.Reporting.WinForms.ReportParameter("Data10", Data10) ReportViewer1.LocalReport.SetParameters(params) Me.ReportViewer1.RefreshReport() End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click Application.Restart() End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click My.Settings.PDBSave = CDB SaveToDisk() SendEmail() Application.Exit() End Sub
Public Sub SaveToDisk() Dim Bytes() As Byte = ReportViewer1.LocalReport.Render("PDF", "", Nothing, Nothing, Nothing, Nothing, Nothing) Dim CurrentDate As System.DateTime = System.DateTime.Now Dim CurDateForFile As String CurDateForFile = CurrentDate.Day & "-" & CurrentDate.Month & "-" & CurrentDate.Year & ".pdf" Dim SavePath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop).ToString & "\Reports\" & CurDateForFile If Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Desktop).ToString & "\Reports\") Then Using Stream As New FileStream(SavePath, FileMode.Create) Stream.Write(Bytes, 0, Bytes.Length) End Using Else Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Desktop).ToString & "\Reports\") SaveToDisk() End If End Sub
Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click ReportViewer1.PrintDialog() End Sub
Public Sub SendEmail() Try Dim ToAddress As String = "toaddress@example.com" Dim FromAddress As String = "fromaddress@example.com"
Dim SmtpMail As New SmtpClient("smtp.example.com", 587) SmtpMail.EnableSsl = True SmtpMail.Credentials = New NetworkCredential(FromAddress, "frompassword")
Dim CurrentDate As System.DateTime = System.DateTime.Now Dim CurDate As String CurDate = CurrentDate.Day & "-" & CurrentDate.Month & "-" & CurrentDate.Year Dim CurDateForFile As String CurDateForFile = CurrentDate.Day & "-" & CurrentDate.Month & "-" & CurrentDate.Year & ".pdf" Dim FilePath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop).ToString & "\Reports\" & CurDateForFile
Dim oMsg As MailMessage = New MailMessage()
oMsg.From = New MailAddress(FromAddress) oMsg.To.Add(ToAddress) oMsg.Subject = "Daily Report of " & CurDate.ToString oMsg.Body = "Sent by Daily Reporter by Mangoskin Apps (http://mangoskin.weebly.com)" Dim oAttch As Mail.Attachment = New Mail.Attachment(FilePath) oMsg.Attachments.Add(oAttch) SmtpMail.Send(oMsg) Catch ex As Exception MsgBox("Unable to send the email... Please check your internet connection." & vbNewLine & "The Local Copy is saved", MsgBoxStyle.Critical, "Error - Daily Reporter") Application.Restart() End Try End Sub
End Class
Note: This is the same thing I need to solve for FTP but currently as a replacement uses email.
Altair - The Flying One
|
|
Post by Nathan Lecompte on Mar 30, 2015 22:03:21 GMT 10
Well, it's quite obvious that it'd be converted to 3 pages instead of 1 otherwise all the information wouldn't fit (since PDF documents set their margin's according to the International Paper Size or A4)...however you could try and maybe shrink it to make it fit on one page if you really have to, although it might make it a bit harder to read since the quality might get degraded.
|
|
Post by altair on Mar 31, 2015 1:14:17 GMT 10
It's okay about the degrading because this report is fairly simple and only contains some textboxes. And I shrinked the size to no avail. Now instead of having 3 pages I have 5 ( No... Printer Apoclypse ) Altair - The Flying One
|
|
Post by Nathan Lecompte on Mar 31, 2015 12:55:14 GMT 10
You could try converting them to an image and then shrink it, or maybe convert it to multiple images, stitch them together and then shrink the final image.
|
|
Post by altair on Mar 31, 2015 23:39:11 GMT 10
How to do that, I don't know anything about Image Manipulation
Altair - The Flying One
|
|
Post by Nathan Lecompte on Apr 1, 2015 15:30:11 GMT 10
Well to start off, what's the filetype it originally exports as?
(I'm guessing PDF by the looks of it)
|
|
Post by altair on Apr 1, 2015 19:27:45 GMT 10
Yes it's PDF.
Altair - The Flying One
|
|
Post by Nathan Lecompte on Apr 2, 2015 8:40:25 GMT 10
|
|