我正在尝试将标头添加到现有的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 应用程序中的操作栏一样:
不幸的是,我不知道如何仅使用文本制作后退按钮以及如何在中心移动标题。这将适用于整个应用程序,而不仅仅是一种布局。
请问有人可以帮我吗?
我有一个 pdf 文件的字节数组,想要从文件中获取文本。我的下面的代码可以工作,但我需要先创建一个实际的文件。你知道更好的方法吗,这样我就不必先创建这个文件了?
try {
File temp = File.createTempFile("temp-pdf", ".tmp");
OutputStream out = new FileOutputStream(temp);
out.write(Base64.decodeBase64(testObject.getPdfAsDoc().getContent()));
out.close();
PDDocument document = PDDocument.load(temp);
PDFTextStripper pdfStripper = new PDFTextStripper();
String text = pdfStripper.getText(document);
log.info(text);
} catch(IOException e){
}
Run Code Online (Sandbox Code Playgroud) 输入:包含嵌入式字体的(例如14个)PDF / A-1b文件列表。
处理:与Apache PDFBOX进行简单合并。
结果:1个PDF / A-1b文件,文件大小太大(太大)。(这几乎是所有源文件大小的总和)。
问题:是否可以减小生成的PDF的文件大小?
想法:删除多余的嵌入式字体。但是如何?这是正确的做法吗?
不幸的是,以下代码无法完成任务,但突出了明显的问题。
try (PDDocument document = PDDocument.load(new File("E:/tmp/16189_ZU_20181121195111_5544_2008-12-31_Standardauswertung.pdf"))) {
List<COSName> collectedFonts = new ArrayList<>();
PDPageTree pages = document.getDocumentCatalog().getPages();
int pageNr = 0;
for (PDPage page : pages) {
pageNr++;
Iterable<COSName> names = page.getResources().getFontNames();
System.out.println("Page " + pageNr);
for (COSName name : names) {
collectedFonts.add(name);
System.out.print("\t" + name + " - ");
PDFont font = page.getResources().getFont(name);
System.out.println(font + ", embedded: " + font.isEmbedded());
page.getCOSObject().removeItem(COSName.F);
page.getResources().getCOSObject().removeItem(name);
}
} …Run Code Online (Sandbox Code Playgroud) 是的,这似乎是一个奇怪的问题,但我无法在 PDFBox 中渲染彩色文本。
通常生成文本的代码如下所示:
//create some document and page...
PDDocument document = new PDDocument();
PDPage page = new PDPage(PDRectangle.A4);
//defined some font
PDFont helveticaRegular = PDType1Font.HELVETICA;
//content stream for writing the text
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();
contentStream.setFont(helveticaRegular, 16);
contentStream.setStrokingColor(1f,0.5f,0.2f);
contentStream.newLineAtOffset(64, page.getMediaBox().getUpperRightY() - 64);
contentStream.showText("The hopefully colored text");
contentStream.endText();
//closing the stream
contentStream.close();
[...] //code for saving and closing the document. Nothing special
Run Code Online (Sandbox Code Playgroud)
有趣的是,这setStrokingColor是接受流上颜色的唯一方法。所以我认为这就是在 PDFBox 中给某些东西着色的方法。
但是:我没有给文本添加任何颜色。所以我想这是其他类型内容的一种方法。
有人知道如何在 PDFBox 中实现彩色文本吗?
我正在研究生成pdf文档.目前我正在尝试不同的方法.我想在pdf文档中获得多行.使用HelloWorld代码示例我想出了......
package org.apache.pdfbox.examples.pdmodel;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
/**
* Creates a "Hello World" PDF using the built-in Helvetica font.
*
* The example is taken from the PDF file format specification.
*/
public final class HelloWorld
{
private HelloWorld()
{
}
public static void main(String[] args) throws IOException
{
String filename = "line.pdf";
String message = "line";
PDDocument doc = new PDDocument();
try
{
PDPage page = new PDPage();
doc.addPage(page); …Run Code Online (Sandbox Code Playgroud) 尝试验证 PDF 签名不起作用。PDF 由 Adobe Acrobat 签名,然后尝试使用客户端证书的公钥对其进行验证。
所以我得到了客户端证书的公钥,对 PDF 进行散列并验证散列是否等于 pdf 签名,但它失败了。
HttpClientCertificate cert = request.ClientCertificate;
X509Certificate2 cert2 = new X509Certificate2(cert.Certificate);
PdfReader pdfreader = new PdfReader("path_to_file");
AcroFields fields = pdfreader.AcroFields;
AcroFields.Item item = fields.GetFieldItem("Signature1");
List<string> names = fields.GetSignatureNames();
foreach (string name in names){
PdfDictionary dict = fields.GetSignatureDictionary(name);
PdfPKCS7 pkcs7 = fields.VerifySignature(name);
Org.BouncyCastle.X509.X509Certificate pdfSign = pkcs7.SigningCertificate;
// Get its associated CSP and public key
RSACryptoServiceProvider csp = (RSACryptoServiceProvider)cert2.PublicKey.Key;
// Hash the data
SHA256 sha256 = new SHA256Managed();
byte[] pdfBytes = System.IO.File.ReadAllBytes("path_to_pdf"); …Run Code Online (Sandbox Code Playgroud) 我需要制作一张看起来像图片中的表格,列之间有空间。我试过:
cell.setPaddingLeft(10);
cell.setMarginLeft(10);
extractionMediaTable.setVerticalBorderSpacing(10);
Run Code Online (Sandbox Code Playgroud)
但这些似乎都不会影响桌子。有什么建议?
我正在尝试使用通过使用 AWS KMS 签署我的 PdfDocument 的 SHA256 摘要获得的签名在 PDF 本身上应用签名。我什至不确定我是否朝着正确的方向前进。
一切运行正常,但生成的文件的签名会引发错误:
Error during signature verification. ASN.1 parsing error: Error encountered while BER decoding:
Run Code Online (Sandbox Code Playgroud)
如果这很重要,我可以从 AWS 检索公钥,但私钥保留在他们身边。我在网上看到的大多数文档都假定您可以访问私钥。此外,由于 AWS 处理签名,我不确定如何或从何处获取证书链。我发现的所有文档也需要该证书链。
首先,我创建了一个空的签名字段,因为大多数文档都指示您这样做。我认为可能存在问题,PdfName.Adbe_pkcs7_detached但如果这是错误的,我不知道还有什么可以代替它。
public void addEmptySignatureField(File src, File destination, String fieldName) throws IOException, GeneralSecurityException {
try (
var reader = new PdfReader(src);
var output = new FileOutputStream(destination)
) {
var signer = new PdfSigner(reader, output, new StampingProperties());
signer.getSignatureAppearance()
.setPageRect(new Rectangle(36, 748, 200, 100))
.setPageNumber(1)
.setLocation("whee")
.setSignatureCreator("Mario")
.setReason("because")
.setLayer2FontSize(14f);
signer.setFieldName(fieldName);
IExternalSignatureContainer blankSignatureContainer …Run Code Online (Sandbox Code Playgroud)