You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Rich Stafford <ri...@equorum.com> on 2023/01/05 15:28:38 UTC

PDFBox and Batik SVGGraphics2d

I am having an issue using PDFBox (pdfbox-app-2.0.21.jar) and SVGGraphics2d (batik-1ll-1.16.jar) to generate SVG output from a small PDF file.

This file has about 9 vector lines, and a rectangle filled with horizontal lines.  Using the PDFBox PDFRenderer to JPG, I get the appropriate fill for the rectangle:

screen capture:
Emacs!


However, using the PDFBox PDFRenderer with SVGGraphics2d, I get a black filled rectangle.

screen capture:
Emacs!


The generator code fragment is as follows:

// setup instance of org.w3c.dom.Document
DOMImplementation oDom = GenericDOMImplementation.getDOMImplementation();
String sSvgOrg = "http://www.w3.org/2000/svg";
Document oSvgDoc = oDom.createDocument(sSvgOrg, "svg", null);
SVGGeneratorContext oCtx = SVGGeneratorContext.createDefault(oSvgDoc);
oCtx.setEmbeddedFontsOn(true);

// setup renderer object
PDFRenderer oRender = new PDFRenderer( oDoc );

// loop for all pages in the PDF
for ( int nPageNdx = 0; nPageNdx < oDoc.getNumberOfPages(); nPageNdx++ )
{
        // setup output file
        if ( sOutputMode.equalsIgnoreCase("svg") )
        {       // svg
                String sSvgPageSpec = GenericUtil.PathMake(sDestPath, "page-"+nPageNdx+".svg");
                (new File(sSvgPageSpec)).createNewFile();
                // setup instance of SVG Generator
                SVGGraphics2D oSvgGen = new SVGGraphics2D( oCtx, false );
                // render the page to SVG
                oRender.renderPageToGraphics( nPageNdx, oSvgGen );
                // write to file
                OutputStream oOutStream = new FileOutputStream( new File(sSvgPageSpec) );
                Writer oOutWriter = new OutputStreamWriter( oOutStream, "UTF-8" );
                oSvgGen.stream( oOutWriter, true );
                continue;
        }
        if ( sOutputMode.equalsIgnoreCase("jpg") )
        {       // jpg output
                String sJpgPageSpec = GenericUtil.PathMake(sDestPath, "page-"+nPageNdx+".jpg");
                File oFileJpg = new File(sJpgPageSpec);
                BufferedImage image = oRender.renderImageWithDPI(nPageNdx, GenericUtil.parseInt(sDpi, 300));
                ImageIO.write(image, "JPEG", oFileJpg);
                continue;
        }
}

I've attached the input PDF file as well.

Thoughts?

Rich Stafford
Chief Scientist
eQuorum Corporation

Re: PDFBox and Batik SVGGraphics2d

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

I can't help with BATIK. Have a look at what happens when 
TilingPaint.createContext() is called. This calls 
TexturePaint.createContext(). Which calls 
TexturePaintContext.getContext() where the show happens. There is some 
raster stuff going on but I don't know what happens with SVG. They have 
a class SVGTexturePaint, I wonder if they use it.

Tilman

