データベースからのデータを含むpdf文書を生成する必要があります。私はたくさんの例を見てきましたが、私はこのデータをデータベースからpdfに得ることができませんでした。Android - データベースからのデータを使用してPDF文書またはprintDocumentを作成する方法
私には2つのモデルの領収書とログ(領収書has_manyログ)があります。私はpdfに領収書からデータを取得し、そのpdfへのreceipt_toの領収書すべてのログを取得します。その後、私はそのPDFドキュメントフォームアンドロイドデバイスを印刷する必要があります。
私の領収書モデルはこちらです。
@Table(name = "Receipt")
public class Receipt extends Model {
@Column(name="Place")
String place;
@Column(name="ShippingNumber")
String shippingNumber;
@Column(name="Warehouse")
String warehouse;
@Column(name="Carrier")
String carrier;
@Column(name="LicencePlate")
String licencePlate;
@Column(name = "Driver")
String driver;
@Column(name = "Customer")
String customer;
@Column(name= "DestWarehouse")
String destWarehouse;
@Column(name = "Employee")
String employee;
@Column(name = "PriceType")
String priceType;
@Column(name = "PriceCorrection")
Integer priceCorrection;
@Column(name = "CreatedAt")
Date createdAt;
public List<Logs> getLogs(){
return getMany(Logs.class,"Receipt");
}
これは私のログモデルです。
@Table(name = "Logs")
public class Logs extends Model {
@Column(name="PlateNumber")
String plate_number;
@Column(name="SortID")
String sort_id;
@Column(name="Grade")
String grade;
@Column(name = "Diametar")
double diameter;
@Column(name="Length")
double length;
@Column(name="CreatedAt")
Date createdAt;
@Column(name="Receipt")
Receipt receipt;
}
また、私は領収書とログをどのように表示しているか分かります。
これは、ログを表示する方法です。
public LogsArrayAdapter(List<Logs> logsList) {
inflater = LayoutInflater.from(DisplayLogs.this);
this.logsList = logsList;
}
@Override
public int getCount() {
return logsList.size();
}
@Override
public Object getItem(int position) {
return logsList.get(position);
}
@Override
public long getItemId(int position) {
return logsList.get(position).getId();
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.activity_display_logs, parent, false);
}
Logs log = logsList.get(position);
((TextView) convertView.findViewById(R.id.textNumber)).setText(log.plate_number);
((TextView) convertView.findViewById(R.id.textSort)).setText(log.sort_id);
((TextView) convertView.findViewById(R.id.textGrade)).setText(log.grade);
((TextView) convertView.findViewById(R.id.textDiameter)).setText(log.diameter + "cm");
((TextView) convertView.findViewById(R.id.textLength)).setText(log.length + "cm");
Log.d("Value", log.createdAt.toString());
((TextView) convertView.findViewById(R.id.textAmount)).setText(String.format("%.2f m3", log.getM3()));
return convertView;
}
これが私の領収書を表示する方法です。
public ReceiptAdapter(List<Receipt> receiptList) {
inflater = LayoutInflater.from(DisplayRecepit.this);
this.receiptList = receiptList;
}
@Override
public int getCount() {
return receiptList.size();
}
@Override
public Object getItem(int position) {
return receiptList.get(position);
}
@Override
public long getItemId(int position) {
return receiptList.get(position).getId();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.activity_display_recepit, parent, false);
}
Receipt receipt = receiptList.get(position);
((TextView) convertView.findViewById(R.id.rPlace)).setText(receipt.place);
((TextView) convertView.findViewById(R.id.rShipNumb)).setText(receipt.shippingNumber);
((TextView) convertView.findViewById(R.id.rEmployee)).setText(receipt.employee);
((TextView) convertView.findViewById(R.id.rWarehouse)).setText(receipt.warehouse);
((TextView) convertView.findViewById(R.id.rCarrier)).setText(receipt.carrier);
((TextView) convertView.findViewById(R.id.rLicence)).setText(receipt.licencePlate);
((TextView) convertView.findViewById(R.id.rDriver)).setText(receipt.driver);
((TextView) convertView.findViewById(R.id.rCustomer)).setText(receipt.customer);
((TextView) convertView.findViewById(R.id.rDestWareh)).setText(receipt.destWarehouse);
((TextView) convertView.findViewById(R.id.rCreatedAt)).setText(new SimpleDateFormat("dd.MM.yyyy HH:mm").format(receipt.createdAt));
return convertView;
}
アドバイスや援助は大歓迎です。私は本当にこれにこだわり、私は助けが必要です。
質問:データベースのデータを含むpdfドキュメントを生成してから印刷するか、android printDocument()を使用してデータベースで直接作業する方が良いでしょうか?
データベースからpdfDocumentまたはprintDocumentに変数を渡すには?