แปลง PUB เป็น JPG PNG TIFF Image Java

ไฟล์ Microsoft Publisher ใช้สำหรับพิมพ์หรือเผยแพร่ข้อมูล คุณสามารถแปลงรูปภาพ PUB) เป็น JPG, PNG หรือ TIFF โดยใช้ Java ในบทความนี้ คุณจะได้เรียนรู้วิธีการแปลงไฟล์ PUB เป็นรูปแบบภาพต่างๆ:

การแปลง PUB เป็นอิมเมจ – การติดตั้ง Java API

Aspose.PUB for Java API รองรับการทำงานกับไฟล์ PUB คุณสามารถเรนเดอร์ไฟล์ PUB เป็น PDF จากนั้นใช้ Aspose.PDF for Java API เพื่อแปลงไฟล์ PDF เอาต์พุตเป็นรูปแบบรูปภาพ เช่น JPG, PNG, TIFF เป็นต้น คุณสามารถดาวน์โหลดไฟล์ JAR สำหรับ Aspose.PUB for Java และ Aspose.PDF for Java API หรือระบุการกำหนดค่าต่อไปนี้เพื่อดาวน์โหลด API จาก Maven repository:

พื้นที่เก็บข้อมูล:

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

การพึ่งพา:

 <dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-pub</artifactId>
        <version>20.8</version>
    </dependency>

    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-pdf</artifactId>
        <version>20.5</version>
    </dependency>
</dependencies>

แปลง PUB เป็น JPG Image โดยทางโปรแกรมโดยใช้ Java

คุณสามารถแปลงไฟล์ Microsoft Publisher (PUB) เป็นภาพ JPG โดยทำตามขั้นตอนต่อไปนี้:

  1. โหลดไฟล์ PUB อินพุต
  2. แปลงไฟล์ PUB เป็น PDF ด้วยเมธอด convertToPdf
  3. รับขนาดหน้าจากเอกสาร PDF
  4. ระบุ ความละเอียด และขนาดของภาพที่ส่งออก
  5. บันทึกภาพ JPG ที่ส่งออกโดยใช้ JpegDevice

รหัสด้านล่างอธิบายวิธีการแปลงภาพ PUB เป็น JPG โดยใช้ Java:

// โหลดไฟล์ PUB อินพุต
IPubParser parser = PubFactory.createParser("Test.pub");
Document doc = parser.parse();

// แปลงไฟล์ PUB เป็น PDF
PubFactory.createPdfConverter().convertToPdf(doc, "Test.pdf");

// โหลดไฟล์ PDF
Document document = new Document("Test.pdf");
facades.PdfFileInfo info = new facades.PdfFileInfo(document);
for (Page page : document.getPages())
{
    // รับขนาดหน้าจากเอกสาร PDF
    int width = (int) info.getPageWidth(page.getNumber());
    int height = (int) (info.getPageHeight(page.getNumber()));

    // ตั้งค่าความละเอียดสำหรับภาพที่ส่งออก
    devices.Resolution resolution = new devices.Resolution(300); 
    
    // สร้างอุปกรณ์ JPEG ด้วยความกว้างและความสูงที่ระบุ
    devices.JpegDevice jpegDevice = new devices.JpegDevice(width, height , resolution);

    // แปลงภาพ PUB เป็น JPG
    jpegDevice.process(page, "Page" + page.getNumber() + ".jpg");
}

แปลง PUB เป็น PNG Image โดยทางโปรแกรมด้วย Java

คุณสามารถแปลงไฟล์ PUB เป็นภาพรูปแบบ PNG ด้วยขั้นตอนด้านล่าง:

  1. โหลดไฟล์ PUB อินพุตด้วยวิธี createParser()
  2. แปลงไฟล์ PUB เป็น PDF
  3. ระบุความกว้างและความสูงของภาพที่ส่งออก
  4. สุดท้าย แปลง PUB เป็นภาพ PNG

