1

私はtelufu pdfにpdfを持っています(anils.comを123.176.47.55に置き換えます)そのpdfからテキストを抽出したい(そのpdfページのように、読む必要のある3番目のブロックデータはありません)そのために、そのページのすべてのフォントをダウンロードしますmupdf-1.3-windows

PDFが使用するすべてのフォントをダウンロードしますが、それらのフォントを使用してそのテキストを別のPDFに書き込むと、コードが再編集されていないテキストの一部が次のようになります

//output file name
public static String pdf1 = "C:\\Documents and Settings\\Administrator\\Desktop\\itextpdf\\anil.pdf";

public static void main(String[] args) throws IOException, DocumentException {
    try {
        PdfReader reader = new PdfReader(new URL("http://anils/DraftRolls/PDFGeneration.aspx?urlPath=D%3a\\SSR_2013_FINAL+ROLLS\\AC_238\\Telugu\\S01A238P038.PDF"),null);
        System.out.println("This PDF has "+reader.getNumberOfPages()+" pages.");

        // reading page no 3 
        String page = PdfTextExtractor.getTextFromPage(reader, 3);                     

        // all fonts I had checked total of 7 fonts but I didn't get all the fonts 
        BaseFont f = BaseFont.createFont("C:\\Documents and Settings\\Administrator\\Desktop\\itextpdf\\fonts\\AAAAAD+Gautami-0174.ttf", "", BaseFont.EMBEDDED);
        Font telugu = new Font(f, 18.0f, Font.BOLD);

        Paragraph description = new Paragraph(page,telugu);

        // description.setAlignment(Paragraph.ALIGN_CENTER); 

        Document document = new Document();
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(pdf1));
        // step 3
        document.open();
        document.add(description);
        document.close();
    }
    catch(Exception e)
    {
        System.out.println(e);
    }
}

一部のテキストはどのフォントにも一致しませんでした。これを解決するにはどうすればよいですか?

4

2 に答える 2

0

元の質問へのコメントで、テキストは元のように整理されている可能性があり、リフローする必要がないことを述べているように、元のページをテンプレートとしてインポートし、選択した領域のみを表示することは、ニーズの解決策になる可能性があります:

public void testImportFragment() throws IOException, DocumentException
{
    PdfReader reader = new PdfReader(new URL("http://anils/DraftRolls/PDFGeneration.aspx?urlPath=D%3a\\SSR_2013_FINAL+ROLLS\\AC_238\\Telugu\\S01A238P038.PDF"),null);
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:\\Documents and Settings\\Administrator\\Desktop\\itextpdf\\anil.pdf"));
    document.open();
    document.newPage();
    document.add(new Paragraph("Test importing the contents of the first row of page three in a different order."));
    copyFragment(reader, writer);
    document.close();
    reader.close();
}

public void copyFragment(PdfReader source, PdfWriter target) throws DocumentException
{
    PdfImportedPage page = target.getImportedPage(source, 3);
    PdfContentByte directContent = target.getDirectContent();

    PdfTemplate template = directContent.createTemplate(110, 57);
    template.addTemplate(page, 1, 0, 0, 1, -15, -706);
    directContent.addTemplate(template, 200, 700);

    template = directContent.createTemplate(110, 57);
    template.addTemplate(page, 1, 0, 0, 1, -202, -705);
    directContent.addTemplate(template, 200, 600);

    template = directContent.createTemplate(110, 57);
    template.addTemplate(page, 1, 0, 0, 1, -389, -705);
    directContent.addTemplate(template, 200, 500);
}
于 2013-09-27T15:21:40.047 に答える