我正在尝试创建一个 PDF 文档,其中纵向超过 2 页,其他页面为横向,我发现页面和文本都旋转到横向,我需要防止页面内容旋转。正在使用以下代码
Document document = new Document(PageSize.A4, 36, 36, 36, 72);
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream(outPutDirectory + indexID + ".pdf"));
writer.setPageEvent(new Orientation(orientation));
document.open();
XMLWorkerHelper.getInstance().parseXHtml(writer,document, new ByteArrayInputStream(parserXHtml(page.getPageContent()).getBytes()))
document.close();
Run Code Online (Sandbox Code Playgroud)
我的预期结果应该是这样的

目前,我正在处理 Microsoft 文档:Word(doc、docx)、Powerpoint(ppt、pptx)和 Excel(xls、xlsx)
我想从第一页创建预览图像。
Apache-poi 库只能完成 PowerPoint 文档。
但我找不到其他类型的解决方案。
我有一个想法将文档转换为 pdf (1) 并转换为图像 (2) 。
对于步骤 2(将 pdf 转换为图像),有许多免费的 java 库,例如 PDFBox。它与我的虚拟 pdf 文件配合得很好
但是,我在步骤 1 中遇到了问题
在我的文档中,它可能包含具有多种样式的文本、表格、图像或对象。Word 文档第一页的示例图像:
哪个开源java库可以完成这个任务?
我尝试使用以下库来实现:
JODConverter - 输出看起来不错,但它需要 OpenOffice。
docx4j - 我不确定它是否可以使用非 ooxml 格式(doc、xls、ppt)并且它真的免费吗?以下是示例代码:
String inputWordPath = "C:\\Users\\test\\Desktop\\TestPDF\\Docx.docx";
String outputPDFPath = "C:\\Users\\test\\Desktop\\TestPDF\\OutDocx4j.pdf";
try {
InputStream is = new FileInputStream(new File(inputWordPath));
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
Mapper fontMapper = new IdentityPlusMapper();
wordMLPackage.setFontMapper(fontMapper);
Docx4J.toPDF(wordMLPackage, new FileOutputStream(new File(outputPDFPath)));
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
输出看起来不错,但在生成的 pdf …
我正在尝试从现有.pdf文件复制一页并将其粘贴到新文档中,如下所示:
using (var writer = new PdfWriter(OutputFile))
{
var reader = new PdfReader("Templates//PDF_Template_Empty.pdf");
PdfDocument template = new PdfDocument(reader);
var titlepage = template.GetPage(1);
using (var pdf = new PdfDocument(writer))
{
pdf.AddPage(titlepage); // exception
Run Code Online (Sandbox Code Playgroud)
但.AddPage()它会抛出这个异常:
iText.Kernel.PdfException:“页面 iText.Kernel.Pdf.PdfPage 无法添加到文档 iText.Kernel.Pdf.PdfDocument,因为它属于文档 iText.Kernel.Pdf.PdfDocument。”
我怎样才能解决这个问题 ?
如果有人提出这个问题,请原谅我,但我还没有找到任何匹配。
我有一些PDF文件,其中图像在每个页面的资源上重复,但从未在其内容流中使用。我认为这导致PDFSplit命令创建非常肿的页面。是否有任何实用程序代码或示例可以清除此类未使用的资源?也许是我出发的起点?
我已经研究数字签名功能好几天了,现在我已经一切正常了,是时候尝试在所有页面上打印图章了,但我做得并不好......
试图给出一个快速的简历,以显示我所做的就是创建 PdfStamper、PdfSignatureAppearance 和一个 Rectangle,然后调用
appearance.setVisibleSignature(rectangle, 1, "SIGNATURE")
Run Code Online (Sandbox Code Playgroud)
上面的第二个参数“1”是我想显示图章的页码,现在可以设为 1,因为我试图在其他页面中显示图章正在创建 PdfStamper、PdfSignatureAppearance 和一个矩形,但将其设置为第 2 页。如果它有效,我会将它放在一个循环中并不断更改页面参数。
但是为什么没有效果???好吧,接近尾声时,我调用了 MakeSignature 的一个方法,在参数中,我必须传递我创建的一个外观,如果我多次调用它,则签名仅出现在与我传递给它的最后一个外观相关的页面上。
例如:
MakeSignature.signDetached(appearance2, digest, pks, chain, null, null, null, 0, CryptoStandard.CMS);
MakeSignature.signDetached(appearance, digest, pks, chain, null, null, null, 0, CryptoStandard.CMS);
Run Code Online (Sandbox Code Playgroud)
邮票将仅显示在第一页上。
也许我可以在这里得到一些帮助???
这里是整个事情:
public String signPdfFirstTime(String src, String dest, PrivateKey pk, Certificate[] chain, String providerName, String conteudoBase64, X509Certificate cert, String alias) throws IOException, DocumentException, GeneralSecurityException
{
byte[] conteudoBinario = Base64.decode(conteudoBase64);
FileOutputStream fos = new FileOutputStream(path + File.separator + src);
fos.write(conteudoBinario);
fos.close();
File f = …Run Code Online (Sandbox Code Playgroud) 所以...我一直在尝试使用 itext 文档中提供的示例来合并文档并为合并的结果创建一个目录。但是将页码文本添加到每个页面的部分并没有像我预期的那样工作。发生的情况是添加的文本在某个水平轴上翻转,如下图所示:

此外,用于为添加的文本 ( public T setFixedPosition(int pageNumber, float left, float bottom, float width))设置固定位置的方法的 java 文档对我来说没有意义:
为元素的绝对重新定位设置值。指定的坐标对应于元素的左下角并向上增长。
但是当我运行时setFixedPosition(pageNumber, 0, 0, 50),文本最终出现在左上角,再次翻转。如果我分别使用源 PdfDocument 页面大小的宽度和高度作为左侧和底部位置的参数,它甚至不会到达右下角。
我可能做错了什么或误解了什么。无论哪种方式,这是我正在使用的代码:
private static int copyPdfPages(PdfDocument source, Document document, Integer start, Integer pages, Integer number) {
int oldC;
int max = start + pages - 1;
Text text;
for (oldC = start; oldC <= max; oldC++) {
text = new Text(String.format("Page %d", number));
PageSize pageSize = source.getDefaultPageSize();
source.copyPagesTo(oldC, oldC, document.getPdfDocument());
document.add(new Paragraph(text).setBorder(new SolidBorder(ColorConstants.RED, 1)) …Run Code Online (Sandbox Code Playgroud) 我正在尝试将标头添加到现有的PDF文件中.它可以工作,但现有PDF中的表头由字体的变化搞砸了.如果我删除设置字体,则标题不会显示.这是我的代码:
// the document
PDDocument doc = null;
try
{
doc = PDDocument.load( file );
List allPages = doc.getDocumentCatalog().getAllPages();
//PDFont font = PDType1Font.HELVETICA_BOLD;
for( int i=0; i<allPages.size(); i++ )
{
PDPage page = (PDPage)allPages.get( i );
PDRectangle pageSize = page.findMediaBox();
PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true,true);
PDFont font = PDType1Font.TIMES_ROMAN;
float fontSize = 15.0f;
contentStream.beginText();
// set font and font size
contentStream.setFont( font, fontSize);
contentStream.moveTextPositionByAmount(700, 1150);
contentStream.drawString( message);
contentStream.endText();
//contentStream.
contentStream.close();}
doc.save( outfile );
}
finally
{
if( …Run Code Online (Sandbox Code Playgroud) 我找不到matlab中的函数,它实现了正态分布的均值和标准差,并绘制了PDF和CDF.
我担心我实现的两个函数都丢失了,因为我得到的最大值pdfNormal大于1.
function plotNormPDF(u,s,color)
mu = u;
sigma = s;
x = (mu - 5 * sigma) : (sigma / 100) : (mu + 5 * sigma);
pdfNormal = normpdf(x, mu, sigma);
string = 'the maximal pdfNormal is';
string = sprintf('%s :%d', string,max(pdfNormal));
disp(string)
plot(x, pdfNormal/max(pdfNormal),color);
end
Run Code Online (Sandbox Code Playgroud)
而对于CDF规范
function plotNormCDF(u,s,color)
mu = u;
sigma = s;
x = (mu - 5*sigma) : (sigma / 100) : (mu + 5*sigma);
pdfNormal = normpdf(x, mu, sigma); …Run Code Online (Sandbox Code Playgroud) 我希望在我的 Android 应用程序中设置一个操作栏,就像我在 iOS 应用程序中的操作栏一样:
不幸的是,我不知道如何仅使用文本制作后退按钮以及如何在中心移动标题。这将适用于整个应用程序,而不仅仅是一种布局。
请问有人可以帮我吗?
黑色形状是需要提取的文本:
到目前为止,我已经从列中提取了文本,但是是手动提取的,因为只有 5 个(对区域使用 Rectangle 类)。我的问题是:有没有办法对行执行此操作,因为矩形的大小(高度)不同,并且手动对 50 多行执行此操作将是一种暴行?更具体地说,我可以使用函数根据每行的高度更改矩形吗?或者有什么建议可能有帮助吗?