これは、 小規模なスタンドアロン·アプリケーションです。 あなたが例について理解していない何かがある場合は、インスピレーションを得るために、この例を使用していますが、本を購入してくださいすることができます。 記事を読む第15章詳細。 この例では、に依存することに注意してSvgToPdf 、およびおそらくいくつかの他の例を示します。
第15章:ページのコンテンツと構造
この例のためのキーワード: Graphics2Dの 、 オプショナルコンテンツグループ 、 PdfLayer 、 PdfTemplate 、 (PdfContentByte> showTextAligned)
この例では、操作したい場合は、次のものが必要です。
あなたは、ディレクトリ内の次のフォントがあることを確認しますc:/windows/fonts/ Webdings(webdings.ttfを):。
この例では、次のリソースを使用しfoobarcity.svg 、 foobarstreets.svg 、 foobarrues.svg 、 foobarstraten.svgを 。
part4.chapter15.SvgLayers
この例をコンパイルして実行する場合は、次の結果を取得します:
foobarcity.pdf
あなたの完全なソースコードをダウンロードすることができますSvgLayersのか、ここでそれを読む:
  / *
   " -第2版アクションでiTextの" *このクラスは、ある本の一部である
   ブルーノLowagie(:9781935182610 ISBN)によって書かれた*
   http://itextpdf.com/examples/:*詳細については、に行く
   *この例では、iTextのAGPLバージョンでのみ動作します。
   * /
 パッケージその4 第15章。
 。。javaのIO FileOutputStreamを インポートします 。
 。。javaのIO IOExceptionを インポートします 。
 。。javaのutilのArrayListを インポートします 。
 。。 インポート COM itextpdfテキスト ドキュメント ;
 。。 インポート COM itextpdfテキスト DocumentException ;
 。。 インポート COM itextpdfテキスト 四角形 ;
 。。 インポート COM itextpdfテキストPDF BASEFONT ;
 。。 インポート COM itextpdfテキストPDF PdfContentByte ;
 。。 インポート COM itextpdfテキストPDF PdfLayer ;
 。。 インポート COM itextpdfテキストPDF PdfTemplate ;
 。。 インポート COM itextpdfテキストPDF PDFWriterは ;
 パブリッククラス SvgLayersはSvgToPdfを{ 伸びる
     / **結果のPDF。  * /
     public static finalの文字列の結果= "results/part4/chapter15/foobarcity.pdf";
     / mapを。**  * /
     public static finalの文字列RUES = "リソース/ XML / foobarrues.svg";
     / mapを。**  * /
     public static finalの文字列STRATEN = "リソース/ XML / foobarstraten.svg";
     / **
       ※PDF形式の文書を作成します。
       新しいPDFドキュメントにする* @ paramファイル名パス
       * @ DocumentExceptionをスロー
       * @ IOExceptionをスロー
       * @ SQLExceptionをスローします。
       * /
     公共 ボイド createPdf(文字列のファイル名)がIOExceptionをスローし DocumentExceptionを {
         / /ステップ1
         文書ドキュメント= 新しい ドキュメント ( 新しい 四角形 (6000、6000));
         / /ステップ2
         PDFWriterの作家= PDFWriterが 。 メソッドgetInstance(文書、 新しい FileOutputStreamを(結果));
        作家setViewerPreferences( PDFWriterが PageModeUseOC |。 PDFWriterが FitWindow。);
        作家setPdfVersion( PDFWriterが VERSION_1_5。);
         / /ステップ3
        ドキュメント開く();
         / /ステップ4
         / /グリッド·レイヤーを作成する
         PdfLayer gridLayer = 新しい PdfLayer ( "グリッド"、作家);
         。gridLayer setZoom(0 0.2 F、1);
         gridLayer setOnPanel(false)を指定します ;
         / /ストリートレイヤーを作成
         PdfLayer streetlayer = PdfLayer 。createTitle(
                 "街/ Rues / Straten"、作家);
         PdfLayer streetlayer_en = 新しい PdfLayer ( "英語"、作家);
         。streetlayer_en シートン ( 真の );
         。streetlayer_en setLanguage( "en"は 、 真の );
         PdfLayer streetlayer_fr = 新しい PdfLayer ( "フラン\ U 00e7ais"、作家);
         。streetlayer_fr シートン ( 偽 );
         。streetlayer_fr setLanguage( "FR"、FALSE);
         PdfLayer streetlayer_nl = 新しい PdfLayer ( "オランダ"、作家);
         。streetlayer_nl シートン ( 偽 );
         。streetlayer_nl setLanguage( "NL"、FALSE);
         。streetlayer addChildメソッド(streetlayer_en);
         。streetlayer addChildメソッド(streetlayer_fr);
         。streetlayer addChildメソッド(streetlayer_nl);
         ArrayListの<PdfLayer>ラジオ= 新しいArrayList <PdfLayer>();
        ラジオ(streetlayer_en)を 追加します;
        ラジオ(streetlayer_fr)を 追加します;
        ラジオ(streetlayer_nl)を 追加します;
         。作家addOCGRadioGroup(ラジオ);
         / /マップを作成
         PdfContentByte CB =作家getDirectContent();
         PdfTemplate 。マップ= CB createTemplate(6000、6000);
         / / DRAW CITY
         drawSvg(地図、CITY);
         。CB addTemplate(地図、0、0);
         PdfTemplate 。通りは= CB createTemplate(6000、6000);
         / / DRAW STREETS
         (道路、通り)drawSvg;
        路上setLayer(streetlayer_en);
         。CB addTemplate(通り、0、0);
         PdfTemplate 。rues = CB createTemplate(6000、6000);
         drawSvg(rues、RUES);
         。rues setLayer(streetlayer_fr);
         。CB addTemplate(rues、0、0);
         PdfTemplate 。straten = CB createTemplate(6000、6000);
         drawSvg(straten、STRATEN);
         。straten setLayer(streetlayer_nl);
         。CB addTemplate(straten、0、0);
         / /グリッドを描画
         。CB セーブステート();
         。CB beginLayer(gridLayer);
         。CB setGrayStroke(0.7 F);
         。CB setLineWidth(2);
         するfor(int i = 0;のi <8は、i + +){
             。CB のmoveTo(1250、1500 + I * 500);
             。CB LINETO(4750、1500 + I * 500);
         }
         するfor(int i = 0;のi <8は、i + +){
             CB のmoveTo(1250 + I * 500、1500);
             CB LINETO(1250 + I * 500、5000);
         }
         CB ストローク();
         。CB endLayer();
         。CB restorestateを();
         / / INFOのレイヤーを作成
         PdfLayer cityInfoLayer = 新しい PdfLayer ( "foobarの情報"、作家);
         。cityInfoLayer シートン ( 偽 );
         PdfLayer hotelLayer = 新しい PdfLayer ( "ホテル"、作家);
         。hotelLayer シートン ( 偽 );
         。cityInfoLayer addChildメソッド(hotelLayer);
         PdfLayer parkingLayer = 新しい PdfLayer ( "駐車場"、作家);
         。parkingLayer シートン ( 偽 );
         。cityInfoLayer addChildメソッド(parkingLayer);
         PdfLayer businessLayer = 新しい PdfLayer ( "産業"、作家);
         。businessLayer シートン ( 偽 );
         。cityInfoLayer addChildメソッド(businessLayer);
         PdfLayer cultureLayer = PdfLayer 。createTitle( "レジャー·文化"、
                作家);
         PdfLayer goingoutLayer = 新しい PdfLayer ( "外出"、作家);
         。goingoutLayer シートン ( 偽 );
         。cultureLayer addChildメソッド(goingoutLayer);
         PdfLayer restoLayer = 新しい PdfLayer ( "レストラン"、作家);
         。restoLayer シートン ( 偽 );
         。goingoutLayer addChildメソッド(restoLayer);
         PdfLayer theatreLayer = 新しい PdfLayer ( "(動画)劇場"、作家);
         。theatreLayer シートン ( 偽 );
         。goingoutLayer addChildメソッド(theatreLayer);
         PdfLayer monumentLayer = 新しい PdfLayer ( "美術館やモニュメント"
                作家);
         。monumentLayer シートン ( 偽 );
         。cultureLayer addChildメソッド(monumentLayer);
         PdfLayer sportsLayer = 新しい PdfLayer ( "スポーツ"、作家);
         。sportsLayer シートン ( 偽 );
         。cultureLayer addChildメソッド(sportsLayer);
         / /情報を描く
         BASEFONTフォント= BASEFONT 。 のcreateFont(
                 "C :/ウィンドウ/フォント/ webdings.ttf"、 BASEFONT 。WINANSI、
                 BASEFONT 埋め込 まれている)。
         。CB セーブステート();
         。CB beginText();
         。CB setRGBColorFill(0x00は、0x00や0xFF)を ;
         。CB setFontAndSize(フォント、36);
         。CB beginLayer(cityInfoLayer);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0x69の)、2700、3100、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0x69の)、3000、2050、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0x69の)、3100、2550、0);
         。CB beginLayer(hotelLayer);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、2000、1900、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、2100、1950、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、2200、2200、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、2700、3000、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、2750、3050、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、2500、3500、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、2300、2000、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、3250、2200、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、3300、2300、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、3400、3050、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、3250、3200、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、2750、3800、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、2900、3800、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、3000、2400、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、2000、2800、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe3)、2600、3200、0);
         。CB endLayer(); / / hotelLayer
         。CB beginLayer(parkingLayer);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe8)、2400、2000、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe8)、2100、2600、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe8)、3300、2250、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xe8)、3000、3900、0);
         。CB endLayer(); / / parkingLayer
         。CB beginLayer(businessLayer);
         。CB setRGBColorFill(が0xC0、0xC0に、が0xC0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0x46)、3050、3600、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0x46)、3200、3900、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0x46)、3150、3700、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0x46)、3260、3610、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0x46)、3350、3750、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0x46)、3500、4000、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0x46)、3500、3800、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0x46)、3450、3700、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0x46)、3450、3600、0);
         。CB endLayer(); / / businessLayer
         。CB endLayer(); / / cityInfoLayer
         。CB beginLayer(goingoutLayer);
         。CB beginLayer(restoLayer);
         。CB setRGBColorFill(0xFFで、0x14を、0x93);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、2650、3500、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、2400、1900、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、2750、3850、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、2700、3200、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、2900、3100、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、2850、3000、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、2800、2900、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、2300、2900、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、1950、2650、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、1800、2750、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、3350、3150、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、3400、3100、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)を辞書式の順序)、3250、3450、0);
         。CB endLayer(); / / restoLayer
         。CB beginLayer(theatreLayer);
         。CB setRGBColorFill(0xDC、0x14で、その値を0x3c);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0xAEの)、2850、3300、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0xAEの)、3050、2900、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0xAEの)、2650、2900、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0xAEの)、2750、2600、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xB8)、2800、3350、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xB8)、2550、2850、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は0xB8)、2850、3300、0);
         。CB endLayer(); / / theatreLayer
         。CB endLayer(); / / goingoutLayer
         。CB beginLayer(monumentLayer);
         。CB setRGBColorFill(0x00は、0x00は、0x00を);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0x47と)、3250、2750、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0x47と)、2750、2900、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0x47と)、2850、3500、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0xADの)、2150、3550、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0xADの)、3300、2730、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0xADの)、2200、2000、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0xADの)、2900、3300、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は 0xADの)、2080、3000、0);
         。CB endLayer(); / / monumentLayer
         。CB beginLayer(sportsLayer);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は $ 53)、2700、4050、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は $ 53)、2700、3900、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は $ 53)、2800、3980、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は $ 53)、1950、2800、0);
         CB。showTextAligned( PdfContentByte 。ALIGN_CENTER、文字列
                 。valueOfの ((char)は $ 53)、3700、2450、0);
         。CB endLayer(); / / sportsLayer
         。CB endText();
         。CB restorestateを();
         / /ステップ5
        ドキュメント閉じる();
     }
     / **
       * Mainメソッド。
       *
       引数が必要ないする* @ param argsに
       * @ DocumentExceptionをスロー
       * @ IOExceptionをスロー
       * @ SQLExceptionをスローします。
       * /
     公共の静的な無効メイン(文字列[] args)はIOExceptionをスローし DocumentExceptionを {
         新しい SvgLayers()createPdf(結果)。
     }
 }
0 件のコメント:
コメントを投稿