On 09.01.2023 20:13, Rich Stafford wrote:
> Tilman,
>
> I've traced the code, and see where it is stroking the pattern onto a TilingPaint object in response to the PDF 'B' operator.  However, I don't see any code that adds the generated bitmap to the DOM.  Consequently, it never gets written to the output SVG.
>
> I"m using the default ImageHandlerBase64Encoder which is supposed to store the base64 encoded images directly in the SVG output/
>
> What am I missing?
>
> Rich Stafford
> Chief Scientist
> eQuorum Corporation
>
> At 12:26 PM 1/6/2023, Tilman Hausherr wrote:
>> Hi,
>>
>> This is in TilingPaint.java  and PageDrawer.java . It's one of the tricky parts in the code. No we can't draw them as vectors.
>>
>> Tilman
>>
>> On 06.01.2023 17:57, Rich Stafford wrote:
>>> Which PDFBox module handles the patterns?  Is there anyway to have PDFBox draw the patterns as vectors?
>>>
>>> Rich
>>>
>>> At 11:40 AM 1/6/2023, Tilman Hausherr wrote:
>>>> Hi,
>>>>
>>>> I can confirm the effect with my own conversion code (which may or may not be the same). I looked at the SVG and there's one thing missing: PDFBox converts patterns to bitmaps and then uses TexturePaint. So there should be some binary content in the SVG but there isn't. Could it be that there is some option that should be set?
>>>>
>>>> Btw the PDF has some errors, like 0 255 0 sc  (or rg), this should be 0 1 0 sc (or rg). But this isn't the cause.
>>>>
>>>> Tilman
>>>>
>>>> On 06.01.2023 14:51, Rich Stafford wrote:
>>>>> Tilman:
>>>>>
>>>>> Thanks for your quick response.  I've upgraded to PDFBox 2.0.27, with the same results.
>>>>>
>>>>> The PDF file can be downloaded here:
>>>>>
>>>>> https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf
>>>>>
>>>>> <https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf>Thanks for any assistance.  I'm going to start tracing thru Batik source code for the SVG error.
>>>>>
>>>>> Rich Stafford
>>>>> Chief Scientist
>>>>> eQuorum Corporation
>>>>> ***
>>>>> At 01:28 PM 1/5/2023, Tilman Hausherr wrote:
>>>>>> Hi,
>>>>>>
>>>>>> Please try with 2.0.27 and upload the PDF somewhere, it didn't get through.
>>>>>>
>>>>>> Tilman
>>>>>>
>>>>>> On 05.01.2023 16:28, Rich Stafford wrote:
>>>>>>> I am having an issue using PDFBox (pdfbox-app-2.0.21.jar) and SVGGraphics2d (batik-1ll-1.16.jar) to generate SVG output from a small PDF file.
>>>>>>>
>>>>>>> This file has about 9 vector lines, and a rectangle filled with horizontal lines.  Using the PDFBox PDFRenderer to JPG, I get the appropriate fill for the rectangle:
>>>>>>>
>>>>>>> screen capture:
>>>>>>> Emacs!
>>>>>>>
>>>>>>> However, using the PDFBox PDFRenderer with SVGGraphics2d, I get a black filled rectangle.
>>>>>>>
>>>>>>> screen capture:
>>>>>>> Emacs!
>>>>>>>
>>>>>>> The generator code fragment is as follows:
>>>>>>>
>>>>>>> // setup instance of org.w3c.dom.Document
>>>>>>> DOMImplementation oDom= GenericDOMImplementation./getDOMImplementation/();
>>>>>>> String sSvgOrg= " http://www.w3.org/2000/svg";
>>>>>>> Document oSvgDoc= oDom.createDocument(sSvgOrg, "svg", *null*);
>>>>>>> SVGGeneratorContext oCtx= SVGGeneratorContext./createDefault/(oSvgDoc);
>>>>>>> oCtx.setEmbeddedFontsOn(*true* );
>>>>>>>
>>>>>>> // setup renderer object
>>>>>>> PDFRenderer oRender= *new* PDFRenderer( oDoc);
>>>>>>>
>>>>>>> // loop for all pages in the PDF
>>>>>>> *for* ( *int* nPageNdx= 0; nPageNdx< oDoc.getNumberOfPages(); nPageNdx++ )
>>>>>>> {
>>>>>>> // setup output file
>>>>>>> *if* ( sOutputMode.equalsIgnoreCase("svg") )
>>>>>>> {// svg
>>>>>>> String sSvgPageSpec= GenericUtil./PathMake/(sDestPath, "page-"+ nPageNdx+".svg");
>>>>>>> ( *new* File( sSvgPageSpec)).createNewFile();
>>>>>>> // setup instance of SVG Generator
>>>>>>> SVGGraphics2D oSvgGen= *new* SVGGraphics2D( oCtx, *false*);
>>>>>>> // render the page to SVG
>>>>>>> oRender .renderPageToGraphics( nPageNdx, oSvgGen);
>>>>>>> // write to file
>>>>>>> OutputStream oOutStream= *new* FileOutputStream( *new* File(sSvgPageSpec) );
>>>>>>> Writer oOutWriter= *new* OutputStreamWriter( oOutStream, "UTF-8");
>>>>>>> oSvgGen .stream( oOutWriter, *true*);
>>>>>>> *continue* ;
>>>>>>> }
>>>>>>> *if* ( sOutputMode.equalsIgnoreCase("jpg") )
>>>>>>> {// jpg output
>>>>>>> String sJpgPageSpec= GenericUtil./PathMake/(sDestPath, "page-"+ nPageNdx+".jpg");
>>>>>>> File oFileJpg= *new* File(sJpgPageSpec);
>>>>>>> BufferedImage image= oRender.renderImageWithDPI(nPageNdx, GenericUtil./parseInt/(sDpi, 300));
>>>>>>> Â Â Â Â ImageIO./write/(image, "JPEG", oFileJpg);
>> Jpg);
>>>>>>> continue;
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> I've attached the input PDF file as well.
>>>>>>>
>>>>>>> Thoughts?
>>>>>>>
>>>>>>> Rich Stafford
>>>>>>> Chief Scientist
>>>>>>> eQuorum Corporation
>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail:
>>>>>>> users-unsubscribe@pdfbox.apache.org
>>>>>>> For additional commands, e-mail:
>>>>>>> users-help@pdfbox.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org



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


Re: PDFBox and Batik SVGGraphics2d

Posted by Rich Stafford <ri...@equorum.com>.
Tilman,

I've traced the code, and see where it is stroking the pattern onto a TilingPaint object in response to the PDF 'B' operator.  However, I don't see any code that adds the generated bitmap to the DOM.  Consequently, it never gets written to the output SVG.

I"m using the default ImageHandlerBase64Encoder which is supposed to store the base64 encoded images directly in the SVG output/

What am I missing?

Rich Stafford
Chief Scientist
eQuorum Corporation

At 12:26 PM 1/6/2023, Tilman Hausherr wrote:
>Hi,
>
>This is in TilingPaint.java  and PageDrawer.java . It's one of the tricky parts in the code. No we can't draw them as vectors.
>
>Tilman
>
>On 06.01.2023 17:57, Rich Stafford wrote:
>>Which PDFBox module handles the patterns?  Is there anyway to have PDFBox draw the patterns as vectors?
>>
>>Rich
>>
>>At 11:40 AM 1/6/2023, Tilman Hausherr wrote:
>>>Hi,
>>>
>>>I can confirm the effect with my own conversion code (which may or may not be the same). I looked at the SVG and there's one thing missing: PDFBox converts patterns to bitmaps and then uses TexturePaint. So there should be some binary content in the SVG but there isn't. Could it be that there is some option that should be set?
>>>
>>>Btw the PDF has some errors, like 0 255 0 sc  (or rg), this should be 0 1 0 sc (or rg). But this isn't the cause.
>>>
>>>Tilman
>>>
>>>On 06.01.2023 14:51, Rich Stafford wrote:
>>>>Tilman:
>>>>
>>>>Thanks for your quick response.  I've upgraded to PDFBox 2.0.27, with the same results.
>>>>
>>>>The PDF file can be downloaded here:
>>>>
>>>>https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf
>>>>
>>>><https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf>Thanks for any assistance.  I'm going to start tracing thru Batik source code for the SVG error.
>>>>
>>>>Rich Stafford
>>>>Chief Scientist
>>>>eQuorum Corporation
>>>>***
>>>>At 01:28 PM 1/5/2023, Tilman Hausherr wrote:
>>>>>Hi,
>>>>>
>>>>>Please try with 2.0.27 and upload the PDF somewhere, it didn't get through.
>>>>>
>>>>>Tilman
>>>>>
>>>>>On 05.01.2023 16:28, Rich Stafford wrote:
>>>>>>I am having an issue using PDFBox (pdfbox-app-2.0.21.jar) and SVGGraphics2d (batik-1ll-1.16.jar) to generate SVG output from a small PDF file.
>>>>>>
>>>>>>This file has about 9 vector lines, and a rectangle filled with horizontal lines.ÂÂ  Using the PDFBox PDFRenderer to JPG, I get the appropriate fill for the rectangle:
>>>>>>
>>>>>>screen capture:
>>>>>>Emacs!
>>>>>>
>>>>>>However, using the PDFBox PDFRenderer with SVGGraphics2d, I get a black filled rectangle.
>>>>>>
>>>>>>screen capture:
>>>>>>Emacs!
>>>>>>
>>>>>>The generator code fragment is as follows:
>>>>>>
>>>>>>// setup instance of org.w3c.dom.Document
>>>>>>DOMImplementation oDom= GenericDOMImplementation./getDOMImplementation/();
>>>>>>String sSvgOrg= " http://www.w3.org/2000/svg";
>>>>>>Document oSvgDoc= oDom.createDocument(sSvgOrg, "svg", *null*);
>>>>>>SVGGeneratorContext oCtx= SVGGeneratorContext./createDefault/(oSvgDoc);
>>>>>>oCtx.setEmbeddedFontsOn(*true* );
>>>>>>
>>>>>>// setup renderer object
>>>>>>PDFRenderer oRender= *new* PDFRenderer( oDoc);
>>>>>>
>>>>>>// loop for all pages in the PDF
>>>>>>*for* ( *int* nPageNdx= 0; nPageNdx< oDoc.getNumberOfPages(); nPageNdx++ )
>>>>>>{
>>>>>>// setup output file
>>>>>>*if* ( sOutputMode.equalsIgnoreCase("svg") )
>>>>>>{// svg
>>>>>>String sSvgPageSpec= GenericUtil./PathMake/(sDestPath, "page-"+ nPageNdx+".svg");
>>>>>>( *new* File( sSvgPageSpec)).createNewFile();
>>>>>>// setup instance of SVG Generator
>>>>>>SVGGraphics2D oSvgGen= *new* SVGGraphics2D( oCtx, *false*);
>>>>>>// render the page to SVG
>>>>>>oRender .renderPageToGraphics( nPageNdx, oSvgGen);
>>>>>>// write to file
>>>>>>OutputStream oOutStream= *new* FileOutputStream( *new* File(sSvgPageSpec) );
>>>>>>Writer oOutWriter= *new* OutputStreamWriter( oOutStream, "UTF-8");
>>>>>>oSvgGen .stream( oOutWriter, *true*);
>>>>>>*continue* ;
>>>>>>}
>>>>>>*if* ( sOutputMode.equalsIgnoreCase("jpg") )
>>>>>>{// jpg output
>>>>>>String sJpgPageSpec= GenericUtil./PathMake/(sDestPath, "page-"+ nPageNdx+".jpg");
>>>>>>File oFileJpg= *new* File(sJpgPageSpec);
>>>>>>BufferedImage image= oRender.renderImageWithDPI(nPageNdx, GenericUtil./parseInt/(sDpi, 300));
>>>>>>Â Â Â Â ImageIO./write/(image, "JPEG", oFileJpg);
>Jpg);
>>>>>>continue;
>>>>>>}
>>>>>>}
>>>>>>
>>>>>>I've attached the input PDF file as well.
>>>>>>
>>>>>>Thoughts?
>>>>>>
>>>>>>Rich Stafford
>>>>>>Chief Scientist
>>>>>>eQuorum Corporation
>>>>>>
>>>>>>
>>>>>>---------------------------------------------------------------------
>>>>>>To unsubscribe, e-mail:
>>>>>>users-unsubscribe@pdfbox.apache.org
>>>>>>For additional commands, e-mail:
>>>>>>users-help@pdfbox.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>For additional commands, e-mail: users-help@pdfbox.apache.org

