ABDALLALSWAITI commited on
Commit
dd229d4
·
verified ·
1 Parent(s): 25fef2d

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +5 -5
  2. puppeteer_pdf.js +17 -14
app.py CHANGED
@@ -122,11 +122,11 @@ def inject_page_breaks(html_content: str, aspect_ratio: str):
122
  """Automatically inject page breaks and page sizing CSS"""
123
 
124
  if aspect_ratio == "16:9":
125
- page_size = "A4 landscape"
126
  elif aspect_ratio == "1:1":
127
  page_size = "210mm 210mm"
128
  else:
129
- page_size = "A4 portrait"
130
 
131
  page_css = f"""
132
  <style id="auto-page-breaks">
@@ -145,14 +145,12 @@ def inject_page_breaks(html_content: str, aspect_ratio: str):
145
  .page, .slide, section.page, article.page, div[class*="page"], div[class*="slide"] {{
146
  width: 100% !important;
147
  min-height: 100vh !important;
148
- height: 100vh !important;
149
  page-break-after: always !important;
150
  break-after: page !important;
151
  page-break-inside: avoid !important;
152
  break-inside: avoid !important;
153
  position: relative !important;
154
  box-sizing: border-box !important;
155
- overflow: hidden !important;
156
  }}
157
 
158
  .page:last-child, .slide:last-child,
@@ -167,6 +165,8 @@ def inject_page_breaks(html_content: str, aspect_ratio: str):
167
  page-break-after: always !important;
168
  break-after: page !important;
169
  min-height: 100vh;
 
 
170
  }}
171
 
172
  body > section:last-child,
@@ -432,4 +432,4 @@ async def convert_string_to_pdf(
432
 
433
  if __name__ == "__main__":
434
  import uvicorn
435
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
122
  """Automatically inject page breaks and page sizing CSS"""
123
 
124
  if aspect_ratio == "16:9":
125
+ page_size = "288mm 162mm"
126
  elif aspect_ratio == "1:1":
127
  page_size = "210mm 210mm"
128
  else:
129
+ page_size = "162mm 288mm"
130
 
131
  page_css = f"""
132
  <style id="auto-page-breaks">
 
145
  .page, .slide, section.page, article.page, div[class*="page"], div[class*="slide"] {{
146
  width: 100% !important;
147
  min-height: 100vh !important;
 
148
  page-break-after: always !important;
149
  break-after: page !important;
150
  page-break-inside: avoid !important;
151
  break-inside: avoid !important;
152
  position: relative !important;
153
  box-sizing: border-box !important;
 
154
  }}
155
 
156
  .page:last-child, .slide:last-child,
 
165
  page-break-after: always !important;
166
  break-after: page !important;
167
  min-height: 100vh;
168
+ box-sizing: border-box !important;
169
+ position: relative !important;
170
  }}
171
 
172
  body > section:last-child,
 
432
 
433
  if __name__ == "__main__":
434
  import uvicorn
435
+ uvicorn.run(app, host="0.0.0.0", port=7860)
puppeteer_pdf.js CHANGED
@@ -44,7 +44,7 @@ async function convertToPDF() {
44
 
45
  // Launch browser with system Chromium
46
  const browserOptions = {
47
- headless: 'new',
48
  args: [
49
  '--no-sandbox',
50
  '--disable-setuid-sandbox',
@@ -54,18 +54,22 @@ async function convertToPDF() {
54
  '--disable-site-isolation-trials',
55
  '--disable-accelerated-2d-canvas',
56
  '--disable-gpu',
57
- '--single-process',
58
- '--no-zygote',
59
  '--disable-software-rasterizer',
60
  '--disable-dev-tools',
61
  '--no-first-run',
62
  '--no-default-browser-check',
63
  '--disable-breakpad',
64
  '--disable-crash-reporter',
 
 
65
  '--crash-dumps-dir=/tmp',
66
  '--disable-component-update'
67
  ]
68
  };
 
 
 
 
69
 
70
  // Try to use system Chromium if available
71
  const chromiumPaths = [
@@ -194,24 +198,23 @@ async function convertToPDF() {
194
 
195
  // Set dimensions based on aspect ratio
196
  if (aspectRatio === '16:9') {
197
- pdfOptions.format = 'A4';
198
- pdfOptions.landscape = true;
199
- pdfOptions.width = '297mm';
200
- pdfOptions.height = '210mm';
201
- console.log('PDF format: A4 Landscape (297mm x 210mm)');
202
  } else if (aspectRatio === '1:1') {
203
  pdfOptions.width = '210mm';
204
  pdfOptions.height = '210mm';
205
  pdfOptions.landscape = false;
206
  console.log('PDF format: Square (210mm x 210mm)');
207
  } else if (aspectRatio === '9:16') {
208
- pdfOptions.format = 'A4';
 
209
  pdfOptions.landscape = false;
210
- pdfOptions.width = '210mm';
211
- pdfOptions.height = '297mm';
212
- console.log('PDF format: A4 Portrait (210mm x 297mm)');
213
  } else {
214
- pdfOptions.format = 'A4';
 
215
  pdfOptions.landscape = true;
216
  console.log('PDF format: A4 Landscape (default)');
217
  }
@@ -246,4 +249,4 @@ async function convertToPDF() {
246
  convertToPDF().catch(error => {
247
  console.error('Unhandled error:', error);
248
  process.exit(1);
249
- });
 
44
 
45
  // Launch browser with system Chromium
46
  const browserOptions = {
47
+ headless: true,
48
  args: [
49
  '--no-sandbox',
50
  '--disable-setuid-sandbox',
 
54
  '--disable-site-isolation-trials',
55
  '--disable-accelerated-2d-canvas',
56
  '--disable-gpu',
 
 
57
  '--disable-software-rasterizer',
58
  '--disable-dev-tools',
59
  '--no-first-run',
60
  '--no-default-browser-check',
61
  '--disable-breakpad',
62
  '--disable-crash-reporter',
63
+ '--no-crashpad',
64
+ '--disable-features=Crashpad',
65
  '--crash-dumps-dir=/tmp',
66
  '--disable-component-update'
67
  ]
68
  };
69
+ browserOptions.env = {
70
+ ...process.env,
71
+ CHROME_CRASHPAD_PIPE_NAME: 'NONE'
72
+ };
73
 
74
  // Try to use system Chromium if available
75
  const chromiumPaths = [
 
198
 
199
  // Set dimensions based on aspect ratio
200
  if (aspectRatio === '16:9') {
201
+ pdfOptions.width = '288mm';
202
+ pdfOptions.height = '162mm';
203
+ pdfOptions.landscape = false;
204
+ console.log('PDF format: Custom 16:9 (288mm x 162mm)');
 
205
  } else if (aspectRatio === '1:1') {
206
  pdfOptions.width = '210mm';
207
  pdfOptions.height = '210mm';
208
  pdfOptions.landscape = false;
209
  console.log('PDF format: Square (210mm x 210mm)');
210
  } else if (aspectRatio === '9:16') {
211
+ pdfOptions.width = '162mm';
212
+ pdfOptions.height = '288mm';
213
  pdfOptions.landscape = false;
214
+ console.log('PDF format: Custom 9:16 (162mm x 288mm)');
 
 
215
  } else {
216
+ pdfOptions.width = '297mm';
217
+ pdfOptions.height = '210mm';
218
  pdfOptions.landscape = true;
219
  console.log('PDF format: A4 Landscape (default)');
220
  }
 
249
  convertToPDF().catch(error => {
250
  console.error('Unhandled error:', error);
251
  process.exit(1);
252
+ });