awilderbeast
asked on
c# itextsharp no errors everything fine, pdf just not opening?
Hi all,
this my first time using this dll, all my code seems to be ok compared to samples ive seen but the pdf isnt opening, anyone tell me why?
Thanks
this my first time using this dll, all my code seems to be ok compared to samples ive seen but the pdf isnt opening, anyone tell me why?
Thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
public partial class _CustomerSupport_CV : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CreatePDF(object sender, EventArgs e)
{
Document PDFDoc = new Document();
try
{
string filepath = System.Web.HttpContext.Current.Server.MapPath("_documents/YourCV.pdf");
PdfWriter.GetInstance(PDFDoc, new FileStream(filepath, FileMode.Create));
PDFDoc.Open();
PDFDoc.Add(new Paragraph("Hello There"));
}
catch (DocumentException de)
{
Errors.Text = de.ToString();
}
catch (IOException ioe)
{
Errors.Text = ioe.ToString();
}
PDFDoc.Close();
}
}
ASKER
ok ive seen the problem
the document is edited progrmattically, but its not shown to the user. how can i open the file in the users browser or make it download?
THanks
the document is edited progrmattically, but its not shown to the user. how can i open the file in the users browser or make it download?
THanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how can i make it open in a new window?
Thanks
Thanks
ASKER
thanks
sorry the code posted by me has some errors.
change the code after PDFDoc.Close();
as:-
change the code after PDFDoc.Close();
as:-
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + filepath);
Response.Buffer = true;
Response.Clear();
Response.WriteFile(filepath, true);
Response.End();
there is no need of MemoryStream
iTextSharp.text.Document PDFDoc = new iTextSharp.text.Document()
string filepath = @"D:\testfile.pdf";
PdfWriter.GetInstance(PDFD
PDFDoc.Open();
PDFDoc.Add(new iTextSharp.text.Paragraph(
PDFDoc.Close();