Re: PDFBox and Batik SVGGraphics2d

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

This is in TilingPaint.java  and PageDrawer.java . It's one of the 
tricky parts in the code. No we can't draw them as vectors.

Tilman

On 06.01.2023 17:57, Rich Stafford wrote:
> Which PDFBox module handles the patterns?  Is there anyway to have PDFBox draw the patterns as vectors?
>
> Rich
>
> At 11:40 AM 1/6/2023, Tilman Hausherr wrote:
>> Hi,
>>
>> I can confirm the effect with my own conversion code (which may or may not be the same). I looked at the SVG and there's one thing missing: PDFBox converts patterns to bitmaps and then uses TexturePaint. So there should be some binary content in the SVG but there isn't. Could it be that there is some option that should be set?
>>
>> Btw the PDF has some errors, like 0 255 0 sc  (or rg), this should be 0 1 0 sc (or rg). But this isn't the cause.
>>
>> Tilman
>>
>> On 06.01.2023 14:51, Rich Stafford wrote:
>>> Tilman:
>>>
>>> Thanks for your quick response.  I've upgraded to PDFBox 2.0.27, with the same results.
>>>
>>> The PDF file can be downloaded here:
>>>
>>> https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf
>>>
>>> <https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf>Thanks for any assistance.  I'm going to start tracing thru Batik source code for the SVG error.
>>>
>>> Rich Stafford
>>> Chief Scientist
>>> eQuorum Corporation
>>> ***
>>> At 01:28 PM 1/5/2023, Tilman Hausherr wrote:
>>>> Hi,
>>>>
>>>> Please try with 2.0.27 and upload the PDF somewhere, it didn't get through.
>>>>
>>>> Tilman
>>>>
>>>> On 05.01.2023 16:28, Rich Stafford wrote:
>>>>> I am having an issue using PDFBox (pdfbox-app-2.0.21.jar) and SVGGraphics2d (batik-1ll-1.16.jar) to generate SVG output from a small PDF file.
>>>>>
>>>>> This file has about 9 vector lines, and a rectangle filled with horizontal lines.  Using the PDFBox PDFRenderer to JPG, I get the appropriate fill for the rectangle:
>>>>>
>>>>> screen capture:
>>>>> Emacs!
>>>>>
>>>>> However, using the PDFBox PDFRenderer with SVGGraphics2d, I get a black filled rectangle.
>>>>>
>>>>> screen capture:
>>>>> Emacs!
>>>>>
>>>>> The generator code fragment is as follows:
>>>>>
>>>>> // setup instance of org.w3c.dom.Document
>>>>> DOMImplementation oDom= GenericDOMImplementation./getDOMImplementation/();
>>>>> String sSvgOrg= " http://www.w3.org/2000/svg";
>>>>> Document oSvgDoc= oDom.createDocument(sSvgOrg, "svg", *null*);
>>>>> SVGGeneratorContext oCtx= SVGGeneratorContext./createDefault/(oSvgDoc);
>>>>> oCtx.setEmbeddedFontsOn(*true* );
>>>>>
>>>>> // setup renderer object
>>>>> PDFRenderer oRender= *new* PDFRenderer( oDoc);
>>>>>
>>>>> // loop for all pages in the PDF
>>>>> *for* ( *int* nPageNdx= 0; nPageNdx< oDoc.getNumberOfPages(); nPageNdx++ )
>>>>> {
>>>>> // setup output file
>>>>> *if* ( sOutputMode.equalsIgnoreCase("svg") )
>>>>> {// svg
>>>>> String sSvgPageSpec= GenericUtil./PathMake/(sDestPath, "page-"+ nPageNdx+".svg");
>>>>> ( *new* File( sSvgPageSpec)).createNewFile();
>>>>> // setup instance of SVG Generator
>>>>> SVGGraphics2D oSvgGen= *new* SVGGraphics2D( oCtx, *false*);
>>>>> // render the page to SVG
>>>>> oRender .renderPageToGraphics( nPageNdx, oSvgGen);
>>>>> // write to file
>>>>> OutputStream oOutStream= *new* FileOutputStream( *new* File(sSvgPageSpec) );
>>>>> Writer oOutWriter= *new* OutputStreamWriter( oOutStream, "UTF-8");
>>>>> oSvgGen .stream( oOutWriter, *true*);
>>>>> *continue* ;
>>>>> }
>>>>> *if* ( sOutputMode.equalsIgnoreCase("jpg") )
>>>>> {// jpg output
>>>>> String sJpgPageSpec= GenericUtil./PathMake/(sDestPath, "page-"+ nPageNdx+".jpg");
>>>>> File oFileJpg= *new* File(sJpgPageSpec);
>>>>> BufferedImage image= oRender.renderImageWithDPI(nPageNdx, GenericUtil./parseInt/(sDpi, 300));
>>>>> Â Â Â Â ImageIO./write/(image, "JPEG", oFileJpg);
>>>>> continue;
>>>>> }
>>>>> }
>>>>>
>>>>> I've attached the input PDF file as well.
>>>>>
>>>>> Thoughts?
>>>>>
>>>>> Rich Stafford
>>>>> Chief Scientist
>>>>> eQuorum Corporation
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail:
>>>>> users-unsubscribe@pdfbox.apache.org
>>>>> For additional commands, e-mail:
>>>>> users-help@pdfbox.apache.org
>>>>


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


