是否有一种快速简单的方法来对齐Document对象中的对象? 不执行任何计算逻辑,即.获取页面宽度,获取内容宽度,除以2等.
我在Document对象中的Paragraph对象中有一个PdfPTable对象.我想将Paragraph对象居中.
谢谢!
我正在尝试使用iTextSharp创建Landscape PDF但它仍然显示肖像.我在旋转时使用以下代码:
Document document = new Document(PageSize.A4, 0, 0, 150, 20);
FileStream msReport = new FileStream(Server.MapPath("~/PDFS/") + "Sample1.pdf", FileMode.Create);
try
{
// creation of the different writers
PdfWriter writer = PdfWriter.GetInstance(document, msReport);
document.Open();
PdfPTable PdfTable = new PdfPTable(1);
PdfTable.SpacingBefore = 30f;
PdfPCell PdfPCell = null;
Font fontCategoryheader = new Font(Font.HELVETICA, 10f, Font.BOLD, Color.BLACK);
for (int i = 0; i < 20; i++)
{
PdfPCell = new PdfPCell(new Phrase(new Chunk("Sales Manager: ", fontCategoryheader)));
PdfPCell.BorderWidth = 0;
PdfPCell.HorizontalAlignment = Element.ALIGN_LEFT;
if (i …Run Code Online (Sandbox Code Playgroud) 我有一个带有文本,图像的html页面,我正在将HTML内容解析为iText以生成PDF.在生成的PDF中,未显示包含的图像,仅显示文本.
如果我传递绝对路径,如D:/Deiva/CRs/HTMLPage/article-101-horz.jpg那么图像将被打印.但是如果我尝试从服务器上打印图像就像
http://localhost:8085/content/dam/article-101-h1.jpg or http://www.google.co.in/intl/en_ALL/images/logos/images_logo_lg.gif
那么它不会在PDF中打印出来.
注意:我使用itextpdf-5.2.1.jar生成PDF.
我的HTML代码(Article.html):
<html>
<head>
</head>
<body>
<p>Generate PDF with image using iText.</p>
<img src="http://localhost:8085/content/dam/article-10-h1.jpg"></img>
<img src="http://www.google.co.in/intl/en_ALL/images/logos/imgs_logo_lg.gif"></img>
<img class="right horz" src="D:/Deiva/CRs/HTMLPage/article-101-horz.jpg"></img>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我使用以下java代码生成PDF:
private void createPDF (){
String path = "D:/Deiva/Test.pdf";
PdfWriter pdfWriter = null;
//create a new document
Document document = new Document();
try {
//get Instance of the PDFWriter
pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(path));
//document header attributes
document.addAuthor("betterThanZero");
document.addCreationDate();
document.addProducer();
document.addCreator("MySampleCode.com");
document.addTitle("Demo for iText XMLWorker");
document.setPageSize(PageSize.LETTER);
//open …Run Code Online (Sandbox Code Playgroud) 我的项目不是开源的,我需要使用类似iTextSharp的东西,因为iTextSharp许可证说它应该只用于开源
任何替代方案请
嘿伙计我有这个字节数组我想转换为pdf并使其可供下载.任何人都知道如何做到这一点?
这是我的动作控制器
public ActionResult DownloadLabTestResult(string labTestResultID)
{
PdfReader pdfReader = new PdfReader("Xue_Tang.pdf");
MemoryStream stream = new MemoryStream();
PdfStamper stamper = new PdfStamper(pdfReader, stream);
pdfReader.Close();
stamper.Close();
stream.Flush();
stream.Close();
byte[] pdfByte = stream.ToArray();
// So i got the byte array of the original pdf at this point. Now how do i convert this
// byte array to a downloadable pdf? i tried the method below but to no avail.
MemoryStream ms = new MemoryStream(pdfByte);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=labtest.pdf");
Response.Buffer = true; …Run Code Online (Sandbox Code Playgroud) 我在vb.net上使用itextsharp从pdf文件中获取文本内容.该解决方案适用于某些文件,但不适用于其他甚至非常简单的文件.问题是令牌字符串值设置为null(一组空方框)
token = New iTextSharp.text.pdf.PRTokeniser(pageBytes)
While token.NextToken()
tknType = token.TokenType()
tknValue = token.StringValue
Run Code Online (Sandbox Code Playgroud)
我可以确保内容的长度,但我无法获得实际的字符串内容.
我意识到这取决于pdf的字体.如果我使用Acrobat或带有Courier的PdfCreator创建一个pdf(顺便说一句,这是我的visual studio编辑器中的默认字体),我可以获得所有文本内容.如果使用不同的字体构建相同的pdf,我得到空的方框.
现在的问题是,无论字体设置如何,我如何提取文本?
谢谢
PDFSharp库是否可以像iTextSharp一样生成PDF文件*考虑HTML格式*?(粗体(强),间距(br)等)
以前我使用iTextSharp并以这种方式粗略处理(下面的代码):
string encodingMetaTag = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
string htmlCode = "text <div> <b> bold </ b> or <u> underlined </ u> <div/>";
var sr = new StringReader (encodingMetaTag + htmlCode);
var pdfDoc = new Document (PageSize.A4, 10f, 10f, 10f, 0f);
var = new HTMLWorker htmlparser (pdfDoc);
PdfWriter.GetInstance (pdfDoc, HttpContext.Current.Response.OutputStream);
pdfDoc.Open ();
htmlparser.Parse (sr);
pdfDoc.Close ();
Run Code Online (Sandbox Code Playgroud)
将适当的HTML表单合并到处理类对象HTMLWorker的PDF文档中..那么用PDFSharp做什么?有PDFSharp类似的解决方案吗?
任何人都可以建议我为iTextSharp提供一本好书或API文档,我在理解lib时一直在努力,并采用了一种非常刺激和耗时的热门和尝试方法.
如何合并多个pdf文件(在运行时生成)ItextSharp然后打印它们.
我找到了以下链接,但该方法需要pdf名称考虑到存储的pdf文件,这不是我的情况.
我有多个报告我会pdf files通过这种方法将它们转换为:
private void AddReportToResponse(LocalReport followsReport)
{
string mimeType;
string encoding;
string extension;
string[] streams = new string[100];
Warning[] warnings = new Warning[100];
byte[] pdfStream = followsReport.Render("PDF", "", out mimeType, out encoding, out extension, out streams, out warnings);
//Response.Clear();
//Response.ContentType = mimeType;
//Response.AddHeader("content-disposition", "attachment; filename=Application." + extension);
//Response.BinaryWrite(pdfStream);
//Response.End();
}
Run Code Online (Sandbox Code Playgroud)
现在我想将所有生成的文件(Bytes)合并到一个pdf文件中进行打印
我有一个PDF文件,我正在使用ITextExtractionStrategy.Now从字符串中读取字符串我正在采用子字符串My name is XYZ,需要从PDF文件中获取子字符串的矩形坐标但不能这样做.在googling我知道那个LocationTextExtractionStrategy,但没有得到如何使用该工具来获取坐标.
这是代码..
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
text.Append(currentText);
string getcoordinate="My name is XYZ";
Run Code Online (Sandbox Code Playgroud)
如何使用ITEXTSHARP获取此子字符串的直角坐标..
请帮忙.
itextsharp ×10
c# ×8
pdf ×2
.net ×1
asp.net ×1
asp.net-mvc ×1
html ×1
html-to-pdf ×1
itext ×1
java ×1
pdfsharp ×1
rdlc ×1