You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by chitgoks <ch...@gmail.com> on 2017/06/01 11:06:47 UTC

rubberstamp annotation with base 64 image

hi

question. im basing code from this url

for rubber stamp annotation

https://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStampWithImage.java

but the sample shows loading it from a file.

im looking to create a BufferedImage from a base64 svg string. has anybody
tried this?

thanks

mark

Re: rubberstamp annotation with base 64 image

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 01.06.2017 um 14:08 schrieb Peter Pinnau:
> Hallo
>> but the sample shows loading it from a file.
>>
>> im looking to create a BufferedImage from a base64 svg string. has 
>> anybody
>> tried this?
> I think you can create a PDImageXObject object from a BufferedImage using
>
> org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory factory
>
> JPEGFactory.createFromImage( PDDocument, BufferedImage , float 
> quality, int resolution);
>
>


I'd advise against converting an image that isn't a photograph to jpeg, 
this will have artefacts. Use LosslessFactory instead.


Tilman


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: rubberstamp annotation with base 64 image

Posted by chitgoks <ch...@gmail.com>.
Sorry, i would like to confirm, that worked. just dont set a width and
height to the transcoder object. just ensure the base64 svg has a width and
height attribute inside.

Website/Java Games: http://www.chitgoks.com
My Blogs:
http://tech.chitgoks.com
http://wuhtevah.chitgoks.com
http://disneyusa.blogspot.com

On Thu, Jun 1, 2017 at 9:30 PM, chitgoks <ch...@gmail.com> wrote:

> Thanks. i found this
>
> http://codegist.net/snippet/java/bufferedimagetranscoderjava_comfreek_java
>
> the generated is not as crisp and clear though.
>
>
> On Thu, Jun 1, 2017 at 8:48 PM, Thad Humphries <th...@gmail.com>
> wrote:
>
>> On Thu, Jun 1, 2017 at 8:13 AM, chitgoks <ch...@gmail.com> wrote:
>>
>> > Hi Peter
>> >
>> > PDImageXObject imageSig = LosslessFactory.createFromImage(pdfDocument,
>> >                           ImageIO.read(new
>> > ByteArrayInputStream(DatatypeConverter.parseBase64Binary(base64Png))));
>> >
>> > works if base64 string is png..
>> >
>> > but it does not work if the base 64 is an svg.
>> >
>> > data:image/svg+xml;base64,PHN2ZyB4bW......
>> >
>> > is this a limitation?
>> >
>> > please advise
>> >
>> > mark
>>
>>
>> PDImageXObject requires a bitmap image. Internally it holds a
>> java.awt.image.BufferedImage. You will need to convert your SVG to a
>> BufferedImage. I've not done this, but  code on there is code on
>> Stackoverflow for it using Apache Batik:
>> https://stackoverflow.com/a/13931120/1316011
>>
>>
>> >
>> >
>> > Website/Java Games: http://www.chitgoks.com
>> > My Blogs:
>> > http://tech.chitgoks.com
>> > http://wuhtevah.chitgoks.com
>> > http://disneyusa.blogspot.com
>> >
>> > On Thu, Jun 1, 2017 at 8:08 PM, Peter Pinnau <
>> peter.pinnau@unterbrecher.de
>> > >
>> > wrote:
>> >
>> > > Hallo
>> > >
>> > >> but the sample shows loading it from a file.
>> > >>
>> > >> im looking to create a BufferedImage from a base64 svg string. has
>> > anybody
>> > >> tried this?
>> > >>
>> > > I think you can create a PDImageXObject object from a BufferedImage
>> using
>> > >
>> > > org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory factory
>> > >
>> > > JPEGFactory.createFromImage( PDDocument, BufferedImage , float
>> quality,
>> > > int resolution);
>> > >
>> > >
>> > > --
>> > > Viele Grüße
>> > > Peter Pinnau
>> > >
>> > >
>> > >
>> > > ---------------------------------------------------------------------
>> > > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> > > For additional commands, e-mail: users-help@pdfbox.apache.org
>> > >
>> > >
>> >
>>
>>
>>
>> --
>> "Hell hath no limits, nor is circumscrib'd In one self-place; but where we
>> are is hell, And where hell is, there must we ever be" --Christopher
>> Marlowe, *Doctor Faustus* (v. 121-24)
>>
>
>

Re: rubberstamp annotation with base 64 image

Posted by chitgoks <ch...@gmail.com>.
Thanks. i found this

http://codegist.net/snippet/java/bufferedimagetranscoderjava_comfreek_java

the generated is not as crisp and clear though.

On Thu, Jun 1, 2017 at 8:48 PM, Thad Humphries <th...@gmail.com>
wrote:

