public void SendToPDF(string filename, clsFont jfont) { //New document, 8.5"x11" in landscape orientation. iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.LETTER.Rotate()); //add metadata doc.AddTitle("Font preview for font " + jfont.SelectedFontName()); doc.AddSubject("font family " + jfont.SelectedFontName()); doc.AddAuthor("JLION.COM jFONT font preview utility"); doc.AddCreationDate(); //create a pdfwriter iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(filename, FileMode.Create)); //trap events PDFPageEvent pdfevent = new PDFPageEvent(); writer.PageEvent = pdfevent; //create the doc doc.Open(); doc.SetMargins(.75f * 72, .75f * 72, 0, 0); for (int currentPage = 0; currentPage < jfont.CountOfPages(); currentPage++) { //convert image to a pdf image for inclusion in the doc System.Drawing.Image jfontimage = jfont.MakeCharList(currentPage); //System.Drawing.Image jfontimage = jfont.MakeCharacterSample(); iTextSharp.text.Image convertedimage = iTextSharp.text.Image.GetInstance(jfontimage, System.Drawing.Imaging.ImageFormat.Bmp); //determine size to scale to. PDF is 72 dpi, so 1 point is 1/72. System.Drawing.Rectangle PDFImageSize = jfont.ImageSize(72); convertedimage.ScaleAbsolute(PDFImageSize.Width, PDFImageSize.Height); //Add some blank space at the top of the document doc.Add(new Paragraph("Font: " + jfont.SelectedFontName())); doc.Add(new Paragraph("Style: " + jfont.SelectedFontStyle())); doc.Add(new Paragraph("")); doc.Add(new Paragraph("")); doc.Add(convertedimage); doc.NewPage(); } doc.Close(); }
public ActionResult InventoryReportPrint(CMSReportViewModels model) { var uService = new UserService(); var prole = uService.ValidatePageRole(User.Identity.GetUserId(), Page_Code.P0016); if (prole == null) { return(RedirectToAction("ErrorPage", "Account", new ErrorViewModel() { Message = Resource.Message_Access_Denied })); } if (prole.View == null || prole.View == false) { return(RedirectToAction("ErrorPage", "Account", new ErrorViewModel() { Message = Resource.Message_Access_Denied })); } if (!string.IsNullOrEmpty(model.Lot_No) || !string.IsNullOrEmpty(model.Drum_Code) || !string.IsNullOrEmpty(model.Product_Code)) { var cmsService = new CMSService(); var cri = new CMSCriteria(); cri.Lot_No = model.Lot_No; cri.Drum_Code = model.Drum_Code; cri.Product_Code = model.Product_Code; cri.Not_Yet_Deliver = true; cri.Sort_By = model.Sort_By; cri.Drum_Code_Have_Value = true; var result = cmsService.GetCMSCharge(cri); if (result.Code == ReturnCode.SUCCESS) { model.chargelist = result.Object as List <CMS_Charge>; } cri = new CMSCriteria(); cri.Drum_Code_Have_Value = true; var result2 = cmsService.GetCMSCharge(cri); if (result2.Code == ReturnCode.SUCCESS) { model.chargelistAll = result2.Object as List <CMS_Charge>; } } var htmlToConvert = RenderPartialViewAsString("InventoryReportPrint", model); Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.Charset = Encoding.UTF8.ToString(); Response.HeaderEncoding = Encoding.UTF8; Response.ContentEncoding = Encoding.UTF8; Response.Buffer = true; StringReader sr = new StringReader(htmlToConvert); Document pdfDoc = new Document(PageSize.A4, 10, 10, 10, 40); pdfDoc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); var writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream); var action = new PdfAction(PdfAction.PRINTDIALOG); writer.SetOpenAction(action); var pageevent = new PDFPageEvent(); writer.PageEvent = pageevent; pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.End(); return(View(model)); }
public void SendToPDF(string filename, clsFont jfont) { int countOfPages = _unicodeCharList.CharCodes.Count() / LINES_PER_PAGE; //fifty lines per page. //New document, 8.5"x11" in landscape orientation. iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.LETTER); //add metadata doc.AddTitle("Unicode Character Set for font " + jfont.SelectedFontName()); doc.AddSubject("font family " + jfont.SelectedFontName()); doc.AddAuthor("JLION.COM jFONT font preview utility"); doc.AddCreationDate(); //create a pdfwriter iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(filename, FileMode.Create)); //trap events PDFPageEvent pdfevent = new PDFPageEvent(); writer.PageEvent = pdfevent; //create the doc doc.Open(); doc.SetMargins(.75f * 72, .75f * 72, 0, 0); //Create our base font string FontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF"); BaseFont baseFont = BaseFont.CreateFont(FontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); iTextSharp.text.Font x = FontFactory.GetFont(jfont.SelectedFontName()); for (int currentPage = 0; currentPage < countOfPages; currentPage++) { PdfPTable table = new PdfPTable(5); table.AddCell("Char"); table.AddCell("Dec"); table.AddCell("Hex"); table.AddCell("Desc"); table.AddCell("AltDesc"); //convert image to a pdf image for inclusion in the doc for (int curChar = currentPage * LINES_PER_PAGE; curChar < (currentPage * LINES_PER_PAGE + LINES_PER_PAGE); curChar++) { UnicodeCharList.CharEntry oneEntry = _unicodeCharList.CharCodes[curChar]; string charString = char.ConvertFromUtf32(Convert.ToInt32(oneEntry.CodeDec)).ToString(); Phrase codedChar = new Phrase(charString, x); table.AddCell(codedChar); table.AddCell(oneEntry.CodeDec); table.AddCell(oneEntry.CodeHex); table.AddCell(oneEntry.Desc); table.AddCell(oneEntry.AltDesc); } doc.Add(table); doc.NewPage(); } doc.Close(); }