[jira] [Updated] (PDFBOX-3539) Close Document after printing

2016-10-21 Thread Ivan Ridao Freitas (JIRA)

 [ 
https://issues.apache.org/jira/browse/PDFBOX-3539?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ivan Ridao Freitas updated PDFBOX-3539:
---
Description: 
In the example class: {code}org.apache.pdfbox.examples.printing.Printing{code}

{{PDDocument}} is not closed after {{job.print();}}

  was:
Example class: {code}org.apache.pdfbox.examples.printing.Printing{code}

{{PDDocument}} is not closed after {{job.print();}}


> Close Document after printing
> -
>
> Key: PDFBOX-3539
> URL: https://issues.apache.org/jira/browse/PDFBOX-3539
> Project: PDFBox
>  Issue Type: Test
>Affects Versions: 2.0.3
>Reporter: Ivan Ridao Freitas
>Priority: Minor
>
> In the example class: {code}org.apache.pdfbox.examples.printing.Printing{code}
> {{PDDocument}} is not closed after {{job.print();}}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

-
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org



[jira] [Updated] (PDFBOX-3539) Close Document after printing

2016-10-21 Thread Ivan Ridao Freitas (JIRA)

 [ 
https://issues.apache.org/jira/browse/PDFBOX-3539?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ivan Ridao Freitas updated PDFBOX-3539:
---
Description: 
Example class: {code}org.apache.pdfbox.examples.printing.Printing{code}

{{PDDocument}} is not closed after {{job.print();}}

  was:
Example class: {code}org.apache.pdfbox.examples.printing.Printing{code}

{PDDocument} is not closed after {job.print();}


> Close Document after printing
> -
>
> Key: PDFBOX-3539
> URL: https://issues.apache.org/jira/browse/PDFBOX-3539
> Project: PDFBox
>  Issue Type: Test
>Affects Versions: 2.0.3
>Reporter: Ivan Ridao Freitas
>Priority: Minor
>
> Example class: {code}org.apache.pdfbox.examples.printing.Printing{code}
> {{PDDocument}} is not closed after {{job.print();}}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

-
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org



[jira] [Created] (PDFBOX-3539) Close Document after printing

2016-10-21 Thread Ivan Ridao Freitas (JIRA)
Ivan Ridao Freitas created PDFBOX-3539:
--

 Summary: Close Document after printing
 Key: PDFBOX-3539
 URL: https://issues.apache.org/jira/browse/PDFBOX-3539
 Project: PDFBox
  Issue Type: Test
Affects Versions: 2.0.3
Reporter: Ivan Ridao Freitas
Priority: Minor


Example class: {code}org.apache.pdfbox.examples.printing.Printing{code}

{PDDocument} is not closed after {job.print();}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

-
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org



[jira] [Commented] (PDFBOX-3359) Drawing to Graphics2D / ScratchFileBuffer not closed

2016-05-26 Thread Ivan Ridao Freitas (JIRA)

[ 
https://issues.apache.org/jira/browse/PDFBOX-3359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15302981#comment-15302981
 ] 

Ivan Ridao Freitas commented on PDFBOX-3359:


I end up using this code to simulate a PDF preview with the current version 
(2.0.1):
{code}
@Override
public void paintComponent(Graphics g) {
Graphics2D graphics = (Graphics2D) g.create();
bufferedImage = new BufferedImage(scaledWidth, scaledHeight, 
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = bufferedImage.createGraphics();
g2.addRenderingHints(hints);
g2.setColor(Color.WHITE);
g2.fillRect(0, 0, scaledWidth, scaledHeight);
g2.scale(scaleX, scaleY);
g2.clip(imageableArea);
try {
g2.setBackground(Color.WHITE);
// Margins
g2.translate(imageableArea.getX(), 
imageableArea.getY());
renderer.renderPageToGraphics(pageNumber, graphics);
} catch(Exception e) {
e.printStackTrace();
}
g2.dispose();
graphics.drawImage(bufferedImage, null, 0, 0);
graphics.dispose();
}
{code}

I make the scaling before PDFBox rendering. I had to set 
g2.setBackground(Color.WHITE); since the background is black by default (I 
don't know if that is the expected behaviour for PDFBox). I also use a cache 
and only re generate bufferedImage if the scale was changed, but I removed that 
from the example code.

> Drawing to Graphics2D / ScratchFileBuffer not closed
> 
>
> Key: PDFBOX-3359
> URL: https://issues.apache.org/jira/browse/PDFBOX-3359
> Project: PDFBox
>  Issue Type: Bug
>  Components: Rendering
>Affects Versions: 2.0.1
>Reporter: Ivan Ridao Freitas
>
> First, there is a little bug on PDFRenderer.renderPageToGraphics(int 
> pageIndex, Graphics2D graphics, float scale) when using scale != 1 the call 
> to clearRect() fills the original size with white background, but it should 
> fill the scaled size.
> Second, I implemented a JPanel which is painted using that function and on 
> every paint this message goes to the console:
> "DEBUG ScratchFileBuffer:516 - ScratchFileBuffer not closed!". Here is the 
> code to test it, run it and *resize the JFrame*:
> {code:title=PanelTest.java|borderStyle=solid}
> import java.awt.Dimension;
> import java.awt.Graphics;
> import java.awt.Graphics2D;
> import java.io.File;
> import java.io.IOException;
> import javax.swing.JFrame;
> import javax.swing.JPanel;
> import javax.swing.SwingUtilities;
> import javax.swing.WindowConstants;
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.rendering.PDFRenderer;
> public class PanelTest {
>
> private static JPanel getTestPanel() {
> PDDocument doc = null;
> try {
> doc = PDDocument.load(new File("anyfile.pdf"));
> } catch (IOException e) {
> e.printStackTrace();
> }
> final PDFRenderer renderer = new PDFRenderer(doc);
> JPanel panel = new JPanel() {
> @Override
> protected void paintComponent(Graphics g) {
> try {
> renderer.renderPageToGraphics(0, (Graphics2D) g, 0.5f);
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> };
> return panel;
> }
> public static void main(String[] args) throws Exception {
> SwingUtilities.invokeLater(new Runnable() {
> @Override
> public void run() {
> JFrame frame = new JFrame();
> frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
> frame.add(getTestPanel());
> frame.pack();
> frame.setSize(600, 400);
> Dimension paneSize = frame.getSize();
> Dimension screenSize = frame.getToolkit().getScreenSize();
> frame.setLocation((screenSize.width - paneSize.width) / 2, 
> (screenSize.height - paneSize.height) / 2);
> frame.setTitle("Test");
> frame.setVisible(true);
> }
> });
> }
> }
> {code}
> Ivan 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

-
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org



[jira] [Comment Edited] (PDFBOX-3359) Drawing to Graphics2D

2016-05-21 Thread Ivan Ridao Freitas (JIRA)

[ 
https://issues.apache.org/jira/browse/PDFBOX-3359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15295227#comment-15295227
 ] 

Ivan Ridao Freitas edited comment on PDFBOX-3359 at 5/21/16 7:37 PM:
-

Yes, I tested and switching those lines fixes that first bug.

What about the debug messages?


was (Author: ivanrf):
Yes, I tested and switching those links fixes that first bug.

What about the debug messages?

> Drawing to Graphics2D
> -
>
> Key: PDFBOX-3359
> URL: https://issues.apache.org/jira/browse/PDFBOX-3359
> Project: PDFBox
>  Issue Type: Bug
>Affects Versions: 2.0.1
>Reporter: Ivan Ridao Freitas
>
> First, there is a little bug on PDFRenderer.renderPageToGraphics(int 
> pageIndex, Graphics2D graphics, float scale) when using scale != 1 the call 
> to clearRect() fills the original size with white background, but it should 
> fill the scaled size.
> Second, I implemented a JPanel which is painted using that function and on 
> every paint this message goes to the console:
> "DEBUG ScratchFileBuffer:516 - ScratchFileBuffer not closed!". Here is the 
> code to test it, run it and *resize the JFrame*:
> {code:title=PanelTest.java|borderStyle=solid}
> import java.awt.Dimension;
> import java.awt.Graphics;
> import java.awt.Graphics2D;
> import java.io.File;
> import java.io.IOException;
> import javax.swing.JFrame;
> import javax.swing.JPanel;
> import javax.swing.SwingUtilities;
> import javax.swing.WindowConstants;
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.rendering.PDFRenderer;
> public class PanelTest {
>
> private static JPanel getTestPanel() {
> PDDocument doc = null;
> try {
> doc = PDDocument.load(new File("anyfile.pdf"));
> } catch (IOException e) {
> e.printStackTrace();
> }
> final PDFRenderer renderer = new PDFRenderer(doc);
> JPanel panel = new JPanel() {
> @Override
> protected void paintComponent(Graphics g) {
> try {
> renderer.renderPageToGraphics(0, (Graphics2D) g, 0.5f);
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> };
> return panel;
> }
> public static void main(String[] args) throws Exception {
> SwingUtilities.invokeLater(new Runnable() {
> @Override
> public void run() {
> JFrame frame = new JFrame();
> frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
> frame.add(getTestPanel());
> frame.pack();
> frame.setSize(600, 400);
> Dimension paneSize = frame.getSize();
> Dimension screenSize = frame.getToolkit().getScreenSize();
> frame.setLocation((screenSize.width - paneSize.width) / 2, 
> (screenSize.height - paneSize.height) / 2);
> frame.setTitle("Test");
> frame.setVisible(true);
> }
> });
> }
> }
> {code}
> Ivan 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

-
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org



[jira] [Commented] (PDFBOX-3359) Drawing to Graphics2D

2016-05-21 Thread Ivan Ridao Freitas (JIRA)

[ 
https://issues.apache.org/jira/browse/PDFBOX-3359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15295227#comment-15295227
 ] 

Ivan Ridao Freitas commented on PDFBOX-3359:


Yes, I tested and switching those links fixes that first bug.

What about the debug messages?

> Drawing to Graphics2D
> -
>
> Key: PDFBOX-3359
> URL: https://issues.apache.org/jira/browse/PDFBOX-3359
> Project: PDFBox
>  Issue Type: Bug
>Affects Versions: 2.0.1
>Reporter: Ivan Ridao Freitas
>
> First, there is a little bug on PDFRenderer.renderPageToGraphics(int 
> pageIndex, Graphics2D graphics, float scale) when using scale != 1 the call 
> to clearRect() fills the original size with white background, but it should 
> fill the scaled size.
> Second, I implemented a JPanel which is painted using that function and on 
> every paint this message goes to the console:
> "DEBUG ScratchFileBuffer:516 - ScratchFileBuffer not closed!". Here is the 
> code to test it, run it and *resize the JFrame*:
> {code:title=PanelTest.java|borderStyle=solid}
> import java.awt.Dimension;
> import java.awt.Graphics;
> import java.awt.Graphics2D;
> import java.io.File;
> import java.io.IOException;
> import javax.swing.JFrame;
> import javax.swing.JPanel;
> import javax.swing.SwingUtilities;
> import javax.swing.WindowConstants;
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.rendering.PDFRenderer;
> public class PanelTest {
>
> private static JPanel getTestPanel() {
> PDDocument doc = null;
> try {
> doc = PDDocument.load(new File("anyfile.pdf"));
> } catch (IOException e) {
> e.printStackTrace();
> }
> final PDFRenderer renderer = new PDFRenderer(doc);
> JPanel panel = new JPanel() {
> @Override
> protected void paintComponent(Graphics g) {
> try {
> renderer.renderPageToGraphics(0, (Graphics2D) g, 0.5f);
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> };
> return panel;
> }
> public static void main(String[] args) throws Exception {
> SwingUtilities.invokeLater(new Runnable() {
> @Override
> public void run() {
> JFrame frame = new JFrame();
> frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
> frame.add(getTestPanel());
> frame.pack();
> frame.setSize(600, 400);
> Dimension paneSize = frame.getSize();
> Dimension screenSize = frame.getToolkit().getScreenSize();
> frame.setLocation((screenSize.width - paneSize.width) / 2, 
> (screenSize.height - paneSize.height) / 2);
> frame.setTitle("Test");
> frame.setVisible(true);
> }
> });
> }
> }
> {code}
> Ivan 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

-
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org



[jira] [Updated] (PDFBOX-3359) Drawing to Graphics2D

2016-05-21 Thread Ivan Ridao Freitas (JIRA)

 [ 
https://issues.apache.org/jira/browse/PDFBOX-3359?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ivan Ridao Freitas updated PDFBOX-3359:
---
Description: 
First, there is a little bug on PDFRenderer.renderPageToGraphics(int pageIndex, 
Graphics2D graphics, float scale) when using scale != 1 the call to clearRect() 
fills the original size with white background, but it should fill the scaled 
size.

Second, I implemented a JPanel which is painted using that function and on 
every paint this message goes to the console:
"DEBUG ScratchFileBuffer:516 - ScratchFileBuffer not closed!". Here is the code 
to test it, run it and *resize the JFrame*:

{code:title=PanelTest.java|borderStyle=solid}
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.File;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;

public class PanelTest {
   
private static JPanel getTestPanel() {
PDDocument doc = null;
try {
doc = PDDocument.load(new File("anyfile.pdf"));
} catch (IOException e) {
e.printStackTrace();
}
final PDFRenderer renderer = new PDFRenderer(doc);
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
try {
renderer.renderPageToGraphics(0, (Graphics2D) g, 0.5f);
} catch (IOException e) {
e.printStackTrace();
}
}
};
return panel;
}

public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(getTestPanel());
frame.pack();
frame.setSize(600, 400);
Dimension paneSize = frame.getSize();
Dimension screenSize = frame.getToolkit().getScreenSize();
frame.setLocation((screenSize.width - paneSize.width) / 2, 
(screenSize.height - paneSize.height) / 2);
frame.setTitle("Test");
frame.setVisible(true);
}
});
}
}
{code}

Ivan 

  was:
First, there is a little bug on PDFRenderer.renderPageToGraphics(int pageIndex, 
Graphics2D graphics, float scale) when using scale != 1 the call to clearRect() 
fills the original size with white background, but it should fill the scaled 
size.

Second, I implemented a JPanel which is painted using that function and on 
every paint this message goes to the console:
"DEBUG ScratchFileBuffer:516 - ScratchFileBuffer not closed!". Here is the code 
to test it, run it and **resize the JFrame**:

{code:title=PanelTest.java|borderStyle=solid}
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.File;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;

public class PanelTest {
   
private static JPanel getTestPanel() {
PDDocument doc = null;
try {
doc = PDDocument.load(new File("anyfile.pdf"));
} catch (IOException e) {
e.printStackTrace();
}
final PDFRenderer renderer = new PDFRenderer(doc);
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
try {
renderer.renderPageToGraphics(0, (Graphics2D) g, 0.5f);
} catch (IOException e) {
e.printStackTrace();
}
}
};
return panel;
}

public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(getTestPanel());
frame.pack();
frame.setSize(600, 400);
Dimension paneSize = frame.getSize();
Dimension screenSize = frame.getToolkit().getScreenSize();
frame.setLocation((screenSize.width - paneSize.width) / 2, 
(screenSize.height - paneSize.height) / 2);
frame.setTitle("Test");
frame.setVisible(true);
}
});
}
}
{code}

