Click here to Skip to main content
15,912,493 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Warning[] warnings;              
string[] streamids;
string mimeType;
string encoding;
string extension;

byte[] bytes = View.ReportViewer.LocalReport.Render("PDF", null, out mimeType, 
               out encoding, out extension, out streamids, out warnings);
            
FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("output.pdf"), 
FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();

//Open existing PDF
Document document = new Document(PageSize.LETTER);
PdfReader reader = new PdfReader(HttpContext.Current.Server.MapPath("output.pdf"));
//Getting a instance of new PDF writer
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(
   HttpContext.Current.Server.MapPath("Print.pdf"), FileMode.Create));
document.Open();
PdfContentByte cb = writer.DirectContent;

int i = 0;
int p = 0;
int n = reader.NumberOfPages;
Rectangle psize = reader.GetPageSize(1);
 
float width = psize.Width;             
float height = psize.Height;

//Add Page to new document
while (i < n)
{
   document.NewPage();
   p++;
   i++;

   PdfImportedPage page1 = writer.GetImportedPage(reader, i);
   cb.AddTemplate(page1, 0, 0);
}

//Attach javascript to the document
PdfAction jAction = PdfAction.JavaScript("this.print(true);\r", writer);
writer.AddJavaScript(jAction);
document.Close();
                
//Attach pdf to the iframe
frmPrint.Attributes["src"] = "Print.pdf";
Posted
Updated 29-May-14 21:34pm
v2

If you need to convert code, there are on-line code converters which will do most (if not all) of the job. This is the one I use:
http://www.developerfusion.com/tools/convert/csharp-to-vb/[^]
And it's converse:
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]
 
Share this answer
 
VB
Dim warnings As Warning()
Dim streamids As String()
Dim mimeType As String
Dim encoding As String
Dim extension As String

Dim bytes As Byte() = View.ReportViewer.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, _
	warnings)

Dim fs As New FileStream(HttpContext.Current.Server.MapPath("output.pdf"), FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()

'Open existing PDF
Dim document As New Document(PageSize.LETTER)
Dim reader As New PdfReader(HttpContext.Current.Server.MapPath("output.pdf"))
'Getting a instance of new PDF writer
Dim writer As PdfWriter = PdfWriter.GetInstance(document, New FileStream(HttpContext.Current.Server.MapPath("Print.pdf"), FileMode.Create))
document.Open()
Dim cb As PdfContentByte = writer.DirectContent

Dim i As Integer = 0
Dim p As Integer = 0
Dim n As Integer = reader.NumberOfPages
Dim psize As Rectangle = reader.GetPageSize(1)

Dim width As Single = psize.Width
Dim height As Single = psize.Height

'Add Page to new document
While i < n
	document.NewPage()
	p += 1
	i += 1

	Dim page1 As PdfImportedPage = writer.GetImportedPage(reader, i)
	cb.AddTemplate(page1, 0, 0)
End While

'Attach javascript to the document
Dim jAction As PdfAction = PdfAction.JavaScript("this.print(true);" & vbCr, writer)
writer.AddJavaScript(jAction)
document.Close()

'Attach pdf to the iframe
frmPrint.Attributes("src") = "Print.pdf"


use
SnippetConverter[^]


Convert VB to C# or C# to VB
[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900