Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

iText pdfStamper (Seitenzahl)

Empfohlene Antworten

Veröffentlicht

Hi Leute,

ich habe ein Problem, ich möchte auf mein PDF die Seitenzahl hinzufügen. Dazu nutze ich den pdfstamper von itext. Mein Code sieht so aus:


			try {

				PdfReader reader = new PdfReader(baos.toByteArray());

				int n = reader.getNumberOfPages();

				//messageManager.reportSuccess("Seitenanzahl: " + n);

				String pdfsource = "";

				pdfsource = resource.toString();

				PdfStamper stamper = new PdfStamper(reader, baos);

				PdfContentByte page;

				Rectangle rect;

				BaseFont bf = BaseFont.createFont();

				for (int i = 1; i < n + 1; i++) {

					page = stamper.getOverContent(i);

					rect = reader.getPageSizeWithRotation(i);

					page.beginText();

					page.setFontAndSize(bf, 10);

					page.showTextAligned(Element.ALIGN_CENTER, "Seite " + i + " von " + n, rect.getRight(300), rect.getTop(835), 0);

					page.endText();

					//messageManager.reportSuccess("forschleife" + i);

				}

				stamper.close();

			} catch (IOException e) {

				e.printStackTrace();

				messageManager.reportSuccess("generatePDF() - IOException: " + e);

			} catch (DocumentException e) {

				e.printStackTrace();

				messageManager.reportSuccess("generatePDF() - DocumentException: " + e);

			}

Leider funktioniert es nicht. Also er bringt keinen Fehler, sondern er macht einfach nichts, also das PDF sieht ganz normal aus, ohne Seitenzahl. Ich fürchte es liegt am pdfstamper und evtl. meinen baos(vielleicht kommt er damit nicht zu recht). Kennt sich jemand mit dem pdfstamper aus und weiß wie man einfach testen könnte ob der stamper überhaupt angelegt werden konnte à la pdfstamper = true oder false oder so?

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.