Ivan 


> Drawing to Graphics2D
> 

[jira] [Updated] (PDFBOX-3359) Drawing to Graphics2D

2016-05-21 Thread Ivan Ridao Freitas (JIRA)

 [ 
https://issues.apache.org/jira/browse/PDFBOX-3359?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ivan Ridao Freitas updated PDFBOX-3359:
---
Description: 
First, there is a little bug on PDFRenderer.renderPageToGraphics(int pageIndex, 
Graphics2D graphics, float scale) when using scale != 1 the call to clearRect() 
fills the original size with white background, but it should fill the scaled 
size.

Second, I implemented a JPanel which is painted using that function and on 
every paint this message goes to the console:
"DEBUG ScratchFileBuffer:516 - ScratchFileBuffer not closed!". Here is the code 
to test it, run it and **resize the JFrame**:

{code:title=PanelTest.java|borderStyle=solid}
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.File;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;

public class PanelTest {
   
private static JPanel getTestPanel() {
PDDocument doc = null;
try {
doc = PDDocument.load(new File("anyfile.pdf"));
} catch (IOException e) {
e.printStackTrace();
}
final PDFRenderer renderer = new PDFRenderer(doc);
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
try {
renderer.renderPageToGraphics(0, (Graphics2D) g, 0.5f);
} catch (IOException e) {
e.printStackTrace();
}
}
};
return panel;
}

