compress pdf with large images via java

I used code below for a proof of concept… Works a treat 🙂 Thanks to Bruno for setting me on the right path 🙂 package compressPDF; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; import java.io.IOException; import javax.imageio.ImageIO; import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.PRStream; import com.itextpdf.text.pdf.PdfName; import com.itextpdf.text.pdf.PdfNumber; import com.itextpdf.text.pdf.PdfObject; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfStamper; import … Read more

Open a selected file (image, pdf, …) programmatically from my Android Application?

Try the below code. I am using this code for opening a PDF file. You can use it for other files also. File file = new File(Environment.getExternalStorageDirectory(), “Report.pdf”); Uri path = Uri.fromFile(file); Intent pdfOpenintent = new Intent(Intent.ACTION_VIEW); pdfOpenintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); pdfOpenintent.setDataAndType(path, “application/pdf”); try { startActivity(pdfOpenintent); } catch (ActivityNotFoundException e) { } If you want to open files, … Read more

Create Index File(TOC) for merged pdf using itext library in java

You’re asking for something that should be trivial, but that isn’t. Please take a look at the MergeWithToc example. You’ll see that your code to merge PDFs is correct, but in my example, I added one extra feature: chunk = new Chunk(String.format(“Page %d”, pageNo)); if (i == 1) chunk.setLocalDestination(“p” + pageNo); ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_RIGHT, new Phrase(chunk), … Read more

Where is the Origin (x,y) of a PDF page?

The dimensions of a page (aka the page boundaries) are defined in a page dictionary: /MediaBox: the boundaries of the physical medium (the page). This value is mandatory, so you’ll find it in every PDF. /CropBox: the region that is visible when displayed or printed. The /CropBox is equal to or smaller than the /MediaBox. … Read more

How to install wkhtmltopdf on a linux based (shared hosting) web server

I’ve managed to successfully install wkhtmltopdf-amd64 on my shared hosting account without root access. Here’s what i did: Downloaded the relevant static binary v0.10.0 from here: http://code.google.com/p/wkhtmltopdf/downloads/list EDIT: The above has moved to here via ssh on my shared host typed the following: $ wget {relavant url to binary from link above} $ tar -xvf … Read more

Open PDF file on the fly from a Java application

I’d try Desktop.open(File), which: Launches the associated application to open the file. So this code should do the trick: if (Desktop.isDesktopSupported()) { try { File myFile = new File(“/path/to/file.pdf”); Desktop.getDesktop().open(myFile); } catch (IOException ex) { // no application registered for PDFs } }

How can I replace text in a PDF using Python?

You can try Aspose.PDF Cloud SDK for Python, Aspose.PDF Cloud is a REST API PDF Processing solution. It is paid API and its free package plan provides 50 credits per month. I’m developer evangelist at Aspose. import os import asposepdfcloud from asposepdfcloud.apis.pdf_api import PdfApi # Get App key and App SID from https://cloud.aspose.com pdf_api_client = … Read more

iText create document with unequal page sizes

I’ve created an UnequalPages example for you that shows how it works: Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dest)); Rectangle one = new Rectangle(70,140); Rectangle two = new Rectangle(700,400); document.setPageSize(one); document.setMargins(2, 2, 2, 2); document.open(); Paragraph p = new Paragraph(“Hi”); document.add(p); document.setPageSize(two); document.setMargins(20, 20, 20, 20); document.newPage(); document.add(p); document.close(); It is important to change … Read more

Print PDF document with python’s win32print module?

I ended up using Ghostscript to accomplish this task. There is a command line tool that relies on Ghostscript called gsprint. You don’t even need Acrobat installed to print PDFs in this fashion which is quite nice. Here is an example: on the command line: gsprint -printer \\server\printer “test.pdf” from python: win32api.ShellExecute(0, ‘open’, ‘gsprint.exe’, ‘-printer … Read more