Re: PDFBox and Batik SVGGraphics2d

Posted by Rich Stafford <ri...@equorum.com>.
Which PDFBox module handles the patterns?  Is there anyway to have PDFBox draw the patterns as vectors?

Rich

At 11:40 AM 1/6/2023, Tilman Hausherr wrote:
>Hi,
>
>I can confirm the effect with my own conversion code (which may or may not be the same). I looked at the SVG and there's one thing missing: PDFBox converts patterns to bitmaps and then uses TexturePaint. So there should be some binary content in the SVG but there isn't. Could it be that there is some option that should be set?
>
>Btw the PDF has some errors, like 0 255 0 sc  (or rg), this should be 0 1 0 sc (or rg). But this isn't the cause.
>
>Tilman
>
>On 06.01.2023 14:51, Rich Stafford wrote:
>>Tilman:
>>
>>Thanks for your quick response.  I've upgraded to PDFBox 2.0.27, with the same results.
>>
>>The PDF file can be downloaded here:
>>
>>https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf
>>
>><https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf>Thanks for any assistance.  I'm going to start tracing thru Batik source code for the SVG error.
>>
>>Rich Stafford
>>Chief Scientist
>>eQuorum Corporation
>>***
>>At 01:28 PM 1/5/2023, Tilman Hausherr wrote:
>>>Hi,
>>>
>>>Please try with 2.0.27 and upload the PDF somewhere, it didn't get through.
>>>
>>>Tilman
>>>
>>>On 05.01.2023 16:28, Rich Stafford wrote:
>>>>I am having an issue using PDFBox (pdfbox-app-2.0.21.jar) and SVGGraphics2d (batik-1ll-1.16.jar) to generate SVG output from a small PDF file.
>>>>
>>>>This file has about 9 vector lines, and a rectangle filled with horizontal lines.  Using the PDFBox PDFRenderer to JPG, I get the appropriate fill for the rectangle:
>>>>
>>>>screen capture:
>>>>Emacs!
>>>>
>>>>However, using the PDFBox PDFRenderer with SVGGraphics2d, I get a black filled rectangle.
>>>>
>>>>screen capture:
>>>>Emacs!
>>>>
>>>>The generator code fragment is as follows:
>>>>
>>>>// setup instance of org.w3c.dom.Document
>>>>DOMImplementation oDom= GenericDOMImplementation./getDOMImplementation/();
>>>>String sSvgOrg= " http://www.w3.org/2000/svg";
>>>>Document oSvgDoc= oDom.createDocument(sSvgOrg, "svg", *null*);
>>>>SVGGeneratorContext oCtx= SVGGeneratorContext./createDefault/(oSvgDoc);
>>>>oCtx.setEmbeddedFontsOn(*true* );
>>>>
>>>>// setup renderer object
>>>>PDFRenderer oRender= *new* PDFRenderer( oDoc);
>>>>
>>>>// loop for all pages in the PDF
>>>>*for* ( *int* nPageNdx= 0; nPageNdx< oDoc.getNumberOfPages(); nPageNdx++ )
>>>>{
>>>>// setup output file
>>>>*if* ( sOutputMode.equalsIgnoreCase("svg") )
>>>>{// svg
>>>>String sSvgPageSpec= GenericUtil./PathMake/(sDestPath, "page-"+ nPageNdx+".svg");
>>>>( *new* File( sSvgPageSpec)).createNewFile();
>>>>// setup instance of SVG Generator
>>>>SVGGraphics2D oSvgGen= *new* SVGGraphics2D( oCtx, *false*);
>>>>// render the page to SVG
>>>>oRender .renderPageToGraphics( nPageNdx, oSvgGen);
>>>>// write to file
>>>>OutputStream oOutStream= *new* FileOutputStream( *new* File(sSvgPageSpec) );
>>>>Writer oOutWriter= *new* OutputStreamWriter( oOutStream, "UTF-8");
>>>>oSvgGen .stream( oOutWriter, *true*);
>>>>*continue* ;
>>>>}
>>>>*if* ( sOutputMode.equalsIgnoreCase("jpg") )
>>>>{// jpg output
>>>>String sJpgPageSpec= GenericUtil./PathMake/(sDestPath, "page-"+ nPageNdx+".jpg");
>>>>File oFileJpg= *new* File(sJpgPageSpec);
>>>>BufferedImage image= oRender.renderImageWithDPI(nPageNdx, GenericUtil./parseInt/(sDpi, 300));
>>>>Â Â Â Â ImageIO./write/(image, "JPEG", oFileJpg);
>>>>continue;
>>>>}
>>>>}
>>>>
>>>>I've attached the input PDF file as well.
>>>>
>>>>Thoughts?
>>>>
>>>>Rich Stafford
>>>>Chief Scientist
>>>>eQuorum Corporation
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail:
>>>>users-unsubscribe@pdfbox.apache.org
>>>>For additional commands, e-mail:
>>>>users-help@pdfbox.apache.org
>>>
>>>

