From bb6d118f3490687fe8fa52822e8f37aa9af7b420 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Fri, 12 Jul 2024 09:31:09 +0300 Subject: [PATCH] wallet_recovery_pdf working --- nextgraph/src/local_broker.rs | 17 ++++++++++++++--- ng-app/src/routes/User.svelte | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/nextgraph/src/local_broker.rs b/nextgraph/src/local_broker.rs index c5754fb..69d06b4 100644 --- a/nextgraph/src/local_broker.rs +++ b/nextgraph/src/local_broker.rs @@ -22,7 +22,7 @@ use pdf_writer::{Content, Finish, Name, Pdf, Rect, Ref, Str}; use qrcode::{render::svg, QrCode}; use serde_bare::to_vec; use serde_json::json; -use svg2pdf::{ConversionOptions, PageOptions}; +use svg2pdf::ConversionOptions; use zeroize::Zeroize; use ng_repo::block_storage::BlockStorage; @@ -1618,7 +1618,7 @@ pub async fn wallet_recovery_pdf( // you can use the methods of pdf_writer library. - let (mut chunk, reference) = svg2pdf::to_chunk(&tree, ConversionOptions::default()); + let (chunk, qrcode_ref) = svg2pdf::to_chunk(&tree, ConversionOptions::default()); // probably then: add the text with chunk.stream() or chunk.indirect() //let pdf_buf = svg2pdf::to_pdf(&tree, ConversionOptions::default(), PageOptions::default()); @@ -1630,6 +1630,7 @@ pub async fn wallet_recovery_pdf( let font_id = Ref::new(1003); let content_id = Ref::new(1004); let font_name = Name(b"F1"); + let qrcode_name = Name(b"Im1"); let mut content = Content::new(); content.begin_text(); @@ -1637,8 +1638,17 @@ pub async fn wallet_recovery_pdf( content.next_line(108.0, 734.0); content.show(Str(b"Hello World from Rust!")); content.end_text(); + content.begin_text(); + content.set_font(font_name, 14.0); + content.next_line(15.0, 810.0); + content.show(Str(recovery_str.as_bytes())); + content.end_text(); + content.save_state(); + content.transform([595.0, 0.0, 0.0, 595.0, 0.0, 0.0]); + content.x_object(qrcode_name); + content.restore_state(); - // Write a document catalog and a page tree with one A4 page that uses no resources. + // Write a document catalog and a page tree with one A4 page . let mut pdf = Pdf::new(); pdf.stream(content_id, &content.finish()); pdf.catalog(catalog_id).pages(page_tree_id); @@ -1650,6 +1660,7 @@ pub async fn wallet_recovery_pdf( .media_box(Rect::new(0.0, 0.0, 595.0, 842.0)) .resources(); page_resources.fonts().pair(font_name, font_id); + page_resources.x_objects().pair(qrcode_name, qrcode_ref); page_resources.finish(); page.contents(content_id); diff --git a/ng-app/src/routes/User.svelte b/ng-app/src/routes/User.svelte index 678ff1c..0655e0d 100644 --- a/ng-app/src/routes/User.svelte +++ b/ng-app/src/routes/User.svelte @@ -57,6 +57,7 @@ active_wallet, connections, reconnect, + display_error, } from "../store"; import {