在itext中我有一个块/短语/段落(我不介意哪个),我想在页面上的其他位置定位,例如300 x 200.我该怎么做?
知道如何使用iTextSharp渲染PDF,以便使用CSS渲染页面.css既可以嵌入HTML中,也可以单独传递,我并不在乎,只是希望它能够工作.
我们将非常感谢具体的代码示例.
另外,我真的很想坚持使用iTextSharp,但如果你有其他的建议,它必须是免费的,开源的,并且有许可证允许在商业软件中使用它.
我一直在使用此代码取得巨大成功,以提取PDF的每个页面中找到的第一个图像.但是,由于未知原因,它现在无法使用某些新PDF.我已经使用了其他工具(Datalogics等),这些工具可以很好地利用这些新的PDF来提取图像.但是,如果我可以使用iTextSharp,我不想购买Datalogics或任何工具.任何人都可以告诉我为什么这段代码没有找到PDF中的图像?
Knowns:我的PDF每页只有1张图片,没有别的.
using iTextSharp.text;
using iTextSharp.text.pdf;
...
public static void ExtractImagesFromPDF(string sourcePdf, string outputPath)
{
// NOTE: This will only get the first image it finds per page.
PdfReader pdf = new PdfReader(sourcePdf);
RandomAccessFileOrArray raf = new iTextSharp.text.pdf.RandomAccessFileOrArray(sourcePdf);
try
{
for (int pageNumber = 1; pageNumber <= pdf.NumberOfPages; pageNumber++)
{
PdfDictionary pg = pdf.GetPageN(pageNumber);
PdfDictionary res = (PdfDictionary)PdfReader.GetPdfObject(pg.Get(PdfName.RESOURCES));
PdfDictionary xobj = (PdfDictionary)PdfReader.GetPdfObject(res.Get(PdfName.XOBJECT));
if (xobj != null)
{
foreach (PdfName name in xobj.Keys)
{
PdfObject obj = xobj.Get(name);
if (obj.IsIndirect())
{ …Run Code Online (Sandbox Code Playgroud) 我想使用ItextSharp lib转换图像中的Pdf页面.
知道如何转换图像文件中的每个页面
是否可以使用iTextSharp在句子中加粗单个单词?我试图加粗几个单词而不必将字符串分成单个短语.
我想要这种类型的输出
例如:取消原因:见本法背面第1号法令指定的法定理由.
我的实际输出低于
例如:取消原因:见本法背面第1号法令指定的法定理由.
码
pdftb4 = new PdfPTable(1);
pdftb4.WidthPercentage = 100;
width = new float[1];
width[0] = 0.7F;
pdftb4.SetWidths(width);
pdfcel4 = new PdfPCell(new Phrase("\n REASON(S) FOR CANCELLATION: See Statutoryreason(s) designated by Code No(s) 1 on the reverse side hereof", docBlackFont10));
pdfcel4.Border = 0;
pdfcel4.HorizontalAlignment = Element.ALIGN_LEFT;
pdftb4.AddCell(pdfcel4);
objDocument.Add(pdftb4);
Run Code Online (Sandbox Code Playgroud)
有人请帮帮我
我想在表中设置PdfpCell的宽度,我想设计一下

我写这段代码
PdfPCell cell;
PdfGrid tableHeader;
PdfGrid tmpTable;
PdfGrid table = new PdfGrid(numColumns: 1) { WidthPercentage = 100, RunDirection = PdfWriter.RUN_DIRECTION_LTR, ExtendLastRow = false };
string imagepath2 = HttpRuntime.AppDomainAppPath + "Header.JPG";
cell = new PdfPCell() { Border = 0, RunDirection = PdfWriter.RUN_DIRECTION_RTL };
cell.Image = iTextSharp.text.Image.GetInstance(imagepath2);
table.AddCell(cell);
tableHeader = new PdfGrid(numColumns: 10);
tableHeader.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
tmpTable = new PdfGrid(numColumns: 1);
tmpTable.TotalWidth = 10f;
tmpTable.LockedWidth = true;
cell = new PdfPCell() {Rotation =-90,VerticalAlignment =Element.ALIGN_MIDDLE, HorizontalAlignment =Element.ALIGN_CENTER, BorderWidth = 1};
cell.Phrase = …Run Code Online (Sandbox Code Playgroud) 我是iTextSharpt(用于C#的iText移植)的新手,我有以下疑问.
在我的代码中我有类似的东西:
iTextSharp.text.Paragraph titolo = new iTextSharp.text.Paragraph(currentVuln.Title, _fontTitolo0);
titolo.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
_document.Add(titolo);
table = new PdfPTable(3);
table.WidthPercentage = 98;
cell = new PdfPCell(new Phrase("Header spanning 3 columns"));
cell.Colspan = 3;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.AddCell(cell);
table.AddCell("Col 1 Row 1");
table.AddCell("Col 2 Row 1");
table.AddCell("Col 3 Row 1");
table.AddCell("Col 1 Row 2");
table.AddCell("Col 2 Row 2");
table.AddCell("Col 3 Row 2");
_document.Add(table);
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我只是打印一个标题(使用Paragraph对象)并在其下面放置一个表格.
问题是我的标题和表格之间没有空格(边距),图形结果不好,这是我在生成的PDF中获得的:

如何在标题段落和表格之间添加一些空格\边距?最好的方法是什么?我试图这样做但是,直到现在,我找不到任何解决方案
TNX
有谁知道iTextSharp使用什么单位系统?我的第一个假设是像素,但我不确定.
谢谢!
编辑:抱歉没有更具体,谢谢你让我知道.我在谈论PageSize和Margins中的度量单位.
我正在尝试做一些我认为会很简单的事情,但它不是那么直接而谷歌没有帮助.
我使用iTextSharp将PDF文档(字母)合并在一起,这样它们就可以一次打印出来.如果一个字母有奇数页面我需要附加一个空白页面,所以我们可以双面打印这些字母.
这是我目前合并所有字母的基本代码:
// initiaise
MemoryStream pdfStreamOut = new MemoryStream();
Document document = null;
MemoryStream pdfStreamIn = null;
PdfReader reader = null;
int numPages = 0;
PdfWriter writer = null;
for int(i = 0;i < letterList.Count; i++)
{
byte[] myLetterData = ...;
pdfStreamIn = new MemoryStream(myLetterData);
reader = new PdfReader(pdfStreamIn);
numPages = reader.NumberOfPages;
// open the streams to use for the iteration
if (i == 0)
{
document = new Document(reader.GetPageSizeWithRotation(1));
writer = PdfWriter.GetInstance(document, pdfStreamOut);
document.Open();
}
PdfContentByte cb = …Run Code Online (Sandbox Code Playgroud) 我正在使用iTextSharp从PDF中读取文本内容.我也能读到这一点.但我正在丢失文字格式,如字体,颜色等.有没有办法获得格式.
以下是我用于确切文本的代码段 -
PdfReader reader = new PdfReader("F:\\EBooks\\AspectsOfAjax.pdf");
textBox1.Text = ExtractTextFromPDFBytes(reader.GetPageContent(1));
private string ExtractTextFromPDFBytes(byte[] input)
{
if (input == null || input.Length == 0) return "";
try
{
string resultString = "";
// Flag showing if we are we currently inside a text object
bool inTextObject = false;
// Flag showing if the next character is literal e.g. '\\' to get a '\' character or '\(' to get '('
bool nextLiteral = false;
// () Bracket nesting level. Text appears …Run Code Online (Sandbox Code Playgroud)