> On Thu, Jun 1, 2017 at 8:13 AM, chitgoks <ch...@gmail.com> wrote:
>
> > Hi Peter
> >
> > PDImageXObject imageSig = LosslessFactory.createFromImage(pdfDocument,
> >                           ImageIO.read(new
> > ByteArrayInputStream(DatatypeConverter.parseBase64Binary(base64Png))));
> >
> > works if base64 string is png..
> >
> > but it does not work if the base 64 is an svg.
> >
> > data:image/svg+xml;base64,PHN2ZyB4bW......
> >
> > is this a limitation?
> >
> > please advise
> >
> > mark
>
>
> PDImageXObject requires a bitmap image. Internally it holds a
> java.awt.image.BufferedImage. You will need to convert your SVG to a
> BufferedImage. I've not done this, but  code on there is code on
> Stackoverflow for it using Apache Batik:
> https://stackoverflow.com/a/13931120/1316011
>
>
> >
> >
> > Website/Java Games: http://www.chitgoks.com
> > My Blogs:
> > http://tech.chitgoks.com
> > http://wuhtevah.chitgoks.com
> > http://disneyusa.blogspot.com
> >
> > On Thu, Jun 1, 2017 at 8:08 PM, Peter Pinnau <
> peter.pinnau@unterbrecher.de
> > >
> > wrote:
> >
> > > Hallo
> > >
> > >> but the sample shows loading it from a file.
> > >>
> > >> im looking to create a BufferedImage from a base64 svg string. has
> > anybody
> > >> tried this?
> > >>
> > > I think you can create a PDImageXObject object from a BufferedImage
> using
> > >
> > > org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory factory
> > >
> > > JPEGFactory.createFromImage( PDDocument, BufferedImage , float quality,
> > > int resolution);
> > >
> > >
> > > --
> > > Viele Grüße
> > > Peter Pinnau
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> > > For additional commands, e-mail: users-help@pdfbox.apache.org
> > >
> > >
> >
>
>
>
> --
> "Hell hath no limits, nor is circumscrib'd In one self-place; but where we
> are is hell, And where hell is, there must we ever be" --Christopher
> Marlowe, *Doctor Faustus* (v. 121-24)
>

Re: rubberstamp annotation with base 64 image

Posted by Thad Humphries <th...@gmail.com>.
On Thu, Jun 1, 2017 at 8:13 AM, chitgoks <ch...@gmail.com> wrote:

> Hi Peter
>
> PDImageXObject imageSig = LosslessFactory.createFromImage(pdfDocument,
>                           ImageIO.read(new
> ByteArrayInputStream(DatatypeConverter.parseBase64Binary(base64Png))));
>
> works if base64 string is png..
>
> but it does not work if the base 64 is an svg.
>
> data:image/svg+xml;base64,PHN2ZyB4bW......
>
> is this a limitation?
>
> please advise
>
> mark


PDImageXObject requires a bitmap image. Internally it holds a
java.awt.image.BufferedImage. You will need to convert your SVG to a
BufferedImage. I've not done this, but  code on there is code on
Stackoverflow for it using Apache Batik:
https://stackoverflow.com/a/13931120/1316011


>
>
> Website/Java Games: http://www.chitgoks.com
> My Blogs:
> http://tech.chitgoks.com
> http://wuhtevah.chitgoks.com
> http://disneyusa.blogspot.com
>
> On Thu, Jun 1, 2017 at 8:08 PM, Peter Pinnau <peter.pinnau@unterbrecher.de
> >
> wrote:
>
> > Hallo
> >
> >> but the sample shows loading it from a file.
> >>
> >> im looking to create a BufferedImage from a base64 svg string. has
> anybody
> >> tried this?
> >>
> > I think you can create a PDImageXObject object from a BufferedImage using
> >
> > org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory factory
> >
> > JPEGFactory.createFromImage( PDDocument, BufferedImage , float quality,
> > int resolution);
> >
> >
> > --
> > Viele Grüße
> > Peter Pinnau
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> > For additional commands, e-mail: users-help@pdfbox.apache.org
> >
> >
>



-- 
"Hell hath no limits, nor is circumscrib'd In one self-place; but where we
are is hell, And where hell is, there must we ever be" --Christopher
Marlowe, *Doctor Faustus* (v. 121-24)

Re: rubberstamp annotation with base 64 image

Posted by chitgoks <ch...@gmail.com>.
Hi Peter

PDImageXObject imageSig = LosslessFactory.createFromImage(pdfDocument,
                          ImageIO.read(new
ByteArrayInputStream(DatatypeConverter.parseBase64Binary(base64Png))));

works if base64 string is png..

but it does not work if the base 64 is an svg.

data:image/svg+xml;base64,PHN2ZyB4bW......

is this a limitation?

please advise

mark


Website/Java Games: http://www.chitgoks.com
My Blogs:
http://tech.chitgoks.com
http://wuhtevah.chitgoks.com
http://disneyusa.blogspot.com

On Thu, Jun 1, 2017 at 8:08 PM, Peter Pinnau <pe...@unterbrecher.de>
wrote:

> Hallo
>
>> but the sample shows loading it from a file.
>>
>> im looking to create a BufferedImage from a base64 svg string. has anybody
>> tried this?
>>
> I think you can create a PDImageXObject object from a BufferedImage using
>
> org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory factory
>
> JPEGFactory.createFromImage( PDDocument, BufferedImage , float quality,
> int resolution);
>
>
> --
> Viele Grüße
> Peter Pinnau
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>

Re: rubberstamp annotation with base 64 image

Posted by Peter Pinnau <pe...@unterbrecher.de>.
Hallo
> but the sample shows loading it from a file.
>
> im looking to create a BufferedImage from a base64 svg string. has anybody
> tried this?
I think you can create a PDImageXObject object from a BufferedImage using

org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory factory

JPEGFactory.createFromImage( PDDocument, BufferedImage , float quality, 
int resolution);


-- 
Viele Grüße
Peter Pinnau



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org