Re: PDFBox and Batik SVGGraphics2d

Posted by Thad Humphries <th...@gmail.com>.
FYI and in case this is a suitable workaround, when I
use org.apache.pdfbox.rendering.PDFRenderer to convert this page to a
java.awt.image.BufferedImage then use javax.imageio.ImageIO.write() to
write the BufferedImage to a PNG, the result shows the green lines.

On Fri, Jan 6, 2023 at 11:41 AM Tilman Hausherr <TH...@t-online.de>
wrote:

> Hi,
>
> I can confirm the effect with my own conversion code (which may or may
> not be the same). I looked at the SVG and there's one thing missing:
> PDFBox converts patterns to bitmaps and then uses TexturePaint. So there
> should be some binary content in the SVG but there isn't. Could it be
> that there is some option that should be set?
>
> Btw the PDF has some errors, like 0 255 0 sc  (or rg), this should be 0
> 1 0 sc (or rg). But this isn't the cause.
>
> Tilman
>
> On 06.01.2023 14:51, Rich Stafford wrote:
> > Tilman:
> >
> > Thanks for your quick response.  I've upgraded to PDFBox 2.0.27, with
> > the same results.
> >
> > The PDF file can be downloaded here:
> >
> > https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf
> >
> > <https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf>Thanks
> > for any assistance.  I'm going to start tracing thru Batik source code
> > for the SVG error.
> >
> > Rich Stafford
> > Chief Scientist
> > eQuorum Corporation
> > ***
> > At 01:28 PM 1/5/2023, Tilman Hausherr wrote:
> >> Hi,
> >>
> >> Please try with 2.0.27 and upload the PDF somewhere, it didn't get
> >> through.
> >>
> >> Tilman
> >>
> >> On 05.01.2023 16:28, Rich Stafford wrote:
> >>> I am having an issue using PDFBox (pdfbox-app-2.0.21.jar) and
> >>> SVGGraphics2d (batik-1ll-1.16.jar) to generate SVG output from a
> >>> small PDF file.
> >>>
> >>> This file has about 9 vector lines, and a rectangle filled with
> >>> horizontal lines.  Using the PDFBox PDFRenderer to JPG, I get the
> >>> appropriate fill for the rectangle:
> >>>
> >>> screen capture:
> >>> Emacs!
> >>>
> >>> However, using the PDFBox PDFRenderer with SVGGraphics2d, I get a
> >>> black filled rectangle.
> >>>
> >>> screen capture:
> >>> Emacs!
> >>>
> >>> The generator code fragment is as follows:
> >>>
> >>> // setup instance of org.w3c.dom.Document
> >>> DOMImplementation oDom=
> >>> GenericDOMImplementation./getDOMImplementation/();
> >>> String sSvgOrg= " http://www.w3.org/2000/svg";
> >>> Document oSvgDoc= oDom.createDocument(sSvgOrg, "svg", *null*);
> >>> SVGGeneratorContext oCtx= SVGGeneratorContext./createDefault/(oSvgDoc);
> >>> oCtx.setEmbeddedFontsOn(*true* );
> >>>
> >>> // setup renderer object
> >>> PDFRenderer oRender= *new* PDFRenderer( oDoc);
> >>>
> >>> // loop for all pages in the PDF
> >>> *for* ( *int* nPageNdx= 0; nPageNdx< oDoc.getNumberOfPages();
> >>> nPageNdx++ )
> >>> {
> >>> // setup output file
> >>> *if* ( sOutputMode.equalsIgnoreCase("svg") )
> >>> {// svg
> >>> String sSvgPageSpec= GenericUtil./PathMake/(sDestPath, "page-"+
> >>> nPageNdx+".svg");
> >>> ( *new* File( sSvgPageSpec)).createNewFile();
> >>> // setup instance of SVG Generator
> >>> SVGGraphics2D oSvgGen= *new* SVGGraphics2D( oCtx, *false*);
> >>> // render the page to SVG
> >>> oRender .renderPageToGraphics( nPageNdx, oSvgGen);
> >>> // write to file
> >>> OutputStream oOutStream= *new* FileOutputStream( *new*
> >>> File(sSvgPageSpec) );
> >>> Writer oOutWriter= *new* OutputStreamWriter( oOutStream, "UTF-8");
> >>> oSvgGen .stream( oOutWriter, *true*);
> >>> *continue* ;
> >>> }
> >>> *if* ( sOutputMode.equalsIgnoreCase("jpg") )
> >>> {// jpg output
> >>> String sJpgPageSpec= GenericUtil./PathMake/(sDestPath, "page-"+
> >>> nPageNdx+".jpg");
> >>> File oFileJpg= *new* File(sJpgPageSpec);
> >>> BufferedImage image= oRender.renderImageWithDPI(nPageNdx,
> >>> GenericUtil./parseInt/(sDpi, 300));
> >>> Â Â Â Â ImageIO./write/(image, "JPEG", oFileJpg);
> >>> continue;
> >>> }
> >>> }
> >>>
> >>> I've attached the input PDF file as well.
> >>>
> >>> Thoughts?
> >>>
> >>> Rich Stafford
> >>> Chief Scientist
> >>> eQuorum Corporation
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> 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. 111-13)

