pdfbox

PDFBox change color of a line

放肆的年华 提交于 2019-12-23 22:22:01
问题 I work with pdfbox 1.8.5 and I try to draw a colored Line using PDPageContentStream.drawLine() . I tried it with PDPageContentStream.setNonStrokingColor( 255, 0, 0 ); but it doesn't work. I also didn´t find any examples or HowTos concerning Line Color. Does anyone know, how I can change the Line Color? 回答1: Try this method. It's working for me. contentStream.setStrokingColor(229, 13, 209); 来源: https://stackoverflow.com/questions/23713959/pdfbox-change-color-of-a-line

java - generate unicode pdf with Apache PDFBox

▼魔方 西西 提交于 2019-12-23 20:56:21
问题 I have to generate pdf in my spring mvc application. recently I tested iTextPdf library, but i could not generate unicode pdf document. in fact I didn't see non-latin characters in the generated document. I decided to use Apache PDFBox for my purpose, but I don't know has it support unicode characters? If has, is there any good tutorial for learning pdfBox? And If not, which library should I use? Thanks in advance. 回答1: The 1.8.* versions don't support PDF generation with Unicode, but the 2.0

Image rotation with PDFBox

痞子三分冷 提交于 2019-12-23 20:31:16
问题 I am quit new to using PDFBox. What I need is to add an image with rotation to an exiting PDF! I know how to add the image, but my problem is how to rotate the image! I've seen somethign about AffineTransform and Matrix but I have no idea what is that and how it works! I'd really appreciate passing some sample code, and thank you in advance! Best Regards 回答1: It helps to look at the source of the "simple" image display method: public void drawXObject(PDXObject xobject, float x, float y, float

PDFBox IO Exception: COSStream has been closed and cannot be read

拈花ヽ惹草 提交于 2019-12-23 20:20:08
问题 I am having an issue with some code I'm writing in Java using PDFBox. I am attempting to populate a PDF with particular forms based on values read from an excel spreadsheet. Below is my class file. import java.io.FileInputStream; import java.io.File; 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.PDPageContentStream.AppendMode; import org

Text is missing when converting pdf file into image in java using pdfbox

一世执手 提交于 2019-12-23 12:46:26
问题 I want to convert a PDF page to image file. Text is missing when I convert a PDF page to image using java. The file which I want to convert 46_2.pdf after converting it shown me like 46_2.png Code: import java.awt.image.BufferedImage; import java.io.File; import java.util.List; import javax.imageio.ImageIO; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; public class ConvertPDFPageToImageWithoutText { public static void main(String[] args) { try { String

Visual signature with pdfbox 1.8.8

不想你离开。 提交于 2019-12-23 09:21:35
问题 I'm trying to produce PDF with visual signature and pdfbox. I have two streams and it seems that pdfbox can deal only with files. I didn't manage to make it work without three temporary files. I can see from here that API has changed, but still it deals with files. public void signPdf(InputStream originalPdf, OutputStream signedPdf, InputStream image, float x, float y, String name, String location, String reason) { File temp = null; File temp2 = null; File scratchFile = null; RandomAccessFile

PDFBox embedded TTF fonts not working

不打扰是莪最后的温柔 提交于 2019-12-23 09:20:39
问题 I am using PDFBox to build a document from an existing PDF template, so it opens the file, adds text to it, and saves it. It works well, except when trying to use external TTF fonts. I have tried different things and searched for 2 days for solutions, but there's not much out there on PDFBox. Here's some code, using the font "Tardy Kid" because it can't be mistaken for anything else, and is not likely to be part of any standard library . The code executes fine, displays "TardyKid" from the

how to globally replace font in a PDF

和自甴很熟 提交于 2019-12-23 08:07:10
问题 Is it possible, using Adobe Acrobat or another tool, to globally replace a font in a PDF? How can I do this? 回答1: Without seeing your particular file it is hard to say that this would definitely work. But, typically a font is defined like this: /Resources << /Font << /F13 1 0 R >> >> 1 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> endobj The font resource is then used as /F13 12 Tf wherever text is drawn with it. If you were to change the /BaseFont in the definition, it would

Calculation String-Width in PDFbox seems only to count characters?

那年仲夏 提交于 2019-12-23 07:29:22
问题 I've the following issue. I try to calculate the width of a string in PDFbox to center it in a rectangle. Now my problem is, that I get the same width for 12 as for 32, but the 1 is smaller than the 3 so that my text is for 12 not centered. How can I solve this issue? Thanks! 回答1: From this question: PDFont font = PDType1Font.HELVETICA_BOLD; // Or whatever font you want. int fontSize = 16; // Or whatever font size you want. float width = font.getStringWidth(text.substring(start,i)) / 1000 *

Detect if a PDF is created from a scanned document using OCR [pdfbox]

折月煮酒 提交于 2019-12-23 05:27:33
问题 I would like to know if a PDF was created from a scanned document using OCR. To make the text from the scanned document selectable, I guess the same text is written using a transparent color, a special font, ... I'm using pdfbox and I looked at the font, the color, and many other properties and I didn't find anything special. 回答1: In my case the text rendering mode was set to "Neither fill nor stroke text". pdfbox code: getGraphicsState().getTextState().getRenderingMode() == PDTextState