小Roy
小Roy
CCConvex Community
Created by 小Roy on 8/29/2024 in #support-community
pdfme esbuild warnings
fyi. I switched to use pdfmake library after trying almost all the popular libraries on the market.
5 replies
CCConvex Community
Created by 小Roy on 8/29/2024 in #support-community
pdfme esbuild warnings
No description
5 replies
CCConvex Community
Created by 小Roy on 8/18/2024 in #support-community
Unable to use convex as a submodule
Thanks so much! I just read the announcements it’s exciting
6 replies
CCConvex Community
Created by 小Roy on 8/29/2024 in #support-community
pdfme esbuild warnings
"use node";

import { action } from "./_generated/server";
import { generate } from "@pdfme/generator";
import { text, barcodes, image } from "@pdfme/schemas";
import QRCode from "qrcode";
import { BLANK_PDF } from "@pdfme/common";

async function generateQRCode(data: string): Promise<string> {
return new Promise((resolve, reject) => {
QRCode.toDataURL(
data,
{ errorCorrectionLevel: "H", type: "image/png" },
(err, url) => {
if (err) reject(err);
else resolve(url);
}
);
});
}

// Convex action to generate shipping label
export const generateShippingLabel = action({
args: {},
handler: async (ctx, args) => {
// Generate QR code
const qrCodeData = `https://www.google.com`;
const qrCodeImage = await generateQRCode(qrCodeData);

// Prepare input data for PDF generation
const inputs = [
{
qrCode: qrCodeImage,
},
];

try {
// Generate PDF with QR code plugin
const pdf = await generate({
template: {
basePdf: BLANK_PDF,
schemas: [
{
qrCode: {
type: "image",
position: { x: 300, y: 100 },
width: 80,
height: 80,
},
},
],
},
inputs,
plugins: {
text,
qrcode: barcodes.qrcode,
image,
},
});

// Convert Uint8Array to Blob and save to Convex storage
const blob = new Blob([pdf], { type: "application/pdf" });
const storageId = await ctx.storage.store(blob);

// Return the storage ID of the saved PDF
return { storageId };
} catch (error) {
console.error("PDF generation error:", error);
throw new Error(
`Failed to generate PDF: ${error instanceof Error ? error.message : String(error)}`
);
}
},
});
"use node";

import { action } from "./_generated/server";
import { generate } from "@pdfme/generator";
import { text, barcodes, image } from "@pdfme/schemas";
import QRCode from "qrcode";
import { BLANK_PDF } from "@pdfme/common";

async function generateQRCode(data: string): Promise<string> {
return new Promise((resolve, reject) => {
QRCode.toDataURL(
data,
{ errorCorrectionLevel: "H", type: "image/png" },
(err, url) => {
if (err) reject(err);
else resolve(url);
}
);
});
}

// Convex action to generate shipping label
export const generateShippingLabel = action({
args: {},
handler: async (ctx, args) => {
// Generate QR code
const qrCodeData = `https://www.google.com`;
const qrCodeImage = await generateQRCode(qrCodeData);

// Prepare input data for PDF generation
const inputs = [
{
qrCode: qrCodeImage,
},
];

try {
// Generate PDF with QR code plugin
const pdf = await generate({
template: {
basePdf: BLANK_PDF,
schemas: [
{
qrCode: {
type: "image",
position: { x: 300, y: 100 },
width: 80,
height: 80,
},
},
],
},
inputs,
plugins: {
text,
qrcode: barcodes.qrcode,
image,
},
});

// Convert Uint8Array to Blob and save to Convex storage
const blob = new Blob([pdf], { type: "application/pdf" });
const storageId = await ctx.storage.store(blob);

// Return the storage ID of the saved PDF
return { storageId };
} catch (error) {
console.error("PDF generation error:", error);
throw new Error(
`Failed to generate PDF: ${error instanceof Error ? error.message : String(error)}`
);
}
},
});
5 replies
CCConvex Community
Created by 小Roy on 8/23/2024 in #support-community
Use pdfkit in actions
Thanks so much! I think this approach works much better than mine!
18 replies
CCConvex Community
Created by 小Roy on 8/23/2024 in #support-community
Use pdfkit in actions
18 replies
CCConvex Community
Created by 小Roy on 8/23/2024 in #support-community
Use pdfkit in actions
No description
18 replies
CCConvex Community
Created by 小Roy on 8/23/2024 in #support-community
Use pdfkit in actions
No description
18 replies
CCConvex Community
Created by 小Roy on 8/23/2024 in #support-community
Use pdfkit in actions
No description
18 replies
CCConvex Community
Created by 小Roy on 8/23/2024 in #support-community
Use pdfkit in actions
No description
18 replies