Re: PDFBox and Batik SVGGraphics2d

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

I can confirm the effect with my own conversion code (which may or may 
not be the same). I looked at the SVG and there's one thing missing: 
PDFBox converts patterns to bitmaps and then uses TexturePaint. So there 
should be some binary content in the SVG but there isn't. Could it be 
that there is some option that should be set?

Btw the PDF has some errors, like 0 255 0 sc  (or rg), this should be 0 
1 0 sc (or rg). But this isn't the cause.

Tilman

On 06.01.2023 14:51, Rich Stafford wrote:
> Tilman:
>
> Thanks for your quick response.  I've upgraded to PDFBox 2.0.27, with 
> the same results.
>
> The PDF file can be downloaded here:
>
> https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf
>
> <https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf>Thanks 
> for any assistance.  I'm going to start tracing thru Batik source code 
> for the SVG error.
>
> Rich Stafford
> Chief Scientist
> eQuorum Corporation
> ***
> At 01:28 PM 1/5/2023, Tilman Hausherr wrote:
>> Hi,
>>
>> Please try with 2.0.27 and upload the PDF somewhere, it didn't get 
>> through.
>>
>> Tilman
>>
>> On 05.01.2023 16:28, Rich Stafford wrote:
>>> I am having an issue using PDFBox (pdfbox-app-2.0.21.jar) and 
>>> SVGGraphics2d (batik-1ll-1.16.jar) to generate SVG output from a 
>>> small PDF file.
>>>
>>> This file has about 9 vector lines, and a rectangle filled with 
>>> horizontal lines.  Using the PDFBox PDFRenderer to JPG, I get the 
>>> appropriate fill for the rectangle:
>>>
>>> screen capture:
>>> Emacs!
>>>
>>> However, using the PDFBox PDFRenderer with SVGGraphics2d, I get a 
>>> black filled rectangle.
>>>
>>> screen capture:
>>> Emacs!
>>>
>>> The generator code fragment is as follows:
>>>
>>> // setup instance of org.w3c.dom.Document
>>> DOMImplementation oDom= 
>>> GenericDOMImplementation./getDOMImplementation/();
>>> String sSvgOrg= " http://www.w3.org/2000/svg";
>>> Document oSvgDoc= oDom.createDocument(sSvgOrg, "svg", *null*);
>>> SVGGeneratorContext oCtx= SVGGeneratorContext./createDefault/(oSvgDoc);
>>> oCtx.setEmbeddedFontsOn(*true* );
>>>
>>> // setup renderer object
>>> PDFRenderer oRender= *new* PDFRenderer( oDoc);
>>>
>>> // loop for all pages in the PDF
>>> *for* ( *int* nPageNdx= 0; nPageNdx< oDoc.getNumberOfPages(); 
>>> nPageNdx++ )
>>> {
>>> // setup output file
>>> *if* ( sOutputMode.equalsIgnoreCase("svg") )
>>> {// svg
>>> String sSvgPageSpec= GenericUtil./PathMake/(sDestPath, "page-"+ 
>>> nPageNdx+".svg");
>>> ( *new* File( sSvgPageSpec)).createNewFile();
>>> // setup instance of SVG Generator
>>> SVGGraphics2D oSvgGen= *new* SVGGraphics2D( oCtx, *false*);
>>> // render the page to SVG
>>> oRender .renderPageToGraphics( nPageNdx, oSvgGen);
>>> // write to file
>>> OutputStream oOutStream= *new* FileOutputStream( *new* 
>>> File(sSvgPageSpec) );
>>> Writer oOutWriter= *new* OutputStreamWriter( oOutStream, "UTF-8");
>>> oSvgGen .stream( oOutWriter, *true*);
>>> *continue* ;
>>> }
>>> *if* ( sOutputMode.equalsIgnoreCase("jpg") )
>>> {// jpg output
>>> String sJpgPageSpec= GenericUtil./PathMake/(sDestPath, "page-"+ 
>>> nPageNdx+".jpg");
>>> File oFileJpg= *new* File(sJpgPageSpec);
>>> BufferedImage image= oRender.renderImageWithDPI(nPageNdx, 
>>> GenericUtil./parseInt/(sDpi, 300));
>>> Â Â Â Â ImageIO./write/(image, "JPEG", oFileJpg);
>>> continue;
>>> }
>>> }
>>>
>>> I've attached the input PDF file as well.
>>>
>>> Thoughts?
>>>
>>> Rich Stafford
>>> Chief Scientist
>>> eQuorum Corporation
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>>> users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail:
>>> users-help@pdfbox.apache.org
>>
>>
>>

