Java’da PostScript (PS) belgelerinde metinle çalışma

Aspose.Page for Java kullanarak PostScript (PS/EPS) belgelerindeki metin öğelerini ekleyin, biçimlendirin ve stillendirin. Yazı tipi seçimi (sistem, TrueType ve OpenType yazı tipleri dahil), metin dolgu ve kontur efektleri, afin dönüşümler (ölçekleme, döndürme, eğme), özel karakter aralığı ve vektör metin kırpma üzerinde tam kontrol sağlayarak yüksek hassasiyetli metinleri programlı olarak işleyin.

 

Aspose.Page for Java, PsDocument sınıfı içinde esnek metin işleme yöntemleri sunarak geliştiricilerin standart dolgulu metin veya vektör yollar boyunca anahatlı metin çıktısı oluşturmasını sağlar.

  • Standart, okunabilir metin paragraflarını, başlıkları ve etiket dizelerini düz renk veya degrade dolgularla işlemek için PsDocument.fillText() yöntemini kullanın.
  • Dekoratif vektör metin ana hatları, içi boş başlıklar veya stilize tipografik efektler oluşturmak için PsDocument.outlineText() yöntemini kullanın.
  • Farklı ortamlarda tam görsel marka tutarlılığını korumak amacıyla harici .ttf veya .otf yazı tipi dosyalarını yüklemek için DrFont/System Fonts kullanın.
  • Metin öğelerine belge sayfası koordinatlarına göre açı vermek, döndürmek veya eğmek için PsDocument.transform() yöntemini kullanın.

PostScript sayfasına standart dolgulu metin ekleme

Standart sistem yazı tiplerini ve renk dolgularını kullanarak bir PostScript sayfasında basit dizeleri işleyin.

import com.aspose.page.eps.PsDocument;
import com.aspose.page.eps.device.PsSaveOptions;
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;

public class AddTextToPS {
    public static void main(String[] args) throws Exception {
        // Initialize output stream and PS document
        FileOutputStream outStream = new FileOutputStream("C:/PSProject/Output/simple_text.ps");
        PsSaveOptions options = new PsSaveOptions();
        PsDocument document = new PsDocument(outStream, options, 1);

        document.openPage(null);

        // Define font and color paint
        Font font = new Font("Times New Roman", Font.BOLD, 20);
        document.setPaint(Color.BLUE);

        // Fill text at specified X, Y coordinates
        document.fillText("Aspose.Page for Java - Text Rendering", font, 100, 150);

        // Close page and save document
        document.closePage();
        document.save();
        outStream.close();

        System.out.println("Text successfully added to PostScript document.");
    }
}

Metin yollarını ana hatlandırma ve konturlama

Etkileyici başlıklar veya tipografik tasarım öğeleri oluşturmak için iç dolgu olmadan vektör metin ana hatları çizin.

import com.aspose.page.eps.PsDocument;
import com.aspose.page.eps.device.PsSaveOptions;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;

public class StrokeTextInPS {
    public static void main(String[] args) throws Exception {
        FileOutputStream outStream = new FileOutputStream("C:/PSProject/Output/stroked_text.ps");
        PsSaveOptions options = new PsSaveOptions();
        PsDocument document = new PsDocument(outStream, options, 1);

        document.openPage(null);

        // Configure font, stroke width, and outline paint
        Font font = new Font("Arial", Font.BOLD, 36);
        document.setStroke(new BasicStroke(2.0f));
        document.setPaint(Color.RED);

        // Outline text string
        document.outlineText("Outlined Vector Text", font, 100, 200);

        document.closePage();
        document.save();
        outStream.close();

        System.out.println("Outlined text rendered successfully.");
    }
}

Özel TrueType/OpenType yazı tiplerini (`.ttf`/`.otf`) kullanma

Yazı tipi dosyalarının yollarını belirterek veya özel yazı tipi klasörlerini PsSaveOptions içine gömerek sistemde bulunmayan marka yazı tiplerini entegre edin.

import com.aspose.page.eps.PsDocument;
import com.aspose.page.eps.device.PsSaveOptions;
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;

public class CustomFontTextPS {
    public static void main(String[] args) throws Exception {
        FileOutputStream outStream = new FileOutputStream("C:/PSProject/Output/custom_font_text.ps");

        // Add custom font folder search path in options
        PsSaveOptions options = new PsSaveOptions();
        options.setAdditionalFontsFolders(new String[] { "C:/PSProject/Fonts/" });

        PsDocument document = new PsDocument(outStream, options, 1);

        document.openPage(null);

        // Reference custom font by its registered family name
        Font customFont = new Font("CustomBrandFont", Font.PLAIN, 24);
        document.setPaint(Color.DARK_GRAY);

        document.fillText("Text rendered using external TrueType font", customFont, 100, 250);

        document.closePage();
        document.save();
        outStream.close();

        System.out.println("Custom font text rendered successfully.");
    }
}

Kurulum ve yapılandırma

Aspose.Page for Java’yı Maven projenize ekleyin:

Package Manager Console Command

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-page</artifactId>
    <version>Latest</version>
</dependency>

FAQ

1. PsDocument içinde metin konumları nasıl hesaplanır?

Metin koordinat noktaları (X, Y), PostScript sayfa çerçevesi içindeki metin dizesinin taban çizgisi başlangıcını temsil eder (PostScript noktaları cinsinden ölçülür; 72 nokta = 1 inç).

2. Metni düz renkler yerine degrade dolgularla oluşturabilir miyim?

Evet. Metne karmaşık dolgu stilleri uygulamak için document.fillText() çağrılmadan önce java.awt.LinearGradientPaint veya java.awt.TexturePaint gibi bir degrade boyama nesnesini document.setPaint() öğesine aktarın.

3. İstenen yazı tipi ana bilgisayar sunucusunda eksikse ne olur?

Belirtilen sistem yazı tipi mevcut değilse ve PsSaveOptions.setAdditionalFontsFolders() aracılığıyla özel bir yazı tipi yolu sağlanmamışsa Aspose.Page, belge oluşturmanın kesintisiz tamamlanmasını sağlamak için Courier veya Helvetica gibi standart varsayılan PostScript yazı tiplerine geri döner.