0

我创建了一个打印 jTable 的方法printTable()并将文件另存为 pdf,我想获取保存的 file.pdf 的路径

有我的部分代码:

public static void printTable()
    {
        MessageFormat Header = new MessageFormat("Password List");
        MessageFormat footer = new MessageFormat("PAGE # {0}");
        
        PrintRequestAttributeSet set = new HashPrintRequestAttributeSet();
        set.add(OrientationRequested.LANDSCAPE);
        
        try {
            
            Boolean Printing =    ListPasss.print(JTable.PrintMode.FIT_WIDTH, Header, footer);
            
            if (Printing )
            {
                System.out.println("succefully..");
           
            }
            else
            {
                System.out.println("Cancelled..");
            }
            } catch (PrinterException e) {
                System.out.println("error");
        }
    }

我想用它来旋转pdf文件以横向我创建的方法是:

public static void RotatePdf()
    {
        try
        {
            // load original PDF
            PDFDocument pdfDoc = new PDFDocument ("Path of printed file", null);
 
            // Loop through all pages
            for (int i = 0; i < pdfDoc.getPageCount(); i++) 
            {
            // get page in the original PDF 
                PDFPage page = pdfDoc.getPage(i);
 
                // change the page rotation to flip it by 90 degrees
                page.setPageRotation(90);
            }
 
            // print the document 
            pdfDoc.print(new PrintSettings());
 
            // save the document
            pdfDoc.saveDocument ("Path of printed file/modified");
        }
        catch (PDFException | PrinterException | IOException t)
        {
            System.out.println("Not Rotated");
        }
    }

有人可以帮忙吗?

4

0 回答 0