Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Replace images in a pdf

0 views
Skip to first unread message

Hans Stoessel

unread,
Oct 28, 2005, 3:03:29 AM10/28/05
to
Hi

I have an existing pdf document and like to replace images in it. To do that
I want to build a C++ or Java program and look for a library (C++ or Java)
those made possible. The quality of the pdf should be remain preserved.

- Is it possible to replace images in a pdf?
- Does anybody know a library (Java or C++) to do that?
- Another idea?

Thanks in advance.

Regards
Hans


Hans-Werner Hilse

unread,
Oct 28, 2005, 4:01:12 AM10/28/05
to
Hi,

On Fri, 28 Oct 2005 09:03:29 +0200
"Hans Stoessel" <hstoess...@pm-medici.ch> wrote:

> I have an existing pdf document and like to replace images in it. To do that
> I want to build a C++ or Java program and look for a library (C++ or Java)
> those made possible. The quality of the pdf should be remain preserved.
>
> - Is it possible to replace images in a pdf?

Yes, should be. There is, however, no simple API for this, AFAIK.

> - Does anybody know a library (Java or C++) to do that?

You might want to check out pdfbox and iText (both of them Java).

> - Another idea?

For a single document, Acrobat seems to be the tool of choice...

-hwh

FyTek, Inc.

unread,
Oct 28, 2005, 10:01:05 AM10/28/05
to

PDF Meld can do this. Not sure if you want to replace all images with
a single new one or specify a replacement on an image-by-image basis
but it will handle either method.

You can use the DLL version PDF Meld with C++. The download page is
here: http://www.fytek.com/products.php?pg=pdfmeld

Thanks,
Mike Bernardo
FyTek, Inc.
http://www.fytek.com
sales @ fytek.com
Phone: 248-471-0851

Hans Stoessel

unread,
Oct 28, 2005, 11:15:54 AM10/28/05
to
Hi

There is a special image in the pdf file to replace. I mean, the program
must find the image, gets the coordinates of it and replace it with another
one.

- Can PDF Meld remove an image from a pdf?
- Can PDF Meld find an image in a pdf and the coordinates of it?
- Can PDF Meld insert a new image instead of another one?
- Waht about other object than images?

Thanks for the help.

Regards
Hans

"FyTek, Inc." <mber...@fytek.com> schrieb im Newsbeitrag
news:1130508065.5...@g43g2000cwa.googlegroups.com...

FyTek, Inc.

unread,
Oct 28, 2005, 3:41:21 PM10/28/05
to

Hans Stoessel wrote:
> Hi
>
> There is a special image in the pdf file to replace. I mean, the program
> must find the image, gets the coordinates of it and replace it with another
> one.
>
> - Can PDF Meld remove an image from a pdf?
> - Can PDF Meld find an image in a pdf and the coordinates of it?
> - Can PDF Meld insert a new image instead of another one?
> - Waht about other object than images?
>
> Thanks for the help.
>
> Regards
> Hans
>

Yes, you can remove images and/or replace them. It doesn't use
coordinates - what you do is use PDF Meld to export a list of images in
the PDF to a plain text file. Next, modify the file by adding a SRC
option on each IMG tag (looks similar to HTML). You can do this by
hand or in your program - not sure how many images you're dealing with.
Finally, create a new PDF using the current PDF as input and the text
file with the replacement images. The replacement image will then
display in the output PDF in the same area as the original. Other
options let you simply remove the image without a replacement or simply
replace all images with a single new image.

You can replace or modify other items in the PDF as well - depends on
what you're trying to do. For example, at a lower level than this, you
can uncompress the PDF to a file, remove objects you don't want to
modify and leave only the ones you change. Then you can load those
back into the PDF without worrying about the xref (byte offset cross
reference table) as PDF Meld will build that for you as well as
compress the streams. Though you should have some knowledge of the PDF
specification when you do this.

If you need more specific details, feel free to contact me at support @
fytek.com.

Hans Stoessel

unread,
Oct 31, 2005, 1:59:02 AM10/31/05
to
Hi Mike

We have dozens of pdf documents and want to replace images (or maybe another
objects) in it. To do this automatically we want write a program in C++ or
Java. As you said is PDF Meld available as a DLL with an API. So I think it
should be possible to do this, I mean we can program a C++ application.

Right?

Best regards
Hans

"FyTek, Inc." <mber...@fytek.com> schrieb im Newsbeitrag

news:1130528481.1...@g44g2000cwa.googlegroups.com...

Hans Stoessel

unread,
Oct 31, 2005, 5:43:50 AM10/31/05
to
Hi Mike

One more time its me.

I want to test the replacing of an image with your DLL. I have downloaded
the DLL and write a test application (C++ in Visual Studio .NET). I use the
following code:

void testDLL()
{
HRESULT hr;

hr = CoInitialize (NULL); // Initialize COM
if (SUCCEEDED(hr))
{
try // Each of the following lines can throw exceptions
{
// Create the instance and get a pointer to the interface
IPDFMeldPtr pPDF(__uuidof(PDFMeld));
pPDF->setInFile
(_bstr_t(L"D:\\Projekte\\CS-PdfTest\\Data\\factssheets.pdf"));
pPDF->setImgFileOut();
pPDF->setOutFile
(_bstr_t(L"D:\\Projekte\\CS-PdfTest\\Data\\factssheets_NEW.txt"));
_variant_t outval = pPDF->buildPDF (); // Build the PDF file
}
catch (_com_error e)
{
cout << e.ErrorMessage() << endl;
}
}
else
{
cout << "CoInitialize Failed" << endl;
}
CoUninitialize(); // Uninitialize COM
}

I supposed that I have a list with the images in the out file, but the file
is empty.

What could be wrong?
The code?
The pdf?
Demo version?

Thanks for any help.

Regards
Hans


"FyTek, Inc." <mber...@fytek.com> schrieb im Newsbeitrag

news:1130528481.1...@g44g2000cwa.googlegroups.com...

0 new messages