Removing white-space from a pdf using PDFBox - java

I'm calling Fedex API to generate a shipping label. The API returns a byte array. I then write this byte array to a pdf using:
Files.write(Paths.get("xyz.pdf"), imgBytes); //imgBytes is the response I get from Fedex API
However, when I open the file, I see that the actual label occupies only about 2/3rd by width and 1/2 by height of the entire pdf because of which I'm having a lot of white space in the PDF.
Is it possible to somehow remove this white-space using PDFBox? Or is it possible to remove the white-space while saving the byte array to the pdf file?
Thanks.

Related

Itext PDF: adding image after text of dynamic length

I am using Itext pdf java library to generate pdf document.
Need to add an image to pdf page after some text snippet. As per current design, the first text will be added to pdf and later on based on the PdfPageEventHelper images will be added.
Now the problem is text snippet can be of any length. So while adding the image I need to provide x and y coordinates. How can I calculate that based on the length of text snippet on that page so that text and image don't overlap?

Convert sheet (ideally range) to picture

is there a way to convert a range of a POI sheet to image (any extension) ?
Is there an library that can help me do that (beside aspose) ?
Thank you so much
Aspose.Cells can convert your Range into Image. Please see the following article for sample code. The code first sets the print area to your desired range. For example, in the article, it is setting print area to E18:H15. You can also set print area manually with Microsoft Excel. After setting print area, it takes the image of entire worksheet using the options.OnePagePerSheet = true statement. But entire worksheet will not be printed in the image and only the range E18:H15 will be printed in the image, hence your purpose is achieved.
Please note, if you do not set the print area and OnePagePerSheet is true, then you will get the image of entire worksheet. And if OnePagePerSheet is false, then you will get as number of images as there are number of pages inside the worksheet.
Article Link:
Export Range of Cells in a Worksheet to Image
Note: I am working as Developer Evangelist at Aspose

Extracting Images with PDFBox - Images being split into strips

I'm using PDFBox to extract the images out of a PDF. My code is based on the example provided by PDFBox, here.
However, some images are being extracted as a number of horizontal 'strips', i.e. a single image in the PDF is extracted as 5 (for example) images that need stitching back together to form the whole image.
Why is this happening, and how do I stop it happening so I can extract the full single image?

How to edit a PDF using iText

I need to delete a text in several PDF files, which is always at the same position. How to achieve this with iText?
I've tried to use the PdfStamper and draw a white filled rectangle over this. This was ok, but the text wasn't really deleted and each PDF Reader (Acrobta, Foxit, etc.) were able to mark the content (ctrl+a), copy and paste it.

Browsing PDF page content. Problem with color space and DPI

I am writing a program that would validate PDF file. I am using iText java library to get content of a file, but I have some problems with parsing it. I need to get info about color space and DPI of each image. How can I get info about position and dimensions of image in PDF? I tried to browse each XObject of PDF but I stuck, I cannot find any information about width and height of file in PDF.
Are there any other libraries which can help me?
Thank You for all answers and tips.
The image object in the PDF file stores only the Width and the Height of the image in pixels. In order to know the position and size of the image on the page, in PDF points, you have to execute the page content stream, to create a virtual rendering. The image is painted on the page using the 'Do' operator and its position and size are given by the current transformation matrix that is in place when the 'Do' operator is executed.
The DPI for a specific drawing instance is computed as 72*imageSizeInPixels/imageSizeInPoints, imageSizeInPoints being computed as described above.

Categories

Resources