Re: PDFBox and Batik SVGGraphics2d

Posted by Rich Stafford <ri...@equorum.com>.
Tilman:

Thanks for your quick response.  I've upgraded to PDFBox 2.0.27, with the same results.

The PDF file can be downloaded here:

https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf

Thanks for any assistance.  I'm going to start tracing thru Batik source code for the SVG error.

Rich Stafford
Chief Scientist
eQuorum Corporation
***
At 01:28 PM 1/5/2023, Tilman Hausherr wrote:
>Hi,
>
>Please try with 2.0.27 and upload the PDF somewhere, it didn't get through.
>
>Tilman
>
>On 05.01.2023 16:28, Rich Stafford wrote:
>>I am having an issue using PDFBox (pdfbox-app-2.0.21.jar) and SVGGraphics2d (batik-1ll-1.16.jar) to generate SVG output from a small PDF file.
>>
>>This file has about 9 vector lines, and a rectangle filled with horizontal lines.  Using the PDFBox PDFRenderer to JPG, I get the appropriate fill for the rectangle:
>>
>>screen capture:
>>Emacs!
>>
>>
>>However, using the PDFBox PDFRenderer with SVGGraphics2d, I get a black filled rectangle.
>>
>>screen capture:
>>Emacs!
>>
>>
>>The generator code fragment is as follows:
>>
>>// setup instance of org.w3c.dom.Document
>>DOMImplementation oDom = GenericDOMImplementation.getDOMImplementation();
>>String sSvgOrg = " http://www.w3.org/2000/svg" ;
>>Document oSvgDoc = oDom .createDocument( sSvgOrg , "svg", null);
>>SVGGeneratorContext oCtx = SVGGeneratorContext.createDefault( oSvgDoc );
>>oCtx .setEmbeddedFontsOn( true );
>>
>>// setup renderer object
>>PDFRenderer oRender = new PDFRenderer( oDoc );
>>
>>// loop for all pages in the PDF
>>for ( int nPageNdx = 0; nPageNdx < oDoc.getNumberOfPages(); nPageNdx++ )
>>{
>>        // setup output file
>>        if ( sOutputMode .equalsIgnoreCase( "svg") )
>>        {       // svg
>>                String sSvgPageSpec = GenericUtil.PathMake( sDestPath , "page-"+ nPageNdx + ".svg");
>>                ( new File( sSvgPageSpec )).createNewFile();
>>                // setup instance of SVG Generator
>>                SVGGraphics2D oSvgGen = new SVGGraphics2D( oCtx, false );
>>                // render the page to SVG
>>                oRender .renderPageToGraphics( nPageNdx, oSvgGen );
>>                // write to file
>>                OutputStream oOutStream = new FileOutputStream( new File( sSvgPageSpec) );
>>                Writer oOutWriter = new OutputStreamWriter( oOutStream, "UTF-8" );
>>                oSvgGen .stream( oOutWriter, true );
>>                continue ;
>>        }
>>        if ( sOutputMode .equalsIgnoreCase( "jpg") )
>>        {       // jpg output
>>                String sJpgPageSpec = GenericUtil.PathMake( sDestPath , "page-"+ nPageNdx + ".jpg");
>>                File oFileJpg = new File( sJpgPageSpec);
>>                BufferedImage image = oRender .renderImageWithDPI( nPageNdx , GenericUtil.parseInt( sDpi , 300));
>>Â Â Â Â                 ImageIO. write( image, "JPEG", oFileJpg);
>>                continue;
>>        }
>>}
>>
>>I've attached the input PDF file as well.
>>
>>Thoughts?
>>
>>Rich Stafford
>>Chief Scientist
>>eQuorum Corporation
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: <ma...@pdfbox.apache.org>users-unsubscribe@pdfbox.apache.org
>>For additional commands, e-mail: <ma...@pdfbox.apache.org>users-help@pdfbox.apache.org
>
>
>

Re: PDFBox and Batik SVGGraphics2d

Posted by Rich Stafford <ri...@equorum.com>.
Tilman:

Thanks for your quick response.  I've upgraded to PDFBox 2.0.27, with the same results.

The PDF file can be downloaded here:

https://s3.amazonaws.com/webdl.equorum.com/misc/size2013.pdf

Thanks for any assistance.  I'm going to start tracing thru Batik source code for the SVG error.

