我通过itextsharp获得pdf生成。在此pdf中,无法选择所有文本,并且在显示时,我们不需要其他字体。如何生成此类型的pdf文件? THKS!
此文件链接:demo file
答案 0 :(得分:0)
我尝试使用代码,但在pdf中,仍然可以选择“示例文本”。我是如何改进我的代码的。
string fileName = DateTime.Now.ToString();
MemoryStream outputStream = new MemoryStream();//
Document doc = new Document((PageSize.A5.Rotate()));//
PdfDestination pdfDest = new PdfDestination(PdfDestination.FIT);
PdfWriter writer = PdfWriter.GetInstance(doc, outputStream);
doc.Open();
PdfContentByte cb = writer.DirectContent;
cb.BeginText();
cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 10f);
cb.SetTextMatrix(1.2f, 9.5f);
cb.ShowText("Sample text");
cb.EndText();
doc.Close();
outputStream.Close();
Response.ContentType = "application/pdf";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.OutputStream.Write(outputStream.GetBuffer(), 0, outputStream.GetBuffer().Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();