16

iTextSharp を使用して pdf を生成しました。ASP.Net で非常によくプレビューできますが、プレビューなしで直接プリンターに送信する必要があります。ユーザーが印刷ボタンをクリックすると、ドキュメントが自動的に印刷されます。

javascript window.print() を使用してページをプリンターに直接送信できることは知っていますが、PDF 用に作成する方法がわかりません。

編集: 埋め込まれていません。このように生成します。

                ...
                FileStream stream = new FileStream(Request.PhysicalApplicationPath + "~1.pdf", FileMode.Create);
                Document pdf = new Document(PageSize.LETTER);
                PdfWriter writer = PdfWriter.GetInstance(pdf, stream);
                pdf.Open();
                pdf.Add(new Paragraph(member.ToString()));
                pdf.Close();

                Response.Redirect("~1.pdf");
                ...

そして、ここにいます。

4

5 に答える 5

6

最後に作成しましたが、IFRAMEを使用する必要があり、aspxでIFrameを定義し、srcプロパティを設定しませんでした。作成したcsファイルでpdfファイルを生成し、iFrameのsrcプロパティを生成されたものとして設定しました。このようなpdfファイル名。

Document pdf = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(pdf, 
new FileStream(Request.PhysicalApplicationPath + "~1.pdf", FileMode.Create));
pdf.Open();

//This action leads directly to printer dialogue
PdfAction jAction = PdfAction.JavaScript("this.print(true);\r", writer);
writer.AddJavaScript(jAction);

pdf.Add(new Paragraph("My first PDF on line"));
pdf.Close();

//Open the pdf in the frame
frame1.Attributes["src"] = "~1.pdf";

そしてそれはトリックを作りました、しかし、私はあなたのソリューションStefanを実装するべきだと思います、問題は私がasp.netとjavascriptに不慣れであり、完全なソースコードを持っていない場合私はあなたの提案をコーディングできなかったということですが少なくとも最初のステップですが、htmlとjavascriptのコードの量を学ぶ必要があることに非常に驚いていました。Thnx。

于 2008-11-07T04:37:47.383 に答える
1

pdfsharp を使用している場合は少しトリッキーですが、かなり実行可能です。

PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage(); 
XGraphics gfx = XGraphics.FromPdfPage(page); 
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic); 
// Draw the text 
gfx.DrawString("Hello, World!", font, XBrushes.Black, 
    new XRect(0, 0, page.Width, page.Height), 
    XStringFormats.Center); 

// real stuff starts here

// current version of pdfsharp doesn't support actions 
// http://www.pdfsharp.net/wiki/WorkOnPdfObjects-sample.ashx
// so we got to get close to the metal see chapter 12.6.4 of 
// http://partners.adobe.com/public/developer/pdf/index_reference.html
PdfDictionary dict = new PdfDictionary(document); // 
dict.Elements["/S"] = new PdfName("/JavaScript"); // 
dict.Elements["/JS"] = new PdfString("this.print(true);\r");
document.Internals.AddObject(dict);
document.Internals.Catalog.Elements["/OpenAction"] = 
    PdfInternals.GetReference(dict);
document.Save(Server.MapPath("2.pdf"));
frame1.Attributes["src"] = "2.pdf"; 
于 2011-07-19T15:32:24.123 に答える
1

pdf は、embedd-tag を使用してページに埋め込まれていますか、それともフレームで開いたばかりですか、またはどのように表示していますか?

埋め込まれている場合は、オブジェクトが選択されていることを確認してから、print() を実行します。

埋め込みドキュメントへの参照を取得します。

var x = document.getElementById("mypdfembeddobject");  
x.click();
x.setActive();
x.focus();
x.print();
于 2008-11-06T23:15:28.783 に答える
0

JavaScriptをPDFに埋め込むことができるので、ユーザーはブラウザがPDFをロードするとすぐに印刷ダイアログを表示できます。

iTextSharpについてはよくわかりませんが、使用しているjavascriptは

var pp = this.getPrintParams();
pp.interactive = pp.constants.interactionLevel.automatic;
this.print(pp);

iTextSharpについては、 http: //itextsharp.sourceforge.net/examples/Chap1106.csを確認してください。

于 2008-11-07T00:03:54.737 に答える
0

また、この宝石を試してください:

<link ref="mypdf" media="print" href="mypdf.pdf">

私はそれをテストしていませんが、私がそれについて読んだことは、ページを印刷するために使用している方法に関係なく、ページコンテンツの代わりに mypdf.pdf を印刷できるようにするためにこの方法で使用できます。

詳しくは、media="print" を検索してご覧ください。

于 2008-11-06T23:25:35.283 に答える