Artefakte beim Drucken

jimb0p

Erfahrenes Mitglied
Hallo Zusammen,

ich möchte ein Label drucken mit Preis, Produktname und einem QR Code. Dies funktioniert soweit. Allerdings habe ich an den Textstellen für Preis und Produktname Artefakte und ich weiß nicht wo sie herkommen. Hier mal ein Beispiel:

78.png


Ich drucke es über die snapshot Funktion und habe auch eine entsprechende GUI als Vorlage dafür:
Code:
<AnchorPane xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="PFAD ZUM CONTROLLER">
   <children>
      <VBox alignment="CENTER" prefHeight="390.0" prefWidth="274.0">
         <children>
            <Text fx:id="footer" smooth="false" strokeType="OUTSIDE" strokeWidth="0.0" textAlignment="CENTER" wrappingWidth="263.37109375">
               <font>
                  <Font name="System Bold" size="60.0" />
               </font>
               <VBox.margin>
                  <Insets top="-22.0" />
               </VBox.margin>
            </Text>
            <ImageView fx:id="imgView" fitHeight="270.0" fitWidth="270.0" pickOnBounds="true" preserveRatio="true" />
            <Text fx:id="header" smooth="false" strokeType="OUTSIDE" strokeWidth="0.0" textAlignment="CENTER" wrappingWidth="260.837890625">
               <font>
                  <Font name="System Bold" size="26.0" />
               </font>
            </Text>
         </children>
      </VBox>
   </children>
</AnchorPane>

Hier mein Code:
Java:
public void createLabel(String name, String price, String artNr) {
            setPrice(price);
            setName(name);
            String codeText = artNr;
            BufferedImage bImage = QRGenerator.createQR(codeText);
            imgView.setImage(SwingFXUtils.toFXImage(bImage, null));

        WritableImage snapshot = primaryStage.getScene().getRoot().snapshot(new SnapshotParameters(), null);
        saveImage(snapshot, new File("tmp.png"));
}

private void saveImage(WritableImage snapshot, File file) {
            BufferedImage image;
            image = javafx.embed.swing.SwingFXUtils.fromFXImage(snapshot, bufferedImage);
            Graphics2D gd = (Graphics2D) image.getGraphics();
            gd.translate(primaryStage.getWidth(), primaryStage.getHeight());
            ImageIO.write(image, "png", file);
}

public void print() {
    DocFlavor flavor = DocFlavor.INPUT_STREAM.PNG;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

    PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
    Media[] res = (Media[]) printService.getSupportedAttributeValues(Media.class, null, null);
    MediaSizeName msn = (MediaSizeName) res[14];
    aset.add(OrientationRequested.LANDSCAPE);
    aset.add(res[14]);

    DocPrintJob pj = printService.createPrintJob();

    FileInputStream fis = new FileInputStream("tmp.png");
    Doc doc = new SimpleDoc(fis, flavor, null);
    pj.print(doc, aset);
}

Habe die Textbereiche bereits als Labels probiert, leider ohne Erfolg. Falls jemand eine Idee hat immer her damit!
 

Neue Beiträge

Zurück