Script to Cut Adobe Illustrator File into Tiles - scripting

I'm creating a Custom Google Map based on an image in an Adobe Illustrator file. I need to cut the file into 256px x 256px PNGs to feed into the Google Maps API.
You can write scripts to automate tasks in Illustrator using ExtendScript, a modified version of JavaScript. I found one example of a script for Photoshop that makes tiles for Google Maps (Hack #68 in this book) but I haven't figured out how to port this over to Illustrator.
The main problem is I can't figure out how to tell Illustrator to isolate 256px x 256px portions of an image. The Photoshop script does this by selecting portions of the image of that size and copying them into a new file, but as far as I know you can't do that in Illustrator.
Any ideas?

I've got no experience writing scripts for Adobe products, but since Illustrator handles vector data, the tiling algorithm is slightly different. There is a Python script for MS VisualEarth that tiles a set of GPS points (demo), maybe you can take some ideas from it.
Another choice may be to (programatically?) render .AI files to .PNG or something similar an then tile it into 256x256px tiles using that PS hack you referenced.

Related

Embedding PDF graphics in PDF output file programmatically

I am looking for a rough overview of how one would go about embedding graphics (coming from a PDF file) into another PDF file when writing a C++ document processor.
Background: I work on the LilyPond music typesetter, and recently added Cairo output to the system. Now I would like to support adding externally provided graphics to the PDF files that we generate (eg. adding a logo onto page laid out). This is trivial with EPS for PS output.
I can see how you could hook up Poppler to read the PDF, and render the PDF contents onto a Cairo surface, but I wonder if there is a simpler shortcut (eg. embed the PDF file as a binary stream, and then point directly to that stream).
If you need to go via an external route, like reading the PDF and writing it into an existing PDF using Cairo, that would be simpler. To do it manually:
A PDF page consists of a stream of operators for drawing it, and a dictionary of external resources (fonts, images etc.). To stamp one PDF page onto another, you would need to:
a) Find all objects for external resources in the stamp which are needed, and add them to the destination PDF.
b) Convert the page to a "Form Xobject", which is a sort of reusable piece of content. Add this to the /XObjects entry in the destination page, making sure to pick a fresh name.
c) Add some operators to the page content in the destination page to invoke the new xobject
To see how this might work, you could play with -stamp-as-xobject and -postpend-content "/XObjName Do" from section 8.4 of the cpdf manual.
Making this work for arbitrary PDFs is really not for the faint of heart, I'm afraid.

How can I add bleed to a PDF book cover using Photoshop?

I have a book cover sent as a PDF which is according 5x8 dimensions, only that is does not have bleed and I need to add it. I am using Adobe InDesign CC 2015 and Adobe Photoshop CC 2015. How can I make it happen?
Create a document in indesign and place the pdf into the document, centered. The document must have bigger dimensions for the bleed. Then put whatever in the bleed that's necessary.
A better way would be to load the pdf file into Illustrator and add the bleed there. Color matching will be a lot more accurate that way. Especially if the pdf contains any vector artwork like outlined fonts. Make sure you've got the correct fonts installed.
If the pdf only contains bitmap images, you could import it into photoshop. Make sure you've created a new document with the needed dimensions and resolution. 300 to 600 dpi would be a good starting point. Usually type will not look clean and sharp when using photoshop since its working on a picture (bitmap). Illustrator or Indesign would make type much cleaner.
If it's possible to get the source files instead, that would be the preferred method. Even if you'd have to redo the artwork would be better to have the original source files/pictures/fonts etc.

EMF GDI hDC to vector PDF

I have a bunch of base emf files that i play on a graphics surface then use gdi to merge text on the surface with drawstring to create a single page report forms.
The graphics object is then or sent to the printer, or saved as a png and then wrapped in a pdf. (iTextSharp)
I'm looking for a way to keep the pdf vector based but cant find any open source ways of getting direct access to the dc to be able to draw a metafile image.
My current pdf's are around 800k per page, where if I print the same image to a pdf printer (amyuni) its 23k. The only product that i've found is PdfTron which creates a 200k vector based file directly without printing, but is way too expensive because of all its features.
Do any of graphics experts have any suggestions for an easy way to put metadata directly into a pdf?
Thanks
Mike

Is there a tool or trick to store a large PDF image as a file (BMP/PNG/etc)?

This is not strictly a programming question, but it's related to programming task I need to perform this in order to make an iPhone app.
I have a PDF file with a large image (say, a campus map) which I want to store as a PNG image to include as resource in the app. The image I want itself is much larger than the screen area (a lot larger, about 4000x4000 px). So I cannot just take a single screenshot of the PDF and save it as PNG. The only way I know to accomplish this is to take a number of screenshots of different parts of the image and manually stitch them together in an image editor. There will be 8-10 images to stitch together, if not more.
I wonder if anyone knows a more efficient way of doing this? Acrobat PDF reader does not allow this. Are there any tools or tricks in either Windows or MacOS I can use? Googling this did not bring anything that works.
It would also be an option to use the PDF directly, iOS has pretty good support for reading PDFs, see the ZoomingPDFViewer sample code from Apple for an example.
As for your actual question, I'm not sure if there are existing tools that do exactly what you want here (though I'd guess there are), but it would also be pretty easy to make a small Cocoa command-line tool that converts a PDF to a number of bitmap tiles using Core Graphics.
You could use Ghostscript to convert your pdf to a png.
A command like
gs -sDEVICE=png16m -r600 -o my_Map.png my_Map.pdf
would provide you a png from a pdf image.

Is there a programmatic way to convert PDFs to images using Adobe's PDF renderer?

We trying to set up automated regression testing our generated PDFs by converting our them to images and then using Python Imaging library to test the difference, pixel by pixel, between new and old versions. Right now, the only step that isn't automated is converting the PDFs to images. I know there are ways to convert PDFs to images with other rendering engines (e.g. postscript), but since we're doing precise pixel by pixel comparisons we want to make sure that we are using Adobe's PDF renderer to generate the image. Is there a way to do this with Adobe's renderer?
Have a look at GhostScript - http://www.ghostscript.com/
Also have a look at the PDF tools from tall components - http://www.tallcomponents.com/
You can use Acrobat programatically, however this may be against their licensing and as far as I remember it was much slower than GhostScript.