public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(getTestPanel());
frame.pack();
frame.setSize(600, 400);
Dimension paneSize = frame.getSize();
Dimension screenSize = frame.getToolkit().getScreenSize();
frame.setLocation((screenSize.width - paneSize.width) / 2, 
(screenSize.height - paneSize.height) / 2);
frame.setTitle("Test");
frame.setVisible(true);
}
});
}
}
{code}

Ivan 

  was:
First, there is a little bug on PDFRenderer.renderPageToGraphics(int pageIndex, 
Graphics2D graphics, float scale) when using scale != 1 the call to clearRect() 
fills the original size with white background, but it should fill the scaled 
size.

Second, I implemented a JPanel which is painted using that function and on 
every paint this message goes to the console:
"DEBUG ScratchFileBuffer:516 - ScratchFileBuffer not closed!". Here is the code 
to test it, run it and resize the JFrame:

{code:title=PanelTest.java|borderStyle=solid}
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.File;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;

public class PanelTest {
   
private static JPanel getTestPanel() {
PDDocument doc = null;
try {
doc = PDDocument.load(new File("anyfile.pdf"));
} catch (IOException e) {
e.printStackTrace();
}
final PDFRenderer renderer = new PDFRenderer(doc);
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
try {
renderer.renderPageToGraphics(0, (Graphics2D) g, 0.5f);
} catch (IOException e) {
e.printStackTrace();
}
}
};
return panel;
}

public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(getTestPanel());
frame.pack();
frame.setSize(600, 400);
Dimension paneSize = frame.getSize();
Dimension screenSize = frame.getToolkit().getScreenSize();
frame.setLocation((screenSize.width - paneSize.width) / 2, 
(screenSize.height - paneSize.height) / 2);
frame.setTitle("Test");
frame.setVisible(true);
}
});
}
}
{code}

Ivan 


> Drawing to Graphics2D
> -

[jira] [Updated] (PDFBOX-3359) Drawing to Graphics2D

2016-05-21 Thread Ivan Ridao Freitas (JIRA)

 [ 
https://issues.apache.org/jira/browse/PDFBOX-3359?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ivan Ridao Freitas updated PDFBOX-3359:
---
Description: 
First, there is a little bug on PDFRenderer.renderPageToGraphics(int pageIndex, 
Graphics2D graphics, float scale) when using scale != 1 the call to clearRect() 
fills the original size with white background, but it should fill the scaled 
size.

Second, I implemented a JPanel which is painted using that function and on 
every paint this message goes to the console:
"DEBUG ScratchFileBuffer:516 - ScratchFileBuffer not closed!". Here is the code 
to test it, run it and resize the JFrame:

{code:title=PanelTest.java|borderStyle=solid}
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.File;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;

public class PanelTest {
   
private static JPanel getTestPanel() {
PDDocument doc = null;
try {
doc = PDDocument.load(new File("anyfile.pdf"));
} catch (IOException e) {
e.printStackTrace();
}
final PDFRenderer renderer = new PDFRenderer(doc);
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
try {
renderer.renderPageToGraphics(0, (Graphics2D) g, 0.5f);
} catch (IOException e) {
e.printStackTrace();
}
}
};
return panel;
}

public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(getTestPanel());
frame.pack();
frame.setSize(600, 400);
Dimension paneSize = frame.getSize();
Dimension screenSize = frame.getToolkit().getScreenSize();
frame.setLocation((screenSize.width - paneSize.width) / 2, 
(screenSize.height - paneSize.height) / 2);
frame.setTitle("Test");
frame.setVisible(true);
}
});
}
}
{code}

Ivan 

  was:
First, there is a little bug on PDFRenderer.renderPageToGraphics(int pageIndex, 
Graphics2D graphics, float scale) when using scale != 1 the call to clearRect() 
fill the original size with white background, but it should fill the scaled 
size.

Second, I implemented a JPanel which is painted using that function and on 
every paint this message goes to the console:
"DEBUG ScratchFileBuffer:516 - ScratchFileBuffer not closed!". Here is the code 
to test it, run it and resize the JFrame:

{code:title=PanelTest.java|borderStyle=solid}
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.File;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;

public class PanelTest {
   
private static JPanel getTestPanel() {
PDDocument doc = null;
try {
doc = PDDocument.load(new File("anyfile.pdf"));
} catch (IOException e) {
e.printStackTrace();
}
final PDFRenderer renderer = new PDFRenderer(doc);
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
try {
renderer.renderPageToGraphics(0, (Graphics2D) g, 0.5f);
} catch (IOException e) {
e.printStackTrace();
}
}
};
return panel;
}

