Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Linux, the way to get rid of boot viruses -- MaDsen Wikholm, mwikholm@at8.abo.fi


devel / comp.lang.postscript / add a logo (png or pdf) to a PDF using only Ghostscript

SubjectAuthor
* add a logo (png or pdf) to a PDF using only GhostscriptJinsong Zhao
+- Re: add a logo (png or pdf) to a PDF using only Ghostscriptken
`- Re: add a logo (png or pdf) to a PDF using only GhostscriptDavid Newall

1
add a logo (png or pdf) to a PDF using only Ghostscript

<tqbhev$1iols$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=196&group=comp.lang.postscript#196

  copy link   Newsgroups: comp.lang.postscript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: jszhao@yeah.net (Jinsong Zhao)
Newsgroups: comp.lang.postscript
Subject: add a logo (png or pdf) to a PDF using only Ghostscript
Date: Thu, 19 Jan 2023 21:43:27 +0800
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <tqbhev$1iols$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 19 Jan 2023 13:43:59 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="d2ef4616a306347e2cb4aadff73f2055";
logging-data="1663676"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19E/xHXnlDRB/vkqku78hIW"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:EKUIxWBXjeEfZRnstoUVXc4W47w=
Content-Language: en-US
 by: Jinsong Zhao - Thu, 19 Jan 2023 13:43 UTC

Hi there,

Is it possible to add a logo (png or pdf) to a PDF using only Ghostscript?

I have learned how to embed text as PDF annotation with Ghostscript,
however, I don't find a way to emb an image to a existing PDF page.

I would appreciate any help or hint.

Best,
Jinsong

Re: add a logo (png or pdf) to a PDF using only Ghostscript

<MPG.3e3395c1f874e8f69898d9@usenet.plus.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=197&group=comp.lang.postscript#197

  copy link   Newsgroups: comp.lang.postscript
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 19 Jan 2023 18:01:35 +0000
From: ken@spamcop.net (ken)
Newsgroups: comp.lang.postscript
Subject: Re: add a logo (png or pdf) to a PDF using only Ghostscript
Date: Thu, 19 Jan 2023 18:01:11 -0000
Message-ID: <MPG.3e3395c1f874e8f69898d9@usenet.plus.net>
References: <tqbhev$1iols$1@dont-email.me>
Reply-To: ken@spamcop.net
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
User-Agent: MicroPlanet-Gravity/3.0.4
X-Antivirus: Avast (VPS 230119-6, 19/1/2023), Outbound message
X-Antivirus-Status: Clean
Lines: 27
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-PRfcaPGFD18aqxumlgI4R50hs7BsDwi5p8z0Mpufx4amGTTS98vbkn/adjLEu2MtHyeDv/b94aTV9HU!FmsfZqoyYYHC4DFRG6W9QuBePDNHvREmxF7tubYgyEasY61ox1e1fjQ0RU1EwVybKtMokGl/Bv7Y!bP1NVWVczJ8vEL6pyg==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
 by: ken - Thu, 19 Jan 2023 18:01 UTC

In article <tqbhev$1iols$1@dont-email.me>, jszhao@yeah.net says...
>
> Hi there,
>
> Is it possible to add a logo (png or pdf) to a PDF using only Ghostscript?

Sort of, but it isn't trivial. For a PNG you would first havr to write a
PostScript program to read PNG files, since Ghostscript doesn't read
PNG.

> I have learned how to embed text as PDF annotation with Ghostscript,
> however, I don't find a way to emb an image to a existing PDF page.
>
> I would appreciate any help or hint.

You need to look at the 'scripting the PDF interpreter' section of the
documentation. You will need to set up the PDF interpreter, set the
media size, draw the page contents, then draw the additioanl content,
then 'show' the page. Depending on the input you may need to open two
PDF files simultaneously to do this.

Note that Ghostscript and the pdfwrite device do not 'add' to existing
files, or modoify files. The outpuit file is completely new and may b
ear no realtyion (in its internal structure) to the original file.

Ken

Re: add a logo (png or pdf) to a PDF using only Ghostscript

<63df5624-f707-cb5f-7034-14fa7377c306@davidnewall.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=198&group=comp.lang.postscript#198

  copy link   Newsgroups: comp.lang.postscript
Message-ID: <63df5624-f707-cb5f-7034-14fa7377c306@davidnewall.com>
Date: Sat, 4 Feb 2023 14:15:47 +1100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Subject: Re: add a logo (png or pdf) to a PDF using only Ghostscript
Content-Language: en-US
To: Jinsong Zhao <jszhao@yeah.net>
Newsgroups: comp.lang.postscript
References: <tqbhev$1iols$1@dont-email.me>
From: ghostscript@davidnewall.com (David Newall)
In-Reply-To: <tqbhev$1iols$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: news.ausics.net
Organization: Ausics - https://www.ausics.net
Lines: 45
X-Complaints: abuse@ausics.net
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!news.ausics.net!not-for-mail
 by: David Newall - Sat, 4 Feb 2023 03:15 UTC

On 20/1/23 00:43, Jinsong Zhao wrote:
> Is it possible to add a logo (png or pdf) to a PDF using only
> Ghostscript?

Chapman Flack wrote various PostScript libraries, including to allow
including drawing various types of images. See www.anastigmatix.net.

Use it by converting PDF to PS (i.e. pdf2ps), include the Import
resources (plus other prerequisites), translate to where you want the
logo to appear (I generate dynamic output, so use currentpoint
translate), read the file using StatFOO and ReadyFOO, scale as
needed,ExecFOO, then convert back to PDF.

For example, you want something like this at the point you want to
display a JPEG logo:

gsave
/net.anastigmatix.Import /ProcSet findresource begin
10 700 translate % top-left of page
(logo.jpeg)(r)file StatJFIF pop ReadyJFIF
% scale to target size (e.g. 200pt)
% need to divide target size by larger of wx & wy
2 copy gt not {exch} if pop
200 exch div dup scale %
ExecJPEG
end
grestore

(I find that some JPEG files cause errors, so reprocess them with
ImageMagick; convert source.jpeg fixed.jpeg)

This converts source.pdf into output.pdf, displaying logo.jpg on every page:

{
cat anastigmatix.ps # contains required resources
echo "/logo{gsave/net.anastigmatix.Import/ProcSet findresource begin
30 700 translate
(logo.jpg)(r)file StatJFIF pop ReadyJFIF
2 copy gt not{exch}if pop 200 exch div dup scale
ExecJPEG end grestore}def"
pdf2ps - - | sed 's/showpage/logo &/'
} < source.pdf | ps2pdf -dNOSAFER - output.pdf

Note use of -dNOSAFER to allow reading the logo file.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor