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

Aspose.Page for Java kullanarak PostScript (PS) belgelerini programlı olarak oluşturun, değiştirin ve yönetin. Sıfırdan kolayca çok sayfalı PS belgeleri oluşturun, sayfalar ekleyin, vektör grafikleri ve metin öğeleri ekleyin, birden çok PostScript dosyasını birleştirin ve Adobe Acrobat veya Distiller yüklemenize gerek kalmadan belge yapısını ayarlayın.

 

Aspose.Page for Java, PostScript belge oluşturma ve sayfa işlemlerini kontrol etmek için PsDocument sınıfını temel alan üst düzey, bağımsız bir nesne modeli sağlar.

Yeni tek sayfalı veya çok sayfalı PostScript yazdırma akışları oluşturmak için PsDocument(outputStream, options) kullanın

  • Bir PostScript akışı içindeki tek tek sayfaları programlı olarak yapılandırmak için PsDocument.openPage()/closePage() yöntemlerini kullanın.
  • Vektör grafiklerini, şekilleri, metinleri ve sayfaları diskteki dosyalara veya akışlara kaydetmek için PsDocument.save() yöntemini kullanın.
  • Sayfa kenar boşluklarını, özel boyutları (A4, Letter) ve yazdırma yönünü ayarlamak için PsSaveOptions sınıfını kullanın.

Java'da çok sayfalı bir PostScript belgesi oluşturma

Kaydetme seçeneklerini yapılandırarak ve belge akışı içindeki sayfaları açıkça açıp kapatarak sıfırdan çok sayfalı bir PS belgesi oluşturun.

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

public class CreateMultiPagePSDocument {
    public static void main(String[] args) throws Exception {
        // Initialize output stream for the new PS file
        FileOutputStream outStream = new FileOutputStream("C:/PSProject/Output/multipage_document.ps");

        // Set save options (Default page size A4, 72 DPI)
        PsSaveOptions options = new PsSaveOptions();

        // Create a multi-page PS document instance
        PsDocument document = new PsDocument(outStream, options, 2); // Explicitly specifying 2 pages

        // --- PAGE 1 ---
        document.openPage("Page 1");
        // Add content to Page 1 (e.g., text or graphics)
        document.closePage();

        // --- PAGE 2 ---
        document.openPage("Page 2");
        // Add content to Page 2
        document.closePage();

        // Save and flush the document
        document.save();
        outStream.close();

        System.out.println("Multi-page PostScript document created successfully.");
    }
}

Mevcut bir belge oluşturucuya sayfa ve grafik ekleme

PostScript belgesinin sayfalarını vektör şekilleri, metin öğeleri ve dönüşümlerle doldurun.

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 AddPageContentToPS {
    public static void main(String[] args) throws Exception {
        FileOutputStream outStream = new FileOutputStream("C:/PSProject/Output/styled_document.ps");
        PsSaveOptions options = new PsSaveOptions();

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

        // Open page
        document.openPage(null);

        // Add text element
        Font font = new Font("Arial", Font.BOLD, 24);
        document.fillText("Hello World from Aspose.Page Java!", font, 100, 100, Color.BLACK);

        // Draw a vector rectangle
        document.setPaint(Color.RED);
        document.drawRect(100, 150, 300, 200);

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

        System.out.println("Styled PS document with vector content saved.");
    }
}

Özel Sayfa Boyutlarını ve Kenar Boşluklarını Yapılandırma

PsSaveOptions kullanarak kesin sayfa boyutları (Letter, Legal veya özel boyutlar gibi) tanımlayın.

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

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

        // Create options and set custom size (e.g., Letter dimensions in points)
        PsSaveOptions options = new PsSaveOptions();
        options.setPageSize(new java.awt.Dimension(612, 792)); // 8.5 x 11 inches in points

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

        document.openPage("Main Page");
        // Page drawing commands...
        document.closePage();

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

        System.out.println("PS document with custom page size saved.");
    }
}

Kurulum ve Ayarlar

Aspose.Page for Java’yı Maven’inize 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. Adobe Acrobat veya PostScript sürücüsü yardımcı programlarının yüklü olması gerekiyor mu?

Hayır. Aspose.Page for Java, harici yazıcı sürücülerine veya yerel yazılımlara bağlı kalmadan PS/EPS belge yapılarını doğrudan oluşturan, işleyen ve değiştiren yerel, bağımsız bir Java kitaplığıdır.

2. Oluşturulan PostScript (PS) belgesini doğrudan PDF veya raster görüntülere dönüştürebilir miyim?

Evet. Oluşturduğunuz PostScript dosyasını doğrudan PDF, PNG, JPEG veya TIFF biçimine dönüştürmek için bir PsDocument örneğini Aspose.Page içindeki PdfDevice veya ImageDevice öğesine aktarabilirsiniz.

3. PsDocument içinde koordinatlar ve ölçü birimleri nasıl tanımlanır?

Aspose.Page, 1 inç = 72 punto olacak şekilde standart PostScript noktalarını kullanır. Koordinatlar, sayfa yüzeyinin başlangıç noktasına göre ölçülür.