public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(getTestPanel());
frame.pack();
frame.setSize(600, 400);
Dimension paneSize = frame.getSize();
Dimension screenSize = frame.getToolkit().getScreenSize();
frame.setLocation((screenSize.width - paneSize.width) / 2, 
(screenSize.height - paneSize.height) / 2);
frame.setTitle("Test");
frame.setVisible(true);
}
});
}
}
{code}

Ivan 


> Drawing to Graphics2D
> -
>
>  

[jira] [Created] (PDFBOX-3359) Drawing to Graphics2D

2016-05-21 Thread Ivan Ridao Freitas (JIRA)
Ivan Ridao Freitas created PDFBOX-3359:
--

 Summary: Drawing to Graphics2D
 Key: PDFBOX-3359
 URL: https://issues.apache.org/jira/browse/PDFBOX-3359
 Project: PDFBox
  Issue Type: Bug
Affects Versions: 2.0.1
Reporter: Ivan Ridao Freitas


First, there is a little bug on PDFRenderer.renderPageToGraphics(int pageIndex, 
Graphics2D graphics, float scale) when using scale != 1 the call to clearRect() 
fill the original size with white background, but it should fill the scaled 
size.

Second, I implemented a JPanel which is painted using that function and on 
every paint this message goes to the console:
"DEBUG ScratchFileBuffer:516 - ScratchFileBuffer not closed!". Here is the code 
to test it, run it and resize the JFrame:

{code:title=PanelTest.java|borderStyle=solid}
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.File;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;

public class PanelTest {
   
private static JPanel getTestPanel() {
PDDocument doc = null;
try {
doc = PDDocument.load(new File("anyfile.pdf"));
} catch (IOException e) {
e.printStackTrace();
}
final PDFRenderer renderer = new PDFRenderer(doc);
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
try {
renderer.renderPageToGraphics(0, (Graphics2D) g, 0.5f);
} catch (IOException e) {
e.printStackTrace();
}
}
};
return panel;
}

public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(getTestPanel());
frame.pack();
frame.setSize(600, 400);
Dimension paneSize = frame.getSize();
Dimension screenSize = frame.getToolkit().getScreenSize();
frame.setLocation((screenSize.width - paneSize.width) / 2, 
(screenSize.height - paneSize.height) / 2);
frame.setTitle("Test");
frame.setVisible(true);
}
});
}
}
{code}

Ivan 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

-
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org