aspose file tools*
The moose likes XML and Related Technologies and the fly likes Converting SVG to PDF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Converting SVG to PDF" Watch "Converting SVG to PDF" New topic
Author

Converting SVG to PDF

Goldi Ahuja
Greenhorn

Joined: Mar 19, 2011
Posts: 11
Hello
I am using batik to create pdf documents out of my svg files which works perfect for one page images
However if i want to add detailed text just below the image and wish that pdf would display it in next page.
Anybody has any idea how to achieve this .
Basically my text is too long and I do not want my first page to have that text.
My code to convert svg to pdf goes here

TranscoderInput input = new TranscoderInput(svgURI);
OutputStream ostream = new FileOutputStream(outputFilename);
TranscoderOutput output = new TranscoderOutput(ostream);
trans.transcode(input, output);

Thanks in advance
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
I don't think SVG 1.1 -which is what Batik implements- has a concept of "pages". That may be a feature of SVG 1.2, if that ever comes to pass.

The easiest solution might be to add a second page using the iText library after the SVG->PDF transformation is done.


Ping & DNS - my free Android networking tools app
Goldi Ahuja
Greenhorn

Joined: Mar 19, 2011
Posts: 11
Thanks Ulf for a quick reply
but if my svg is converted to pdf using transcoder, the pdf would already have the entire output scaled to one page
I want to output one svg to span to two pages
DO you think it wud be gettable through itext?
Thanks again



Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
As I said, I don't think Batik supports multi-page SVGs. And, as I also said, iText can be used to add a second page to an existing PDF.
Goldi Ahuja
Greenhorn

Joined: Mar 19, 2011
Posts: 11
Is there any other alternative to batik to convert svg to multipage pdf?
thanks for your quick responses , its been a great help
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
That's unlikely, since no current SVG standard has a concept of multiple pages.

What's wrong with the approach I suggested?
Goldi Ahuja
Greenhorn

Joined: Mar 19, 2011
Posts: 11
If i got it right ,
The approach that you suggest would first convert my svg to a one page pdf i.e my image would be scaled to one page , my charts would become very small
and then using itext i can add another page

but my initial image has already been squeezed by transcoder which is not what my employer desires
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
As I understand it, the image only becomes small if there is a lot of text (or large text) underneath it; is that correct? If so, then that issue goes away if you move the text out of the SVG, and onto the second page of the PDF.
Goldi Ahuja
Greenhorn

Joined: Mar 19, 2011
Posts: 11
but the problem for me is the text is a part of my image only <text> and <tspan> tags which i cannot simple cut as a plain text
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
You can either change the process that creates the SVG, or -if that is not feasible- use DOM to remove the problematic tags from the SVG, and use the information embedded in those tags to create the second page of the PDF.
Goldi Ahuja
Greenhorn

Joined: Mar 19, 2011
Posts: 11
Not just text It has rectangles as well at the lower bottom of the page which needs to be printed in second page
Would it be possible to draw svg rectangles and texts in second page using itext ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
iText does not support SVG, but it can certainly draw lines, and consequently rectangles.

It may also be possible to split the SVG in half, thus creating two SVG files for the two pages. Then you wouldn't need to use iText at all.
Goldi Ahuja
Greenhorn

Joined: Mar 19, 2011
Posts: 11
My data for svg is in memory and being formed dynamically , how to break it into two parts ? If I create two separate PDF files , still it wont solve the purpose as my client wants one pdf with 2 pages
how do i merge the two pdf in one ? is there any utility which could do this?

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
My data for svg is in memory and being formed dynamically , how to break it into two parts ?

If it is created in your Java code, maybe you can create two SVG files from the start? Alternatively - SVG is just XML, so any DOM library can be used to operate on it in any way you see fit.

how do i merge the two pdf in one ? is there any utility which could do this?

Libraries such as PDFBox and iText can do this.
Goldi Ahuja
Greenhorn

Joined: Mar 19, 2011
Posts: 11
That means I form two svg files in my java DOM code and create two pdfs out of that and then merge them using itext
sounds good , I would try the same
Thanks a ton, I would keep you posted about the updates
Thanks again Ulf
 
Consider Paul's rocket mass heater.
 
subject: Converting SVG to PDF