Rich Stafford
Chief Scientist
eQuorum Corporation
***
At 01:28 PM 1/5/2023, Tilman Hausherr wrote:
>Hi,
>
>Please try with 2.0.27 and upload the PDF somewhere, it didn't get through.
>
>Tilman
>
>On 05.01.2023 16:28, Rich Stafford wrote:
>>I am having an issue using PDFBox (pdfbox-app-2.0.21.jar) and SVGGraphics2d (batik-1ll-1.16.jar) to generate SVG output from a small PDF file.
>>
>>This file has about 9 vector lines, and a rectangle filled with horizontal lines.  Using the PDFBox PDFRenderer to JPG, I get the appropriate fill for the rectangle:
>>
>>screen capture:
>>Emacs!
>>
>>
>>However, using the PDFBox PDFRenderer with SVGGraphics2d, I get a black filled rectangle.
>>
>>screen capture:
>>Emacs!
>>
>>
>>The generator code fragment is as follows:
>>
>>// setup instance of org.w3c.dom.Document
>>DOMImplementation oDom = GenericDOMImplementation.getDOMImplementation();
>>String sSvgOrg = " http://www.w3.org/2000/svg" ;
>>Document oSvgDoc = oDom .createDocument( sSvgOrg , "svg", null);
>>SVGGeneratorContext oCtx = SVGGeneratorContext.createDefault( oSvgDoc );
>>oCtx .setEmbeddedFontsOn( true );
>>
>>// setup renderer object
>>PDFRenderer oRender = new PDFRenderer( oDoc );
>>
>>// loop for all pages in the PDF
>>for ( int nPageNdx = 0; nPageNdx < oDoc.getNumberOfPages(); nPageNdx++ )
>>{
>>        // setup output file
>>        if ( sOutputMode .equalsIgnoreCase( "svg") )
>>        {       // svg
>>                String sSvgPageSpec = GenericUtil.PathMake( sDestPath , "page-"+ nPageNdx + ".svg");
>>                ( new File( sSvgPageSpec )).createNewFile();
>>                // setup instance of SVG Generator
>>                SVGGraphics2D oSvgGen = new SVGGraphics2D( oCtx, false );
>>                // render the page to SVG
>>                oRender .renderPageToGraphics( nPageNdx, oSvgGen );
>>                // write to file
>>                OutputStream oOutStream = new FileOutputStream( new File( sSvgPageSpec) );
>>                Writer oOutWriter = new OutputStreamWriter( oOutStream, "UTF-8" );
>>                oSvgGen .stream( oOutWriter, true );
>>                continue ;
>>        }
>>        if ( sOutputMode .equalsIgnoreCase( "jpg") )
>>        {       // jpg output
>>                String sJpgPageSpec = GenericUtil.PathMake( sDestPath , "page-"+ nPageNdx + ".jpg");
>>                File oFileJpg = new File( sJpgPageSpec);
>>                BufferedImage image = oRender .renderImageWithDPI( nPageNdx , GenericUtil.parseInt( sDpi , 300));
>>Â Â Â Â                 ImageIO. write( image, "JPEG", oFileJpg);
>>                continue;
>>        }
>>}
>>
>>I've attached the input PDF file as well.
>>
>>Thoughts?
>>
>>Rich Stafford
>>Chief Scientist
>>eQuorum Corporation
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: <ma...@pdfbox.apache.org>users-unsubscribe@pdfbox.apache.org
>>For additional commands, e-mail: <ma...@pdfbox.apache.org>users-help@pdfbox.apache.org
>
>
>

Re: PDFBox and Batik SVGGraphics2d

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

Please try with 2.0.27 and upload the PDF somewhere, it didn't get through.

Tilman

On 05.01.2023 16:28, Rich Stafford wrote:
> I am having an issue using PDFBox (pdfbox-app-2.0.21.jar) and 
> SVGGraphics2d (batik-1ll-1.16.jar) to generate SVG output from a small 
> PDF file.
>
> This file has about 9 vector lines, and a rectangle filled with 
> horizontal lines.  Using the PDFBox PDFRenderer to JPG, I get the 
> appropriate fill for the rectangle:
>
> screen capture:
> Emacs!
>
> However, using the PDFBox PDFRenderer with SVGGraphics2d, I get a 
> black filled rectangle.
>
> screen capture:
> Emacs!
>
> The generator code fragment is as follows:
>
> // setup instance of org.w3c.dom.Document
> DOMImplementation oDom= GenericDOMImplementation./getDOMImplementation/();
> String sSvgOrg= "http://www.w3.org/2000/svg" ;
> Document oSvgDoc= oDom.createDocument( sSvgOrg , "svg", *null*);
> SVGGeneratorContext oCtx= SVGGeneratorContext./createDefault/( oSvgDoc );
> oCtx.setEmbeddedFontsOn( *true* );
>
> // setup renderer object
> PDFRenderer oRender= *new* PDFRenderer( oDoc);
>
> // loop for all pages in the PDF
> *for* ( *int* nPageNdx= 0; nPageNdx< oDoc.getNumberOfPages(); nPageNdx++ )
> {
> // setup output file
> *if* ( sOutputMode.equalsIgnoreCase( "svg") )
> {// svg
> String sSvgPageSpec= GenericUtil./PathMake/( sDestPath , "page-"+ 
> nPageNdx + ".svg");
> ( *new* File(sSvgPageSpec)).createNewFile();
> // setup instance of SVG Generator
> SVGGraphics2D oSvgGen= *new* SVGGraphics2D( oCtx, *false*);
> // render the page to SVG
> oRender .renderPageToGraphics( nPageNdx, oSvgGen);
> // write to file
> OutputStream oOutStream= *new* FileOutputStream( *new* 
> File(sSvgPageSpec) );
> Writer oOutWriter= *new* OutputStreamWriter( oOutStream, "UTF-8");
> oSvgGen .stream( oOutWriter, *true*);
> *continue* ;
> }
> *if* ( sOutputMode.equalsIgnoreCase( "jpg") )
> {// jpg output
> String sJpgPageSpec= GenericUtil./PathMake/( sDestPath , "page-"+ 
> nPageNdx + ".jpg");
> File oFileJpg= *new* File(sJpgPageSpec);
> BufferedImage image= oRender.renderImageWithDPI( nPageNdx , 
> GenericUtil./parseInt/( sDpi , 300));
> ImageIO./write/(image, "JPEG", oFileJpg);
> continue;
> }
> }
>
> I've attached the input PDF file as well.
>
> Thoughts?
>
> Rich Stafford
> Chief Scientist
> eQuorum Corporation
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail:users-help@pdfbox.apache.org