รหัสต่อไปนี้แสดงวิธีการแปลงภาพ PUB เป็น PNG ด้วย Java:

// โหลดไฟล์ PUB อินพุต
IPubParser parser = PubFactory.createParser("Test.pub");
Document doc = parser.parse();

// แปลงไฟล์ PUB เป็น PDF
PubFactory.createPdfConverter().convertToPdf(doc, "Test.pdf");

Document document = new Document("Test.pdf");
facades.PdfFileInfo info = new facades.PdfFileInfo(document);
for (Page page : document.getPages())
{
    // รับขนาดหน้าจากเอกสาร PDF
    int width = (int) info.getPageWidth(page.getNumber());
    int height = (int) (info.getPageHeight(page.getNumber()));

    // สร้างอุปกรณ์ PNG ด้วยความกว้างและความสูงที่ระบุ
    devices.PngDevice pngDevice = new devices.PngDevice(width, height);

    // แปลง PUB เป็นภาพ PNG
    pngDevice.process(page, "Page" + page.getNumber() + ".png");
}

การแปลง PUB เป็น TIFF โดยทางโปรแกรมใน Java

คุณสามารถแปลงไฟล์ PUB เป็นภาพ TIFF โดยทำตามขั้นตอนด้านล่าง:

  1. ประการแรก โหลดไฟล์ Publisher (PUB) อินพุต
  2. แปลงไฟล์ PUB เป็น PDF โดยใช้วิธี convertToPdf()
  3. ระบุคุณสมบัติของภาพ TIFF โดยใช้คลาส TiffSettings
  4. สุดท้าย แปลง PUB เป็นภาพ TIFF ด้วยอินสแตนซ์ TiffDevice

รหัสต่อไปนี้สาธิตวิธีการแปลงภาพ PUB เป็น TIFF โดยทางโปรแกรมโดยใช้ Java:

// โหลดไฟล์ PUB อินพุต
IPubParser parser = PubFactory.createParser("Test.pub");
Document doc = parser.parse();

// แปลงไฟล์ PUB เป็น PDF
PubFactory.createPdfConverter().convertToPdf(doc, "Test.pdf");

Document document = new Document("Test.pdf");
facades.PdfFileInfo info = new facades.PdfFileInfo(document);

// รับขนาดหน้าจากเอกสาร PDF
int width = (int) info.getPageWidth((int)(1));
int height = (int) info.getPageHeight((int)(1));

devices.Resolution resolution = new devices.Resolution(300); 

devices.TiffSettings settings = new devices.TiffSettings();
settings.setCompression(devices.CompressionType.None);
settings.setDepth(devices.ColorDepth.Default);

// สร้างอุปกรณ์ TIFF ด้วยความกว้างและความสูงที่ระบุ
devices.TiffDevice tiffDevice = new devices.TiffDevice(width, height , resolution, settings);

// แปลงภาพ PUB เป็น TIFF
tiffDevice.process(document, "Output.tiff");

รับใบอนุญาต API ฟรี

คุณสามารถประเมิน API ได้อย่างเต็มประสิทธิภาพโดยขอ ใบอนุญาตชั่วคราวฟรี

บทสรุป

โดยสรุป คุณได้เรียนรู้วิธีแปลง Microsoft Publisher, PUB, ไฟล์เป็นรูปแบบรูปภาพต่างๆ เช่น JPG, PNG, TIFF ฯลฯ โดยทางโปรแกรมโดยใช้ Java นอกจากนี้ คุณสามารถเรียนรู้เกี่ยวกับคุณลักษณะเพิ่มเติมได้โดยไปที่ เอกสารประกอบ ของ Aspose.PUB for Java API นอกจากนี้ โปรดติดต่อเราผ่าน ฟอรัมสนับสนุนฟรี สำหรับข้อกังวลใดๆ ของคุณ

ดูสิ่งนี้ด้วย